billiob pushed a commit to branch master. http://git.enlightenment.org/apps/terminology.git/commit/?id=58a1adac38acf20904414aedfc29c1693efe8526
commit 58a1adac38acf20904414aedfc29c1693efe8526 Author: Boris Faure <[email protected]> Date: Sat Apr 4 16:41:19 2020 +0200 sb: ubsan: do not apply 0 offset to NULL pointer --- src/bin/sb.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/bin/sb.c b/src/bin/sb.c index f52f9d4..38a2e99 100644 --- a/src/bin/sb.c +++ b/src/bin/sb.c @@ -14,8 +14,11 @@ ty_sb_add(struct ty_sb *sb, const char *s, size_t len) { size_t new_alloc = ((new_len + sb->gap + 15) / 16) * 24; char *new_buf; + char *buf = sb->buf; - new_buf = realloc(sb->buf - sb->gap, new_alloc); + if (buf && sb->gap) + buf -= sb->gap; + new_buf = realloc(buf, new_alloc); if (new_buf == NULL) return -1; sb->buf = new_buf + sb->gap; @@ -131,7 +134,10 @@ ty_sb_rskip(struct ty_sb *sb, int len) void ty_sb_free(struct ty_sb *sb) { - free(sb->buf - sb->gap); + char *buf = sb->buf; + if (buf && sb->gap) + buf -= sb->gap; + free(buf); sb->gap = sb->len = sb->alloc = 0; sb->buf = NULL; } --
