From 8dbef2d424d124add3539fbb9ff90ab96eaa78b9 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 29 Mar 2026 10:21:15 +0700 Subject: [PATCH] null check and the prefered realloc pattern with a temporary variable --- client/src/util.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/client/src/util.c b/client/src/util.c index e043a4120..8f887a6d4 100644 --- a/client/src/util.c +++ b/client/src/util.c @@ -1785,9 +1785,18 @@ int byte_strrstr(const uint8_t *src, size_t srclen, const uint8_t *pattern, size } void sb_append_char(smartbuf *sb, unsigned char c) { + if (sb->idx >= sb->size) { + sb->size *= 2; - sb->ptr = realloc(sb->ptr, sb->size); + + void *tmp = realloc(sb->ptr, sb->size); + if (tmp == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); + return; + } + + sb->ptr = tmp; } sb->ptr[sb->idx] = c; sb->idx++;