mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-10 08:16:15 +02:00
Don't use GC_STRNDUP
It calls strlen() on the input (rather than simply copying at most `size` bytes), which can fail if the input is not zero-terminated and is inefficient in any case. Fixes #7347.
This commit is contained in:
parent
bc9692a6b7
commit
0b4c4d7434
1 changed files with 3 additions and 7 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue