Fix tg3__arena_strdup to distinguish empty strings from absent strings

Co-authored-by: syoyo <18676+syoyo@users.noreply.github.com>
Agent-Logs-Url: https://github.com/syoyo/tinygltf/sessions/445ab61b-4294-45e6-8faf-4f2fc8dfe369
This commit is contained in:
copilot-swe-agent[bot]
2026-03-20 21:21:35 +00:00
parent 0949983acc
commit 5e0c5b9ada

View File

@@ -1358,10 +1358,13 @@ static void *tg3__arena_alloc(tg3_arena *arena, size_t size) {
}
static char *tg3__arena_strdup(tg3_arena *arena, const char *s, size_t len) {
if (!s || len == 0) return NULL;
if (!s) return NULL;
/* Allocate len+1 bytes; when len==0 this produces a 1-byte "\0" buffer so
* that empty strings (data!=NULL, len==0) remain distinguishable from
* absent strings (data==NULL, len==0). */
char *dst = (char *)tg3__arena_alloc(arena, len + 1);
if (!dst) return NULL;
memcpy(dst, s, len);
if (len > 0) memcpy(dst, s, len);
dst[len] = '\0';
return dst;
}