This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch tymux-10-quiet-head
in repository terminology.
View the commit online.
commit 1a3ea1ad7f681ae6e250b24db9ac5ba526206dfb
Author: Boris Faure <[email protected]>
AuthorDate: Thu Nov 5 21:47:05 2026 +0000
sb: prepend to an empty buffer as an add
ty_sb_prepend() on an empty buffer copied from a NULL pointer and sized
the new allocation without room for the terminating NUL, so reading the
result as a string ran one byte past it. No caller does this yet: the
link and colour finders always add a character before prepending.
---
src/bin/sb.c | 22 ++++++++++++++++++++++
src/bin/tytest.c | 1 +
src/bin/unit_tests.h | 1 +
3 files changed, 24 insertions(+)
diff --git a/src/bin/sb.c b/src/bin/sb.c
index c79e5965..26f809c5 100644
--- a/src/bin/sb.c
+++ b/src/bin/sb.c
@@ -39,6 +39,9 @@ ty_sb_add(struct ty_sb *sb, const char *s, size_t len)
int
ty_sb_prepend(struct ty_sb *sb, const char *s, size_t len)
{
+ if (!sb->buf)
+ return ty_sb_add(sb, s, len);
+
if (len >= sb->gap)
{
size_t aligned_gap = ((len + 15) / 16) * 24;
@@ -193,6 +196,25 @@ tytest_sb_add(void)
return 0;
}
+int
+tytest_sb_prepend(void)
+{
+ struct ty_sb sb = {};
+
+ /* to an empty buffer, as an add: with room for the NUL */
+ assert(ty_sb_prepend(&sb, "ab", 2) == 0);
+ assert(sb.buf && sb.len == 2 && sb.alloc > sb.gap + sb.len);
+ assert(strcmp(sb.buf, "ab") == 0);
+ ty_sb_free(&sb);
+
+ assert(ty_sb_prepend(&sb, "", 0) == 0);
+ assert(sb.buf && sb.len == 0 && sb.alloc > sb.gap);
+ assert(sb.buf[0] == '\0');
+ ty_sb_free(&sb);
+
+ return 0;
+}
+
int
tytest_sb_skip(void)
{
diff --git a/src/bin/tytest.c b/src/bin/tytest.c
index f357ad63..9982a584 100644
--- a/src/bin/tytest.c
+++ b/src/bin/tytest.c
@@ -41,6 +41,7 @@ static struct {
{ "truecolor_render", tytest_truecolor_render},
#endif
{ "sb_add", tytest_sb_add},
+ { "sb_prepend", tytest_sb_prepend},
{ "sb_skip", tytest_sb_skip},
{ "sb_trim", tytest_sb_trim},
{ "sb_gap", tytest_sb_gap},
diff --git a/src/bin/unit_tests.h b/src/bin/unit_tests.h
index 11cd94d8..237f583e 100644
--- a/src/bin/unit_tests.h
+++ b/src/bin/unit_tests.h
@@ -15,6 +15,7 @@ int tytest_cell_is_empty_rgb(void);
int tytest_truecolor_render(void);
#endif
int tytest_sb_add(void);
+int tytest_sb_prepend(void);
int tytest_sb_skip(void);
int tytest_sb_trim(void);
int tytest_sb_gap(void);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.