[master] e4f312d Eliminate use of strndup(), in this case the length is known to match precisely.

Poul-Henning Kamp phk at varnish-cache.org
Thu May 12 14:19:17 CEST 2011


commit e4f312d354be8f95f2d07e7567c2ca5f56d8217e
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu May 12 12:15:36 2011 +0000

    Eliminate use of strndup(), in this case the length is known to match
    precisely.

diff --git a/bin/varnishreplay/varnishreplay.c b/bin/varnishreplay/varnishreplay.c
index 2ef996f..713f125 100644
--- a/bin/varnishreplay/varnishreplay.c
+++ b/bin/varnishreplay/varnishreplay.c
@@ -49,10 +49,6 @@
 #include "varnishapi.h"
 #include "vss.h"
 
-#ifndef HAVE_STRNDUP
-#include "compat/strndup.h"
-#endif
-
 #define freez(x) do { if (x) free(x); x = NULL; } while (0);
 
 static struct vss_addr *addr_info;
@@ -661,7 +657,9 @@ gen_traffic(void *priv, enum vsl_tag tag, unsigned fd,
 	msg = malloc(sizeof (struct message));
 	msg->tag = tag;
 	msg->len = len;
-	msg->ptr = strndup(ptr, len);
+	msg->ptr = malloc(len);
+	AN(msg->ptr);
+	memcpy(msg->ptr, ptr, len);
 	mailbox_put(&thr->mbox, msg);
 
 	return (0);



More information about the varnish-commit mailing list