Merge pull request #7350 from edolstra/remove-strndup

Don't use GC_STRNDUP
This commit is contained in:
Eelco Dolstra 2022-11-26 08:50:54 +01:00 committed by GitHub
commit 534332c8a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -69,15 +69,11 @@ static char * dupString(const char * s)
// empty string. // empty string.
static const char * makeImmutableStringWithLen(const char * s, size_t size) static const char * makeImmutableStringWithLen(const char * s, size_t size)
{ {
char * t;
if (size == 0) if (size == 0)
return ""; return "";
#if HAVE_BOEHMGC auto t = allocString(size + 1);
t = GC_STRNDUP(s, size); memcpy(t, s, size);
#else t[size] = 0;
t = strndup(s, size);
#endif
if (!t) throw std::bad_alloc();
return t; return t;
} }