Check the return of strndup
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
+#include <err.h>
#include "pw.h"
char *
newstr(char const * p)
{
- char *q = NULL;
+ char *q;
+ size_t l;
- if ((p = unquote(p)) != NULL) {
- int l = strlen(p) + 1;
+ if ((p = unquote(p)) == NULL)
+ return (NULL);
- if ((q = malloc(l)) != NULL)
- memcpy(q, p, l);
- }
- return q;
+ l = strlen(p) + 1;
+
+ if ((q = strndup(p, l)) == NULL)
+ err(1, "strndup()");
+
+ return (q);
}
struct userconf *