kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 7349fab13f8fba2f574632e575b24aeb4b6e55cf
parent 70d9df88964175d746f2a438f071a41b5e14f806
Author: Joris Vink <joris@coders.se>
Date:   Mon, 11 Aug 2014 11:02:30 +0200

Sprinkle kore_snprintf() where appropriate.

Diffstat:
examples/generic/src/example.c | 9+++++----
examples/tasks/src/tasks.c | 5++---
examples/video_stream/src/stream.c | 14+++++---------
3 files changed, 12 insertions(+), 16 deletions(-)

diff --git a/examples/generic/src/example.c b/examples/generic/src/example.c @@ -160,7 +160,8 @@ serve_file_upload(struct http_request *req) } if (http_file_lookup(req, "file", &name, &d, &len)) { - snprintf(buf, sizeof(buf), "%s is %d bytes", name, len); + (void)snprintf(buf, sizeof(buf), + "%s is %d bytes", name, len); kore_buf_replace_string(b, "$upload$", buf, strlen(buf)); } else { @@ -290,12 +291,12 @@ serve_params_test(struct http_request *req) } for (i = 1; i < 4; i++) { - snprintf(name, sizeof(name), "test%d", i); + (void)snprintf(name, sizeof(name), "test%d", i); if (http_argument_get_string(name, &test, &len)) { - snprintf(name, sizeof(name), "$test%d$", i); + (void)snprintf(name, sizeof(name), "$test%d$", i); kore_buf_replace_string(b, name, test, len); } else { - snprintf(name, sizeof(name), "$test%d$", i); + (void)snprintf(name, sizeof(name), "$test%d$", i); kore_buf_replace_string(b, name, NULL, 0); } } diff --git a/examples/tasks/src/tasks.c b/examples/tasks/src/tasks.c @@ -156,7 +156,6 @@ post_back(struct http_request *req) int run_curl(struct kore_task *t) { - int l; struct kore_buf *b; u_int32_t len; CURLcode res; @@ -172,8 +171,8 @@ run_curl(struct kore_task *t) if (len > sizeof(user)) return (KORE_RESULT_ERROR); - l = snprintf(fields, sizeof(fields), "user=%.*s", len, user); - if (l == -1 || (size_t)l >= sizeof(fields)) + if (!kore_snprintf(fields, sizeof(fields), + NULL, "user=%.*s", len, user)) return (KORE_RESULT_ERROR); if ((curl = curl_easy_init()) == NULL) diff --git a/examples/video_stream/src/stream.c b/examples/video_stream/src/stream.c @@ -76,7 +76,7 @@ video_stream(struct http_request *req) { struct video *v; off_t start, end; - int n, err, l, status; + int n, err, status; char *header, *bytes, *range[3], rb[128], *ext, ctype[32]; if (!video_open(req, &v)) @@ -87,8 +87,7 @@ video_stream(struct http_request *req) return (KORE_RESULT_OK); } - l = snprintf(ctype, sizeof(ctype), "video/%s", ext + 1); - if (l == -1 || (size_t)l >= sizeof(ctype)) { + if (!kore_snprintf(ctype, sizeof(ctype), NULL, "video/%s", ext + 1)) { http_response(req, 500, NULL, 0); return (KORE_RESULT_OK); } @@ -136,9 +135,8 @@ video_stream(struct http_request *req) } status = 206; - l = snprintf(rb, sizeof(rb), "bytes %ld-%ld/%ld", - start, end - 1, v->size); - if (l == -1 || (size_t)l >= sizeof(rb)) { + if (!kore_snprintf(rb, sizeof(rb), NULL, + "bytes %ld-%ld/%ld", start, end - 1, v->size)) { http_response(req, 500, NULL, 0); return (KORE_RESULT_OK); } @@ -163,13 +161,11 @@ video_stream(struct http_request *req) static int video_open(struct http_request *req, struct video **out) { - int l; struct stat st; struct video *v; char fpath[MAXPATHLEN]; - l = snprintf(fpath, sizeof(fpath), "videos%s", req->path); - if (l == -1 || (size_t)l >= sizeof(fpath)) + if (!kore_snprintf(fpath, sizeof(fpath), NULL, "videos%s", req->path)) return (KORE_RESULT_ERROR); TAILQ_FOREACH(v, &videos, list) {