gbranden pushed a commit to branch master
in repository groff.
commit 9d210665e372fdb77933dcbb5175bb9e9a4fe433
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sun Nov 9 09:55:31 2025 -0600
Improve assertion messages.
* src/libs/libgroff/color.cpp (color::get_rgb, color::get_cmy)
(color::get_cmyk, color::get_gray):
* src/preproc/eqn/pile.cpp (pile_box::output)
(matrix_box::output, column::debug_print)
* src/preproc/eqn/common.cpp (common_output::rounded_box):
* src/preproc/pic/lex.cpp (get_delimited):
* src/preproc/pic/object.cpp (object_spec::position_rectangle)
(object_spec::make_move, object_spec::make_line)
(object_spec::make_object):
* src/preproc/pic/tex.cpp (tex_output::spline)
(tex_output::circle, tex_output::ellipse):
* src/preproc/pic/troff.cpp (simple_output::line)
(simple_output::ellipse, simple_output::circle):
* src/preproc/refer/command.cpp (check_args):
* src/preproc/refer/label.ypp (format_serial)
(extractor_expr::evaluate):
* src/utils/hpftodit/hpftodit.cpp (main):
* src/utils/lkbib/lkbib.cpp (main): Replace `assert(0)` calls with
communicative predicates.
With this change, no `assert(0)` calls remain in groff.
---
ChangeLog | 22 ++++++++++++++++++++++
src/libs/libgroff/color.cpp | 8 ++++----
src/preproc/eqn/pile.cpp | 14 +++++++-------
src/preproc/pic/common.cpp | 2 +-
src/preproc/pic/lex.cpp | 2 +-
src/preproc/pic/object.cpp | 10 +++++-----
src/preproc/pic/tex.cpp | 6 +++---
src/preproc/pic/troff.cpp | 6 +++---
src/preproc/refer/command.cpp | 2 +-
src/preproc/refer/label.ypp | 4 ++--
src/utils/hpftodit/hpftodit.cpp | 2 +-
src/utils/lkbib/lkbib.cpp | 2 +-
12 files changed, 51 insertions(+), 29 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 53b6bbbeb..3d43dfbd3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2025-11-09 G. Branden Robinson <[email protected]>
+
+ * src/libs/libgroff/color.cpp (color::get_rgb, color::get_cmy)
+ (color::get_cmyk, color::get_gray):
+ * src/preproc/eqn/pile.cpp (pile_box::output)
+ (matrix_box::output, column::debug_print)
+ * src/preproc/eqn/common.cpp (common_output::rounded_box):
+ * src/preproc/pic/lex.cpp (get_delimited):
+ * src/preproc/pic/object.cpp (object_spec::position_rectangle)
+ (object_spec::make_move, object_spec::make_line)
+ (object_spec::make_object):
+ * src/preproc/pic/tex.cpp (tex_output::spline)
+ (tex_output::circle, tex_output::ellipse):
+ * src/preproc/pic/troff.cpp (simple_output::line)
+ (simple_output::ellipse, simple_output::circle):
+ * src/preproc/refer/command.cpp (check_args):
+ * src/preproc/refer/label.ypp (format_serial)
+ (extractor_expr::evaluate):
+ * src/utils/hpftodit/hpftodit.cpp (main):
+ * src/utils/lkbib/lkbib.cpp (main): Replace `assert(0)` calls
+ with communicative predicates.
+
2025-11-09 G. Branden Robinson <[email protected]>
* src/preproc/pic/lex.cpp (get_delimited): Drop `switch` case
diff --git a/src/libs/libgroff/color.cpp b/src/libs/libgroff/color.cpp
index 0a8c9a946..2f8ba830a 100644
--- a/src/libs/libgroff/color.cpp
+++ b/src/libs/libgroff/color.cpp
@@ -249,7 +249,7 @@ color::get_rgb(unsigned int *r, unsigned int *g, unsigned
int *b) const
*r = *g = *b = Gray;
break;
default:
- assert(0);
+ assert(0 == "unhandled case of color scheme");
break;
}
}
@@ -280,7 +280,7 @@ color::get_cmy(unsigned int *c, unsigned int *m, unsigned
int *y) const
*c = *m = *y = MAX_COLOR_VAL - Gray;
break;
default:
- assert(0);
+ assert(0 == "unhandled case of color scheme");
break;
}
}
@@ -330,7 +330,7 @@ void color::get_cmyk(unsigned int *c, unsigned int *m,
*k = MAX_COLOR_VAL - Gray;
break;
default:
- assert(0);
+ assert(0 == "unhandled case of color scheme");
break;
}
}
@@ -355,7 +355,7 @@ void color::get_gray(unsigned int *g) const
*g = Gray;
break;
default:
- assert(0);
+ assert(0 == "unhandled case of color scheme");
break;
}
}
diff --git a/src/preproc/eqn/pile.cpp b/src/preproc/eqn/pile.cpp
index 30203231d..515646337 100644
--- a/src/preproc/eqn/pile.cpp
+++ b/src/preproc/eqn/pile.cpp
@@ -79,7 +79,7 @@ void pile_box::output()
uid, col.p[i]->uid);
break;
default:
- assert(0);
+ assert(0 == "unhandled case of column alignment");
}
col.p[i]->output();
printf("\\h'-\\n[" WIDTH_FORMAT "]u'", col.p[i]->uid);
@@ -95,7 +95,7 @@ void pile_box::output()
col.p[i]->uid, uid);
break;
default:
- assert(0);
+ assert(0 == "unhandled case of column alignment");
}
if (i != col.len - 1)
printf("\\v'\\n[" BASELINE_SEP_FORMAT "]u'", uid);
@@ -117,7 +117,7 @@ void pile_box::output()
av = "center";
break;
default:
- assert(0);
+ assert(0 == "unhandled case of column alignment");
}
printf("<mtable columnalign='%s'>", av);
for (int i = 0; i < col.len; i++) {
@@ -216,7 +216,7 @@ void matrix_box::output()
uid, i, p[i]->p[j]->uid);
break;
default:
- assert(0);
+ assert(0 == "unhandled case of column alignment");
}
p[i]->p[j]->output();
printf("\\h'-\\n[" WIDTH_FORMAT "]u'", p[i]->p[j]->uid);
@@ -232,7 +232,7 @@ void matrix_box::output()
p[i]->p[j]->uid, uid, i);
break;
default:
- assert(0);
+ assert(0 == "unhandled case of column alignment");
}
if (j != p[i]->len - 1)
printf("\\v'\\n[" BASELINE_SEP_FORMAT "]u'", uid);
@@ -263,7 +263,7 @@ void matrix_box::output()
av = "center";
break;
default:
- assert(0);
+ assert(0 == "unhandled case of column alignment");
}
printf("<mtd columnalign='%s'>", av);
p[j]->p[i]->output();
@@ -349,7 +349,7 @@ void column::debug_print(const char *s)
c = 'c';
break;
default:
- assert(0);
+ assert(0 == "unhandled case of column alignment");
}
fprintf(stderr, "%c%s %d { ", c, s, space);
list_debug_print(" above ");
diff --git a/src/preproc/pic/common.cpp b/src/preproc/pic/common.cpp
index e61df9323..bc434288e 100644
--- a/src/preproc/pic/common.cpp
+++ b/src/preproc/pic/common.cpp
@@ -342,7 +342,7 @@ void common_output::rounded_box(const position ¢, const
distance &dim,
solid_rounded_box(cent, dim, rad, lt);
break;
default:
- assert(0);
+ assert(0 == "unhandled case of line type");
}
}
diff --git a/src/preproc/pic/lex.cpp b/src/preproc/pic/lex.cpp
index 623634927..56e0a5376 100644
--- a/src/preproc/pic/lex.cpp
+++ b/src/preproc/pic/lex.cpp
@@ -1392,7 +1392,7 @@ int get_delimited()
state = IN_STRING_QUOTED;
break;
default:
- assert(0);
+ assert(0 == "unhandled case of lexical analyzer state");
}
if (state == DELIM_END)
break;
diff --git a/src/preproc/pic/object.cpp b/src/preproc/pic/object.cpp
index a8e079be0..35a22d3ca 100644
--- a/src/preproc/pic/object.cpp
+++ b/src/preproc/pic/object.cpp
@@ -902,7 +902,7 @@ int object_spec::position_rectangle(rectangle_object *p,
motion.x = p->width()/2.0;
break;
default:
- assert(0);
+ assert(0 == "unhandled case of motion direction");
}
if (flags & HAS_AT) {
pos = at;
@@ -1205,7 +1205,7 @@ graphic_object *object_spec::make_move(position *curpos,
direction *dirp)
segment_pos.x = segment_width;
break;
default:
- assert(0);
+ assert(0 == "unhandled case of motion direction");
}
}
}
@@ -1567,7 +1567,7 @@ linear_object *object_spec::make_line(position *curpos,
direction *dirp)
segment_pos.x = segment_width;
break;
default:
- assert(0);
+ assert(0 == "unhandled case of motion direction");
}
}
segment_list = new segment(segment_pos, segment_is_absolute, segment_list);
@@ -1693,7 +1693,7 @@ linear_object *object_spec::make_line(position *curpos,
direction *dirp)
p->set_vertex_number(vertex_number);
break;
default:
- assert(0);
+ assert(0 == "unhandled case of picture object type");
}
have_last_line = 1;
last_line = endpos - startpos;
@@ -2045,7 +2045,7 @@ object *object_spec::make_object(position *curpos,
direction *dirp)
case MARK_OBJECT:
case OTHER_OBJECT:
default:
- assert(0);
+ assert(0 == "unhandled case of picture object type");
break;
}
if (obj) {
diff --git a/src/preproc/pic/tex.cpp b/src/preproc/pic/tex.cpp
index 04d469b78..a386970d1 100644
--- a/src/preproc/pic/tex.cpp
+++ b/src/preproc/pic/tex.cpp
@@ -239,7 +239,7 @@ void tex_output::spline(const position &start, const
position *v, int n,
printf(" %.3f", lt.dash_width/scale);
break;
case line_type::invisible:
- assert(0);
+ assert(0 == "unhandled case of line type");
}
fputs("}%\n", stdout);
}
@@ -312,7 +312,7 @@ void tex_output::circle(const position ¢, double rad,
dotted_circle(cent, rad, lt);
break;
default:
- assert(0);
+ assert(0 == "unhandled case of line type");
}
}
@@ -348,7 +348,7 @@ void tex_output::ellipse(const position ¢, const
distance &dim,
dotted_ellipse(cent, dim / scale, lt);
break;
default:
- assert(0);
+ assert(0 == "unhandled case of line type");
}
}
diff --git a/src/preproc/pic/troff.cpp b/src/preproc/pic/troff.cpp
index 2bd1ed861..e8397bc93 100644
--- a/src/preproc/pic/troff.cpp
+++ b/src/preproc/pic/troff.cpp
@@ -135,7 +135,7 @@ void simple_output::line(const position &start, const
position *v,
case line_type::invisible:
break;
default:
- assert(0);
+ assert(0 == "unhandled case of line type");
}
pos = v[i];
}
@@ -190,7 +190,7 @@ void simple_output::circle(const position ¢, double rad,
simple_circle(0, cent, rad);
break;
default:
- assert(0);
+ assert(0 == "unhandled case of line type");
}
}
@@ -218,7 +218,7 @@ void simple_output::ellipse(const position ¢, const
distance &dim,
simple_ellipse(0, cent, dim);
break;
default:
- assert(0);
+ assert(0 == "unhandled case of line type");
}
}
diff --git a/src/preproc/refer/command.cpp b/src/preproc/refer/command.cpp
index f24a08111..5cd2dfe86 100644
--- a/src/preproc/refer/command.cpp
+++ b/src/preproc/refer/command.cpp
@@ -739,7 +739,7 @@ static int check_args(const char *types, const char *name,
}
break;
default:
- assert(0);
+ assert(0 == "unhandled case of command type");
}
if (types[1] == '?')
types += 2;
diff --git a/src/preproc/refer/label.ypp b/src/preproc/refer/label.ypp
index 35fe9cd11..44202b8f8 100644
--- a/src/preproc/refer/label.ypp
+++ b/src/preproc/refer/label.ypp
@@ -620,7 +620,7 @@ static const char *format_serial(char c, int n)
break;
}
default:
- assert(0);
+ assert(0 == "unhandled case of register format");
}
return buf;
}
@@ -715,7 +715,7 @@ void extractor_expr::evaluate(int tentative, const
reference &ref,
result.append(end, temp.contents() + temp.length() - end);
break;
default:
- assert(0);
+ assert(0 == "unhandled case of part in expression evaluator");
}
}
}
diff --git a/src/utils/hpftodit/hpftodit.cpp b/src/utils/hpftodit/hpftodit.cpp
index 617a76abe..b29a04dc3 100644
--- a/src/utils/hpftodit/hpftodit.cpp
+++ b/src/utils/hpftodit/hpftodit.cpp
@@ -340,7 +340,7 @@ main(int argc, char **argv)
exit(2);
break;
default:
- assert(0);
+ assert(0 == "unhandled case of command-line option");
}
if (debug_flag && argc - optind < 1)
diff --git a/src/utils/lkbib/lkbib.cpp b/src/utils/lkbib/lkbib.cpp
index 419972cbf..a69a57250 100644
--- a/src/utils/lkbib/lkbib.cpp
+++ b/src/utils/lkbib/lkbib.cpp
@@ -119,7 +119,7 @@ int main(int argc, char **argv)
exit(2);
break;
default:
- assert(0);
+ assert(0 == "unhandled case of command-line option");
}
if (optind >= argc) {
usage(stderr);
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit