From 22fdfb820f45adb31eb69b0b08e628c3512902d9 Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Sat, 25 Jun 2011 12:39:41 +0000 Subject: [PATCH] Simplify cgi_error_unknown() a bit. --- cgi.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/cgi.c b/cgi.c index 0583f88a..96af186c 100644 --- a/cgi.c +++ b/cgi.c @@ -1,4 +1,4 @@ -const char cgi_rcs[] = "$Id: cgi.c,v 1.130 2011/04/19 13:00:47 fabiankeil Exp $"; +const char cgi_rcs[] = "$Id: cgi.c,v 1.131 2011/06/23 14:01:01 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/cgi.c,v $ @@ -1212,12 +1212,8 @@ jb_err cgi_error_unknown(const struct client_state *csp, "file a bug report.

\r\n" "\r\n" "\r\n"; - char errnumbuf[30]; - /* - * Due to sizeof(errnumbuf), body_size will be slightly - * bigger than necessary but it doesn't really matter. - */ - const size_t body_size = strlen(body_prefix) + sizeof(errnumbuf) + strlen(body_suffix) + 1; + /* Includes room for larger error numbers in the future. */ + const size_t body_size = sizeof(body_prefix) + sizeof(body_suffix) + 5; assert(csp); assert(rsp); @@ -1230,16 +1226,13 @@ jb_err cgi_error_unknown(const struct client_state *csp, rsp->is_static = 0; rsp->crunch_reason = INTERNAL_ERROR; - snprintf(errnumbuf, sizeof(errnumbuf), "%d", error_to_report); - rsp->body = malloc(body_size); if (rsp->body == NULL) { return JB_ERR_MEMORY; } - strlcpy(rsp->body, body_prefix, body_size); - strlcat(rsp->body, errnumbuf, body_size); - strlcat(rsp->body, body_suffix, body_size); + + snprintf(rsp->body, body_size, "%s%d%s", body_prefix, error_to_report, body_suffix); rsp->status = strdup(status); if (rsp->status == NULL) -- 2.39.2