From e16d7dddf1ef1df0c8a00f01fede497521134b74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 7 May 2008 18:38:38 +0200 Subject: Replace strn?cpy() + strn?cat() calls with a?sprintf(). Instead of creating strings through a series os string copy and concatenations, use directly the appropriate printf-like function. --- src/input/input_http.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'src/input/input_http.c') diff --git a/src/input/input_http.c b/src/input/input_http.c index 0e9345731..3b091e7cb 100644 --- a/src/input/input_http.c +++ b/src/input/input_http.c @@ -235,26 +235,16 @@ static int http_plugin_basicauth (const char *user, const char *password, char* char *tmp; char *sptr; char *dptr; - int totlen; + size_t count; int enclen; - int count; - totlen = strlen (user) + 1; - if(password != NULL) - totlen += strlen (password); - - enclen = ((totlen + 2) / 3 ) * 4 + 1; + count = asprintf(&tmp, "%s:%s", user, (password != NULL) ? password : ""); + + enclen = ((count + 2) / 3 ) * 4 + 1; if (len < enclen) return -1; - - tmp = malloc (sizeof(char) * (totlen + 1)); - strcpy (tmp, user); - strcat (tmp, ":"); - if (password != NULL) - strcat (tmp, password); - - count = strlen(tmp); + sptr = tmp; dptr = dest; while (count >= 3) { -- cgit v1.2.3