Commit d1ce35d2 authored by Ben Gamari's avatar Ben Gamari Committed by Ben Gamari
Browse files

rts: Don't use strndup

Reviewers: austin

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D2125
parent 350ffc3e
......@@ -1597,7 +1597,7 @@ static rtsBool read_heap_profiling_flag(const char *arg_in)
if (!right)
right = arg + strlen(arg);
char *selector = strndup(left, right - left);
char *selector = stgStrndup(left, right - left + 1);
switch (arg[2]) {
case 'c': // cost centre label select
......
......@@ -112,6 +112,18 @@ stgCallocBytes (int n, int m, char *msg)
return space;
}
/* borrowed from the MUSL libc project */
char *stgStrndup(const char *s, size_t n)
{
size_t l = strnlen(s, n);
char *d = stgMallocBytes(l+1, "stgStrndup");
if (!d) return NULL;
memcpy(d, s, l);
d[l] = 0;
return d;
}
/* To simplify changing the underlying allocator used
* by stgMallocBytes(), provide stgFree() as well.
*/
......
......@@ -26,6 +26,8 @@ void *stgReallocBytes(void *p, int n, char *msg);
void *stgCallocBytes(int n, int m, char *msg)
GNUC3_ATTRIBUTE(__malloc__);
char *stgStrndup(const char *s, size_t n);
void stgFree(void* p);
/* -----------------------------------------------------------------------------
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment