diff options
author | Linus Nordberg <linus@nordberg.se> | 2013-05-10 18:06:44 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordberg.se> | 2013-05-10 18:06:44 +0200 |
commit | 58f591ffc9a7d4fea5879210d56db3ca11e98f1e (patch) | |
tree | 752b316fd9b164ad11571211787dfe041d960e02 /lib | |
parent | f3252b34114236c65624862d2a572f5e290e8cc8 (diff) |
Use malloc+memcpy rather than calloc+strcpy in rs_strdup.
For effiency (but triggered by calloc needing unistd.h on Darwin).
Conflicts:
lib/util.c
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util.c | 14 |
1 files changed, 9 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,12 +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; - if (buf) - strcpy (buf, s); + len = strlen (s); + buf = rs_malloc (ctx, len + 1); + + if (buf != NULL) + memcpy (buf, s, len + 1); else - rs_err_ctx_push (ctx, RSE_NOMEM, NULL); + rs_err_ctx_push (ctx, RSE_NOMEM, __func__); return buf; } |