]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
mod_lua:
authorDaniel Gruno <humbedooh@apache.org>
Wed, 1 Aug 2012 07:28:22 +0000 (07:28 +0000)
committerDaniel Gruno <humbedooh@apache.org>
Wed, 1 Aug 2012 07:28:22 +0000 (07:28 +0000)
Clean up style
use apr_pstrcat instead of apr_psprintf
fix a bug that was causing bad string interpolations.

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

modules/lua/mod_lua.c

index 3b0631c5c46bc08e2beb90d9ad7868b8b6f8fe16..460f8e2d371a084728e238fcb0aebb1a65d656e2 100644 (file)
@@ -183,18 +183,23 @@ static const char* ap_lua_interpolate_string(apr_pool_t* pool, const char* strin
             if (x-y > 0) {
                 stringBetween = apr_pstrndup(pool, string+y, x-y);
             }
-            else stringBetween = "";
-            int v = atoi(apr_pstrndup(pool,string+x+1, 1));
-            ret = apr_psprintf(pool, "%s%s%s", ret, stringBetween, values[v]);
-            y = ++x;
+            else {
+                stringBetween = "";
+            }
+            int v = *(string+x+1) - '0';
+            ret = apr_pstrcat(pool, ret, stringBetween, values[v], NULL);
+            y = ++x+1;
         }
     }
     
     if (x-y > 0 && y > 0) {
-        stringBetween = apr_pstrndup(pool, string+y+1, x-y);
-        ret = apr_psprintf(pool, "%s%s", ret, stringBetween);
+        stringBetween = apr_pstrndup(pool, string+y, x-y);
+        ret = apr_pstrcat(pool, ret, stringBetween, NULL);
+    }
+    /* If no replacement was made, just return the original string */
+    else if (y==0) {
+        return string;
     }
-    else if (y==0) return string; /* If no replacement was made, just return the original str. */
     return ret;
 }
 
@@ -362,7 +367,6 @@ static int lua_map_handler(request_rec *r)
                                     hook_spec->bytecode_len,
                                     function_name,
                                     "mapped handler");
-
             L = ap_lua_get_lua_state(pool, spec, r);
 
             if (!L) {