commit 97c17f724b05368d41cec4e13daf1439edca1283
parent 4a4fa4889ef82724b7c7a25110855d423548f5a0
Author: Joris Vink <joris@coders.se>
Date: Mon, 11 Aug 2014 10:45:10 +0200
Add kore_snprintf() as a wrapper around snprintf().
Diffstat:
3 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/includes/kore.h b/includes/kore.h
@@ -414,6 +414,7 @@ void kore_strlcpy(char *, const char *, size_t);
void kore_server_disconnect(struct connection *);
int kore_split_string(char *, char *, char **, size_t);
void kore_strip_chars(char *, char, char **);
+int kore_snprintf(char *, size_t, int *, const char *, ...);
long long kore_strtonum(const char *, int, long long, long long, int *);
int kore_base64_encode(u_int8_t *, u_int32_t, char **);
int kore_base64_decode(char *, u_int8_t **, u_int32_t *);
diff --git a/src/http.c b/src/http.c
@@ -788,8 +788,7 @@ http_populate_multipart_form(struct http_request *req, int *v)
val++;
slen = strlen(val);
boundary = kore_malloc(slen + 3);
- l = snprintf(boundary, slen + 3, "--%s", val);
- if (l == -1) {
+ if (!kore_snprintf(boundary, slen + 3, &l, "--%s", val)) {
kore_mem_free(boundary);
kore_mem_free(type);
return (KORE_RESULT_ERROR);
diff --git a/src/utils.c b/src/utils.c
@@ -102,6 +102,25 @@ kore_strlcpy(char *dst, const char *src, size_t len)
}
}
+int
+kore_snprintf(char *str, size_t size, int *len, const char *fmt, ...)
+{
+ int l;
+ va_list args;
+
+ va_start(args, fmt);
+ l = vsnprintf(str, size, fmt, args);
+ va_end(args);
+
+ if (l == -1 || (size_t)l >= size)
+ return (KORE_RESULT_ERROR);
+
+ if (len != NULL)
+ *len = l;
+
+ return (KORE_RESULT_OK);
+}
+
long long
kore_strtonum(const char *str, int base, long long min, long long max, int *err)
{