gbranden pushed a commit to branch master
in repository groff.
commit 6af159cc03b38f05f29bb0510a2b91886e1acc80
Author: G. Branden Robinson <[email protected]>
AuthorDate: Wed Jul 30 19:35:03 2025 -0500
[pre-grohtml]: Clear heap-allocated memory.
* src/preproc/html/pre-html.cpp (get_line): Clear heap-allocated memory
and annotate how we could do so in-language in C++03.
---
ChangeLog | 5 +++++
src/preproc/html/pre-html.cpp | 10 ++++++++--
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index c08b9ae82..50102af6b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2025-07-30 G. Branden Robinson <[email protected]>
+
+ * src/preproc/html/pre-html.cpp (get_line): Clear heap-allocated
+ memory and annotate how we could do so in-language in C++03.
+
2025-07-30 G. Branden Robinson <[email protected]>
* src/preproc/html/pre-html.cpp (get_resolution)
diff --git a/src/preproc/html/pre-html.cpp b/src/preproc/html/pre-html.cpp
index 04233842c..ebf0953a8 100644
--- a/src/preproc/html/pre-html.cpp
+++ b/src/preproc/html/pre-html.cpp
@@ -262,6 +262,10 @@ void sys_fatal(const char *s)
/*
* get_line - Copy a line (w/o newline) from a file to the
* global line buffer.
+ *
+ * TODO: Discard; migrate callers to POSIX `getline()`.
+ * https://pubs.opengroup.org/onlinepubs/9799919799/functions/\
+ * getline.html
*/
static bool get_line(FILE *f, const char *file_name, int lineno)
@@ -271,7 +275,8 @@ static bool get_line(FILE *f, const char *file_name, int
lineno)
if (0 /* nullptr */ == linebuf) {
linebufsize = 128;
try {
- linebuf = new char[linebufsize];
+ linebuf = new char[linebufsize]; // C++03: new int[linebufsize]();
+ (void) memset(linebuf, '\0', (linebufsize * sizeof(char)));
}
catch (std::bad_alloc &e) {
fatal_with_file_and_line(file_name, lineno, "cannot allocate %1"
@@ -298,7 +303,8 @@ static bool get_line(FILE *f, const char *file_name, int
lineno)
int newbufsize = linebufsize * 2;
char *old_linebuf = linebuf;
try {
- linebuf = new char[newbufsize];
+ linebuf = new char[newbufsize]; // C++03: new int[newbufsize]();
+ (void) memset(linebuf, '\0', (newbufsize * sizeof(char)));
}
catch (std::bad_alloc &e) {
fatal_with_file_and_line(file_name, lineno, "cannot allocate"
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit