]> granicus.if.org Git - apache/commitdiff
According to my testing, one special case of 'log_xlate_error', i.e. EES_INCOMPLETE_CHAR,
authorChristophe Jaillet <jailletc36@apache.org>
Sun, 6 Jan 2013 19:48:40 +0000 (19:48 +0000)
committerChristophe Jaillet <jailletc36@apache.org>
Sun, 6 Jan 2013 19:48:40 +0000 (19:48 +0000)
 is 13x (!!!) faster with the use 'ap_bin2hex' instead of apr_snprintf(..., "%02X" + srlen for each character.

Output is *not* exactly the same. It was uppercase, now it is lowercase.
It is just for logging, so I don't think it is an issue.
Should it be, a call to ap_strtoupper can be added.

So sad it is just for logging in case of error... no real speedup to be expected in real life .

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1429582 13f79535-47bb-0310-9956-ffa450edef68

modules/filters/mod_charset_lite.c

index 39ab18fc1f3195d17465a5dab202067332f10063..2d3d1439964ca911f2ae9d3c86611c20e3763a79 100644 (file)
@@ -474,7 +474,7 @@ static void log_xlate_error(ap_filter_t *f, apr_status_t rv)
     charset_filter_ctx_t *ctx = f->ctx;
     const char *msg;
     char msgbuf[100];
-    int cur;
+    int len;
 
     switch(ctx->ees) {
     case EES_LIMIT:
@@ -492,12 +492,14 @@ static void log_xlate_error(ap_filter_t *f, apr_status_t rv)
     case EES_INCOMPLETE_CHAR:
         rv = 0;
         strcpy(msgbuf, APLOGNO(02196) "xlate filter - incomplete char at end of input - ");
-        cur = 0;
-        while ((apr_size_t)cur < ctx->saved) {
-            apr_snprintf(msgbuf + strlen(msgbuf), sizeof(msgbuf) - strlen(msgbuf),
-                         "%02X", (unsigned)ctx->buf[cur]);
-            ++cur;
-        }
+        len = ctx->saved;
+
+        /* We must ensure not to process more than what would fit in the
+         * remaining of the destination buffer, including terminating NULL */
+        if (len > (sizeof(msgbuf) - strlen(msgbuf) - 1) / 2)
+            len = (sizeof(msgbuf) - strlen(msgbuf) - 1) / 2;
+
+        ap_bin2hex(ctx->buf, len, msgbuf + strlen(msgbuf));
         msg = msgbuf;
         break;
     case EES_DOWNSTREAM: