diff options
author | Linus Nordberg <linus@nordberg.se> | 2013-05-09 08:59:00 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordberg.se> | 2013-05-09 08:59:00 +0200 |
commit | 65a9a8786d5507e7f150567e4effd6e7409ac92c (patch) | |
tree | dde2ef4244a32c4a4b695e9865bf23b1426def84 | |
parent | de670651b8d513c3956fc8618bca303ba55a04f4 (diff) |
Use malloc+memcpy rather than calloc+strcpy in rs_strdup.
For effiency (but triggered by calloc needing unistd.h on Darwin).
-rw-r--r-- | lib/util.c | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -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 <string.h> @@ -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; } |