X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=xutil.c;h=5f98f3f7e9b83135679c801b01d898345f8c37f4;hp=eadd3783f9477735d43cabd84f96c9a53e900184;hb=59b251ef940609dac7e17528065a39544463e0b4;hpb=d008389a4ae306e510b11cc18947d305704f9236 diff --git a/xutil.c b/xutil.c index eadd3783..5f98f3f7 100644 --- a/xutil.c +++ b/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; } @@ -104,9 +108,8 @@ xregcomp (regex_t *preg, const char *regex, int cflags) char *error = xmalloc (error_size); regerror (rerr, preg, error, error_size); - fprintf (stderr, "Internal error compiling regex %s: %s\n", + fprintf (stderr, "Internal error: compiling regex %s: %s\n", regex, error); - free (error); exit (1); } } @@ -115,7 +118,8 @@ int xregexec (const regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags) { - int i, rerr; + unsigned int i; + int rerr; rerr = regexec (preg, string, nmatch, pmatch, eflags); if (rerr) @@ -123,7 +127,8 @@ xregexec (const regex_t *preg, const char *string, for (i = 0; i < nmatch; i++) { if (pmatch[i].rm_so == -1) { - fprintf (stderr, "Internal error matching regex against %s: Sub-match %d not found\n", + fprintf (stderr, "Internal error: matching regex against %s:" + "Sub-match %d not found\n", string, i); exit (1); }