X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=lib%2Fxutil.c;h=268225b8956690137ae471c82e4ef39de71c4a96;hp=6fa5eb0ddb49dfb12dcd0cf039d4165cd8f6f7cb;hb=8b445212e46a194b59edbd6857449430fe460165;hpb=146549321044615d9aef2b30cedccda9c49f3f38 diff --git a/lib/xutil.c b/lib/xutil.c index 6fa5eb0d..268225b8 100644 --- a/lib/xutil.c +++ b/lib/xutil.c @@ -18,7 +18,6 @@ * Author: Carl Worth */ -#define _GNU_SOURCE /* For strndup */ #include "notmuch-private.h" #include @@ -84,11 +83,16 @@ xstrndup (const char *s, size_t n) { char *ret; - ret = strndup (s, n); + if (strlen (s) <= n) + n = strlen (s); + + ret = malloc (n + 1); if (ret == NULL) { fprintf (stderr, "Out of memory.\n"); exit (1); } + memcpy (ret, s, n); + ret[n] = '\0'; return ret; }