[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: svn commit: r1485007 - /subversion/branches/invoke-diff-cmd-feature/subversion/libsvn_subr/io.c

From: Philip Martin <philip.martin_at_wandisco.com>
Date: Wed, 22 May 2013 09:46:15 +0100

gbg_at_apache.org writes:

> Author: gbg
> Date: Tue May 21 22:57:23 2013
> New Revision: 1485007
>
> URL: http://svn.apache.org/r1485007
> Log:
> On the invoke-diff-cmd branch: Repair erroneous initialization.
>
> * subversion/svn/io.c
>
> (svn_io_run_external_diff): Change pcalloc to palloc call.
>
> Modified:
> subversion/branches/invoke-diff-cmd-feature/subversion/libsvn_subr/io.c
>
> Modified: subversion/branches/invoke-diff-cmd-feature/subversion/libsvn_subr/io.c
> URL: http://svn.apache.org/viewvc/subversion/branches/invoke-diff-cmd-feature/subversion/libsvn_subr/io.c?rev=1485007&r1=1485006&r2=1485007&view=diff
> ==============================================================================
> --- subversion/branches/invoke-diff-cmd-feature/subversion/libsvn_subr/io.c (original)
> +++ subversion/branches/invoke-diff-cmd-feature/subversion/libsvn_subr/io.c Tue May 21 22:57:23 2013
> @@ -3036,7 +3036,7 @@ svn_io_run_external_diff(const char *dir
> for (i = 0, size = 0; cmd[i]; i++)
> size += strlen(cmd[i]) + 1;
>
> - failed_command = apr_pcalloc(pool, size * sizeof(char *));
> + failed_command = apr_palloc(pool, size * sizeof(char *));
>
> for (i = 0; cmd[i]; i++)
> {
>

That's not right. You have calculated 'size' by summing strlen to give
you the total text length. Multiplying the text length by the sizeof a
pointer is wrong. You could multiply by sizeof(char) but that is 1. You
need to add +1 for the terminating null byte.

However this is an error path so I'd go for simplicity rather than
efficiency:

       const char *failed_command = "";
       for (i = 0; cmd[i]; ++i)
         {
           failed_command = apr_pstrcat(pool, failed_command, cmd[i]);
           failed_command = apr_pstrcat(pool, failed_command, " ");
         }

or:

       const char *failed_command = "";
       for (i = 0; cmd[i]; ++i)
         failed_command = apr_psprintf(pool, "%s %s", failed_command, cmd[i]);
          

-- 
Certified & Supported Apache Subversion Downloads:
http://www.wandisco.com/subversion/download
Received on 2013-05-22 10:46:53 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.