summaryrefslogtreecommitdiff
path: root/lib/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/util.c')
-rw-r--r--lib/util.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/util.c b/lib/util.c
index eceaec9..70d815c 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -1,6 +1,7 @@
-/* Copyright 2012 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 <stdlib.h>
#include <string.h>
#include <radsec/radsec.h>
#include <radsec/radsec-impl.h>
@@ -9,11 +10,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;
}