Commit cb93ff93 authored by David Zeuthen's avatar David Zeuthen

fix some unaligned access bugs

parent 66da3caa
......@@ -166,16 +166,17 @@ p_free (void *memory)
char *
p_strdup (const char *s)
{
void *p;
char *p;
size_t len;
len = strlen (s) + 1;
len = strlen (s);
p = p_malloc (len + 1);
if (p == NULL)
goto out;
memcpy (p, s, len + 1);
memcpy (p, s, len);
p[len] = '\0';
out:
return p;
......@@ -197,18 +198,23 @@ out:
char *
p_strndup (const char *s, size_t n)
{
void *p;
char *p;
size_t len;
len = strlen (s) + 1;
if (len > n)
len = n;
for (len = 0; len < n; len++) {
if (s[len] == '\0')
break;
if (len == n)
break;
}
p = p_malloc (len + 1);
if (p == NULL)
goto out;
memcpy (p, s, len + 1);
memcpy (p, s, len);
p[len] = '\0';
out:
return 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