gbranden pushed a commit to branch master
in repository groff.
commit c93ed40d8e4960a8b789fd4f1df575e21f5f253f
Author: G. Branden Robinson <[email protected]>
AuthorDate: Wed Jun 24 19:27:01 2026 -0500
[pic]: Improve type discipline.
* src/preproc/pic/object.cpp (graphic_object::add_text): Convert type of
local variables `len` and `i` from `int` to `size_t`, since they're
used or compared to an array index. Refactor loop to lift `i` out of
it, since it requires a type declaration, and you can't do that after
a comma in a C++98 for loop initialization expression. Use `i`
instead of `len` as the index into the `text` array since the value of
`len` is now a loop invariant--`i` is the index.
---
ChangeLog | 11 +++++++++++
src/preproc/pic/object.cpp | 15 ++++++++-------
2 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 166742789..5af286079 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2026-06-24 G. Branden Robinson <[email protected]>
+
+ * src/preproc/pic/object.cpp (graphic_object::add_text): Convert
+ type of local variables `len` and `i` from `int` to `size_t`,
+ since they're used or compared to an array index. Refactor loop
+ to lift `i` out of it, since it requires a type declaration, and
+ you can't do that after a comma in a C++98 for loop
+ initialization expression. Use `i` instead of `len` as the
+ index into the `text` array since the value of `len` is now a
+ loop invariant--`i` is the index.
+
2026-06-24 G. Branden Robinson <[email protected]>
* src/preproc/pic/lex.cpp (interpolate_macro_with_args): When
diff --git a/src/preproc/pic/object.cpp b/src/preproc/pic/object.cpp
index 0c2e4414d..8a65fc1cd 100644
--- a/src/preproc/pic/object.cpp
+++ b/src/preproc/pic/object.cpp
@@ -652,20 +652,21 @@ void graphic_object::set_invisible()
void graphic_object::add_text(text_item *t, int a)
{
aligned = a;
- int len = 0;
+ size_t len = 0;
text_item *p;
for (p = t; p; p = p->next)
len++;
if (len == 0)
- text = 0;
+ text = 0 /* nullptr */;
else {
text = new text_piece[len];
- for (p = t, len = 0; p; p = p->next, len++) {
- text[len].text = p->text;
+ size_t i = 0;
+ for (p = t; p != 0 /* nullptr */; p = p->next, i++) {
+ text[i].text = p->text;
p->text = 0;
- text[len].adj = p->adj;
- text[len].filename = p->filename;
- text[len].lineno = p->lineno;
+ text[i].adj = p->adj;
+ text[i].filename = p->filename;
+ text[i].lineno = p->lineno;
}
}
ntext = len;
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit