From f9ef46fb267f6cf5ec187b068c993615040b7a7b Mon Sep 17 00:00:00 2001 From: Reyk Floeter Date: Tue, 23 Jun 2015 15:29:12 +0200 Subject: Use strndup instead of calloc + memcpy. From Leandro Pereira (@lafp on twitter) --- httpd/patterns.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/httpd/patterns.c b/httpd/patterns.c index 08c1e27..61f6ab8 100644 --- a/httpd/patterns.c +++ b/httpd/patterns.c @@ -692,14 +692,12 @@ str_match(const char *string, const char *pattern, struct str_match *m, if (sm[i].sm_so > sm[i].sm_eo) continue; len = sm[i].sm_eo - sm[i].sm_so; - if ((m->sm_match[i] = calloc(1, - len + 1)) == NULL) { + if ((m->sm_match[i] = strndup(string + + sm[i].sm_so, len)) == NULL) { *errstr = strerror(errno); str_match_free(m); return (-1); } - (void)memcpy(m->sm_match[i], - string + sm[i].sm_so, len); } *errstr = NULL; -- cgit v1.2.3-54-g00ecf