apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject cvs commit: apr/test teststr.c
Date Sun, 25 Aug 2002 04:22:36 GMT
rbb         2002/08/24 21:22:36

  Modified:    .        CHANGES
               strings  apr_snprintf.c
               test     teststr.c
  Log:
  If the length argument to apr_snprintf is 0, then we should return the
  length that the string would be if we actually were going to fill it out.
  However, if the length argument is 0, we can also accept a NULL string.
  Also, added a test case for this.
  
  Revision  Changes    Path
  1.326     +5 -0      apr/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apr/CHANGES,v
  retrieving revision 1.325
  retrieving revision 1.326
  diff -u -r1.325 -r1.326
  --- CHANGES	25 Aug 2002 04:10:39 -0000	1.325
  +++ CHANGES	25 Aug 2002 04:22:35 -0000	1.326
  @@ -1,5 +1,10 @@
   Changes with APR 0.9.0
   
  +  *) If the length argument to apr_snprintf is 0, then we should return the
  +     length that the string would be if we actually were going to fill it out.
  +     However, if the length argument is 0, we can also accept a NULL string.
  +     Also, added a test case for this.  [Ryan Bloom]
  +
     *) Printing a string with apr_snprintf can seg fault, if a precision is
        specified for the string, and the string being printed doesn't have a
        trailing '\0'.  Fix that seg fault by not calling strlen if a precision
  
  
  
  1.27      +15 -15    apr/strings/apr_snprintf.c
  
  Index: apr_snprintf.c
  ===================================================================
  RCS file: /home/cvs/apr/strings/apr_snprintf.c,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- apr_snprintf.c	25 Aug 2002 04:10:40 -0000	1.26
  +++ apr_snprintf.c	25 Aug 2002 04:22:35 -0000	1.27
  @@ -294,14 +294,16 @@
    */
   #define INS_CHAR(c, sp, bep, cc)                    \
   {                                                   \
  -    if (sp >= bep) {                                \
  -        vbuff->curpos = sp;                         \
  -        if (flush_func(vbuff))                      \
  -            return -1;                              \
  -        sp = vbuff->curpos;                         \
  -        bep = vbuff->endpos;                        \
  +    if (sp) {                                       \
  +        if (sp >= bep) {                            \
  +            vbuff->curpos = sp;                     \
  +            if (flush_func(vbuff))                  \
  +                return -1;                          \
  +            sp = vbuff->curpos;                     \
  +            bep = vbuff->endpos;                    \
  +        }                                           \
  +        *sp++ = (c);                                \
       }                                               \
  -    *sp++ = (c);                                    \
       cc++;                                           \
   }
   
  @@ -1247,16 +1249,15 @@
       va_list ap;
       apr_vformatter_buff_t vbuff;
   
  -    if (len == 0)
  -        return 0;
  -
       /* save one byte for nul terminator */
       vbuff.curpos = buf;
       vbuff.endpos = buf + len - 1;
       va_start(ap, format);
       cc = apr_vformatter(snprintf_flush, &vbuff, format, ap);
       va_end(ap);
  -    *vbuff.curpos = '\0';
  +    if (len != 0) {
  +        *vbuff.curpos = '\0';
  +    }
       return (cc == -1) ? (int)len : cc;
   }
   
  @@ -1267,13 +1268,12 @@
       int cc;
       apr_vformatter_buff_t vbuff;
   
  -    if (len == 0)
  -        return 0;
  -
       /* save one byte for nul terminator */
       vbuff.curpos = buf;
       vbuff.endpos = buf + len - 1;
       cc = apr_vformatter(snprintf_flush, &vbuff, format, ap);
  -    *vbuff.curpos = '\0';
  +    if (len != 0) {
  +        *vbuff.curpos = '\0';
  +    }
       return (cc == -1) ? (int)len : cc;
   }
  
  
  
  1.5       +10 -0     apr/test/teststr.c
  
  Index: teststr.c
  ===================================================================
  RCS file: /home/cvs/apr/test/teststr.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- teststr.c	25 Aug 2002 04:10:40 -0000	1.4
  +++ teststr.c	25 Aug 2002 04:22:36 -0000	1.5
  @@ -124,6 +124,7 @@
   {
       char buff[100];
       char *testing = apr_palloc(p, 10);
  +    int rv;
   
       testing[0] = 't';
       testing[1] = 'e';
  @@ -135,10 +136,19 @@
       
       fprintf(stderr, "Testing precision  ........  ");
       apr_snprintf(buff, sizeof(buff), "%.*s", 7, testing);
  +    /* If this test fails, we are going to seg fault, so there is no reason
  +     * to print a failure message.  rbb
  +     */
       if (!strncmp(buff, testing, 7)) {
           fprintf(stderr, "OK\n");
       }
   
  +    fprintf(stderr, "Testing 0 length ..........  ");
  +    rv = apr_snprintf(NULL, 0, "%sBAR", "FOO");
  +    if (rv != 6) {
  +        fprintf(stderr, "FAILED\n");
  +    }
  +    fprintf(stderr, "OK\n");
   }
   
   int main(int argc, const char * const argv[])
  
  
  

Mime
View raw message