* Author: Carl Worth <cworth@cworth.org>
*/
-#define _GNU_SOURCE /* For strndup */
#include "notmuch-private.h"
#include <stdio.h>
{
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;
}
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);
}
}
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)
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);
}