X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=xutil.c;h=5f98f3f7e9b83135679c801b01d898345f8c37f4;hp=6fa5eb0ddb49dfb12dcd0cf039d4165cd8f6f7cb;hb=59a9c36316293b161528097a73c72d5f5ed58781;hpb=cc48812cb55e046a77ce1b4aad33566acc5fbd47 diff --git a/xutil.c b/xutil.c index 6fa5eb0d..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,8 +108,9 @@ xregcomp (regex_t *preg, const char *regex, int cflags) char *error = xmalloc (error_size); regerror (rerr, preg, error, error_size); - INTERNAL_ERROR ("compiling regex %s: %s\n", - regex, error); + fprintf (stderr, "Internal error: compiling regex %s: %s\n", + regex, error); + exit (1); } } @@ -121,9 +126,12 @@ xregexec (const regex_t *preg, const char *string, return rerr; for (i = 0; i < nmatch; i++) { - if (pmatch[i].rm_so == -1) - INTERNAL_ERROR ("matching regex against %s: Sub-match %d not found\n", - string, i); + if (pmatch[i].rm_so == -1) { + fprintf (stderr, "Internal error: matching regex against %s:" + "Sub-match %d not found\n", + string, i); + exit (1); + } } return 0;