gbranden pushed a commit to branch master
in repository groff.
commit 2ffcc873fbb10cd3e4f69c4e138ed7a5af75dc30
Author: G. Branden Robinson <[email protected]>
AuthorDate: Thu Jun 11 06:00:57 2026 -0500
[libgroff]: Be more fasitidious with heap memory.
* src/libs/libgroff/string.cpp (sfree_alloc, srealloc): When
"shortening" the length of an existing `string`, zero out the memory
from the new length to the capacity (which is not reduced).
Performance analysis
====================
Impact seems negligible. I timed a full groff build from "distclean" to
completion, using a single core.
Before
------
real 2m50.447s
user 2m57.468s
sys 0m20.466s
After
-----
real 2m49.394s
user 2m53.555s
sys 0m22.126s
---
ChangeLog | 7 +++++++
src/libs/libgroff/string.cpp | 2 ++
2 files changed, 9 insertions(+)
diff --git a/ChangeLog b/ChangeLog
index a037aa4ad..5527d05c2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2026-06-11 G. Branden Robinson <[email protected]>
+
+ * src/libs/libgroff/string.cpp (sfree_alloc, srealloc): Be more
+ fasitidious with heap memory; when "shortening" the length of an
+ existing `string`, zero out the memory from the new length to
+ the capacity (which is not reduced).
+
2026-06-09 G. Branden Robinson <[email protected]>
* src/libs/libgroff/string.cpp: Continue refactoring to
diff --git a/src/libs/libgroff/string.cpp b/src/libs/libgroff/string.cpp
index 44bcc3c42..796bd7bca 100644
--- a/src/libs/libgroff/string.cpp
+++ b/src/libs/libgroff/string.cpp
@@ -88,6 +88,7 @@ static char *sfree_alloc(char *ptr, size_t oldsz, size_t len,
{
if (oldsz >= len) {
*sizep = oldsz;
+ memset((ptr + len), 0, (oldsz - len));
return ptr;
}
delete[] ptr;
@@ -111,6 +112,7 @@ static char *srealloc(char *ptr, size_t oldsz, size_t
oldlen,
{
if (oldsz >= newlen) {
*sizep = oldsz;
+ memset((ptr + oldlen), 0, (newlen - oldsz));
return ptr;
}
size_t amount = newlen;
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit