You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2013/12/18 12:29:29 UTC

svn commit: r1551917 - /subversion/trunk/subversion/svnserve/logger.c

Author: stsp
Date: Wed Dec 18 11:29:29 2013
New Revision: 1551917

URL: http://svn.apache.org/r1551917
Log:
* subversion/svnserve/logger.c
  (logger__log_error): Replace strcpy()/strlen() calls with a single call
   to apr_snprintf() which performs bounds checking and calculates the
   length for us. No functional change.

Modified:
    subversion/trunk/subversion/svnserve/logger.c

Modified: subversion/trunk/subversion/svnserve/logger.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/svnserve/logger.c?rev=1551917&r1=1551916&r2=1551917&view=diff
==============================================================================
--- subversion/trunk/subversion/svnserve/logger.c (original)
+++ subversion/trunk/subversion/svnserve/logger.c Wed Dec 18 11:29:29 2013
@@ -149,8 +149,8 @@ logger__log_error(logger_t *logger,
           if (len > sizeof(errstr) - sizeof(APR_EOL_STR)) {
             len = sizeof(errstr) - sizeof(APR_EOL_STR);
           }
-          strcpy(errstr + len, APR_EOL_STR);
-          len += strlen(APR_EOL_STR);
+          len += apr_snprintf(errstr + len, sizeof(APR_EOL_STR),
+                              "%s", APR_EOL_STR);
           svn_error_clear(svn_stream_write(logger->stream, errstr, &len));
 
           continuation = "-";



Re: svn commit: r1551917 - /subversion/trunk/subversion/svnserve/logger.c

Posted by Stefan Sperling <st...@apache.org>.
On Wed, Dec 18, 2013 at 10:22:26PM +0100, Bert Huijben wrote:
> Can you explain why you changed this?
> 
> This changes one bit of dynamic calculation to another bit of dynamic calculation while this string is completely constant. You now use the compiler to optimize away a strlen, but apr_snprintf() has a lot more overhead in other places (variable arguments, parsing the format string, etc.).
> 
> In this case I'm really wondering why we change working code...?
> 
> 	Bert 
> 

I just think we shouldn't use strcpy() anywhere. It's always a
red flag for me when reading code. In this case it does no harm,
of course, but I still think code using strcpy() is generally
bad style. The function should be phased out of general use.

Feel free to revert this if the alleged performance overhead
in the logging subsystem of svnserve concerns you more than my
peace of mind that we don't use strcpy() in our core code (all
other instances I found where in tests or generated bindings code
where I don't care as much but wouldn't mind seeing them eradicated
either).

RE: svn commit: r1551917 - /subversion/trunk/subversion/svnserve/logger.c

Posted by Bert Huijben <be...@qqmail.nl>.

> -----Original Message-----
> From: stsp@apache.org [mailto:stsp@apache.org]
> Sent: woensdag 18 december 2013 12:29
> To: commits@subversion.apache.org
> Subject: svn commit: r1551917 -
> /subversion/trunk/subversion/svnserve/logger.c
> 
> Author: stsp
> Date: Wed Dec 18 11:29:29 2013
> New Revision: 1551917
> 
> URL: http://svn.apache.org/r1551917
> Log:
> * subversion/svnserve/logger.c
>   (logger__log_error): Replace strcpy()/strlen() calls with a single call
>    to apr_snprintf() which performs bounds checking and calculates the
>    length for us. No functional change.
> 
> Modified:
>     subversion/trunk/subversion/svnserve/logger.c
> 
> Modified: subversion/trunk/subversion/svnserve/logger.c
> URL:
> http://svn.apache.org/viewvc/subversion/trunk/subversion/svnserve/logge
> r.c?rev=1551917&r1=1551916&r2=1551917&view=diff
> ==========================================================
> ====================
> --- subversion/trunk/subversion/svnserve/logger.c (original)
> +++ subversion/trunk/subversion/svnserve/logger.c Wed Dec 18 11:29:29
> 2013
> @@ -149,8 +149,8 @@ logger__log_error(logger_t *logger,
>            if (len > sizeof(errstr) - sizeof(APR_EOL_STR)) {
>              len = sizeof(errstr) - sizeof(APR_EOL_STR);
>            }
> -          strcpy(errstr + len, APR_EOL_STR);
> -          len += strlen(APR_EOL_STR);
> +          len += apr_snprintf(errstr + len, sizeof(APR_EOL_STR),
> +                              "%s", APR_EOL_STR);
>            svn_error_clear(svn_stream_write(logger->stream, errstr, &len));

Can you explain why you changed this?

This changes one bit of dynamic calculation to another bit of dynamic calculation while this string is completely constant. You now use the compiler to optimize away a strlen, but apr_snprintf() has a lot more overhead in other places (variable arguments, parsing the format string, etc.).

In this case I'm really wondering why we change working code...?

	Bert