gbranden pushed a commit to branch master
in repository groff.
commit ca899536e514235103897235b98d58c4883cedf2
Author: G. Branden Robinson <[email protected]>
AuthorDate: Fri Apr 10 01:26:46 2026 -0500
src/roff/troff/env.cpp: Slightly refactor.
* src/roff/troff/env.cpp (add_hyphenation_exception_words_request):
memset(3) stack-allocated character arrays `buf` and `pos` with null
terminators/zeroes as a paranoid hedge.
---
ChangeLog | 8 ++++++++
src/roff/troff/env.cpp | 13 ++++++++++---
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 71dc10789..3acc2e3a3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2026-04-10 G. Branden Robinson <[email protected]>
+
+ * src/roff/troff/env.cpp
+ (add_hyphenation_exception_words_request): Slightly refactor.
+ memset(3) stack-allocated character arrays `buf` and `pos` with
+ null terminators/zeroes as a paranoid hedge. Drop later
+ null-termination of `buf` as redundant.
+
2026-04-10 G. Branden Robinson <[email protected]>
* src/roff/troff/env.cpp
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index a48edc275..a472a164d 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -3924,8 +3924,16 @@ static void add_hyphenation_exception_words_request() //
.hw
skip_line();
return;
}
- char buf[WORD_MAX + 1];
- unsigned char pos[WORD_MAX + 2];
+ // C++11: constexpr
+ const size_t buflen = WORD_MAX + 1 /* '\0' */;
+ // C++11: char buf[buflen]{};
+ char buf[buflen];
+ (void) memset(buf, 0, buflen);
+ // C++11: constexpr
+ const size_t posbuflen = WORD_MAX + 2 /* leading '-' + '\0' */;
+ // C++11: unsigned char pos[posbuflen]{};
+ unsigned char pos[posbuflen];
+ (void) memset(pos, 0, posbuflen);
for (;;) {
if (!has_arg())
break;
@@ -3970,7 +3978,6 @@ static void add_hyphenation_exception_words_request() //
.hw
}
if (is_word_valid && (i > 0)) {
pos[npos] = 0U;
- buf[i] = '\0';
// C++03: new unsigned char[npos + 1]();
unsigned char *tem = new unsigned char[npos + 1];
(void) memset(tem, 0, ((npos + 1) * sizeof(unsigned char)));
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit