mirror of
https://github.com/syoyo/tinygltf.git
synced 2026-09-01 16:08:42 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user