From 65a9a8786d5507e7f150567e4effd6e7409ac92c Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Thu, 9 May 2013 08:59:00 +0200 Subject: Use malloc+memcpy rather than calloc+strcpy in rs_strdup. For effiency (but triggered by calloc needing unistd.h on Darwin). --- lib/util.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'lib/util.c') diff --git a/lib/util.c b/lib/util.c index eceaec9..1142afa 100644 --- a/lib/util.c +++ b/lib/util.c @@ -1,4 +1,4 @@ -/* Copyright 2012 NORDUnet A/S. All rights reserved. +/* Copyright 2012,2013 NORDUnet A/S. All rights reserved. See LICENSE for licensing information. */ #include @@ -9,11 +9,16 @@ char * rs_strdup (struct rs_context *ctx, const char *s) { - char *buf = rs_calloc (ctx, 1, strlen (s) + 1); + size_t len; + char *buf; + + len = strlen (s); + buf = rs_malloc (ctx, len + 1); if (buf != NULL) - return strcpy (buf, s); + memcpy (buf, s, len + 1); + else + rs_err_ctx_push (ctx, RSE_NOMEM, __func__); - rs_err_ctx_push (ctx, RSE_NOMEM, NULL); - return NULL; + return buf; } -- cgit v1.1 From 4f9a7e63c1d14837ec880b9a63cc6a92a822e7d5 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Thu, 9 May 2013 09:32:31 +0200 Subject: Include stdlib.h everywhere we call (m|c)alloc. --- lib/util.c | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/util.c') diff --git a/lib/util.c b/lib/util.c index 1142afa..e50d473 100644 --- a/lib/util.c +++ b/lib/util.c @@ -1,6 +1,7 @@ /* Copyright 2012,2013 NORDUnet A/S. All rights reserved. See LICENSE for licensing information. */ +#include #include #include #include -- cgit v1.1 From f0df8b47b0c7639ab3842c2b92c80f70b8ed66d3 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Thu, 9 May 2013 09:49:37 +0200 Subject: Update copyright years. --- lib/util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/util.c') diff --git a/lib/util.c b/lib/util.c index e50d473..70d815c 100644 --- a/lib/util.c +++ b/lib/util.c @@ -1,5 +1,5 @@ -/* Copyright 2012,2013 NORDUnet A/S. All rights reserved. - See LICENSE for licensing information. */ +/* Copyright 2012-2013 NORDUnet A/S. All rights reserved. + See LICENSE for licensing information. */ #include #include -- cgit v1.1