You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by rb...@locus.apache.org on 2000/10/18 05:21:15 UTC

cvs commit: apache-2.0/src/lib/apr/strings apr_cpystrn.c

rbb         00/10/17 20:21:15

  Modified:    src/lib/apr/strings apr_cpystrn.c
  Log:
  Cleanup apr_tokenize_to_argv a bit, and fix a problem where we weren't
  allocating enough memory for the argv array.  This brings us closer to
  getting piped logs working again.
  
  Revision  Changes    Path
  1.5       +7 -10     apache-2.0/src/lib/apr/strings/apr_cpystrn.c
  
  Index: apr_cpystrn.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/strings/apr_cpystrn.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- apr_cpystrn.c	2000/10/16 06:04:48	1.4
  +++ apr_cpystrn.c	2000/10/18 03:21:14	1.5
  @@ -172,7 +172,7 @@
           SKIP_WHITESPACE(tmpCnt);
       }
   
  -    *argv_out = apr_palloc(token_context, numargs*sizeof(char*));
  +    *argv_out = apr_palloc(token_context, (numargs + 1)*sizeof(char*));
       if (*argv_out == NULL) {
           return (APR_ENOMEM);
       }
  @@ -183,17 +183,14 @@
           CHECK_QUOTATION(cp, isquoted);
           tmpCnt = cp;
           DETERMINE_NEXTSTRING(cp, isquoted);
  -        if (*cp == '\0') {
  -            (*argv_out)[numargs] = apr_pstrdup(token_context, tmpCnt);
  -            numargs++;
  +        cp++;
  +        (*argv_out)[numargs] = apr_palloc(token_context, cp - tmpCnt);
  +        apr_cpystrn((*argv_out)[numargs], tmpCnt, cp - tmpCnt);
  +        numargs++;
  +        /* This needs to be -1 because we move past the end above. */
  +        if (*(cp - 1) == '\0') {
               (*argv_out)[numargs] = '\0';
               break;
  -        }
  -        else {
  -            cp++;
  -            (*argv_out)[numargs] = apr_palloc(token_context, cp - tmpCnt);
  -            apr_cpystrn((*argv_out)[numargs], tmpCnt, cp - tmpCnt);
  -            numargs++;
           }
           
           SKIP_WHITESPACE(cp);