httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r1228766 - /httpd/httpd/trunk/modules/proxy/proxy_util.c
Date Sun, 08 Jan 2012 01:40:01 GMT
Author: jim
Date: Sun Jan  8 01:40:01 2012
New Revision: 1228766

URL: http://svn.apache.org/viewvc?rev=1228766&view=rev
Log:
optimize this... Do strlen() ONLY if we need to check
for overflow.

Modified:
    httpd/httpd/trunk/modules/proxy/proxy_util.c

Modified: httpd/httpd/trunk/modules/proxy/proxy_util.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/proxy_util.c?rev=1228766&r1=1228765&r2=1228766&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/proxy/proxy_util.c (original)
+++ httpd/httpd/trunk/modules/proxy/proxy_util.c Sun Jan  8 01:40:01 2012
@@ -81,15 +81,18 @@ APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(prox
 PROXY_DECLARE(apr_status_t) ap_proxy_strncpy(char *dst, const char *src,
                                              apr_size_t dlen)
 {
-    if ((strlen(src)+1) > dlen) {
-        /* XXX: APR_ENOSPACE would be better */
-        return APR_EGENERAL;
-    }
-    else {
-        /* XXX: Once slen and dlen are known, no excuse not to memcpy */
-        apr_cpystrn(dst, src, dlen);
+    char *thenil;
+    apr_size_t thelen;
+
+    thenil = apr_cpystrn(dst, src, dlen);
+    thelen = thenil - dst;
+    /* Assume the typical case is smaller copying into bigger
+       so we have a fast return */
+    if ((thelen < dlen-1) || ((strlen(src)) == thelen)) {
+        return APR_SUCCESS;
     }
-    return APR_SUCCESS;
+    /* XXX: APR_ENOSPACE would be better */
+    return APR_EGENERAL;
 }
 
 /* already called in the knowledge that the characters are hex digits */



Mime
View raw message