apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@apache.org
Subject cvs commit: apr/test teststr.c
Date Sun, 27 Jun 2004 11:45:11 GMT
trawick     2004/06/27 04:45:11

  Modified:    .        Tag: APR_0_9_BRANCH CHANGES
               strings  Tag: APR_0_9_BRANCH apr_snprintf.c
               test     Tag: APR_0_9_BRANCH teststr.c
  Log:
  Fix apr_snprintf() to respect precision for small floating point
  numbers.
  
  PR:            29621
  Submitted by:  Artur Zaprzala <zybi talex.pl>
  Reviewed by:   Jeff Trawick
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.426.2.25 +3 -0      apr/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apr/CHANGES,v
  retrieving revision 1.426.2.24
  retrieving revision 1.426.2.25
  diff -u -r1.426.2.24 -r1.426.2.25
  --- CHANGES	23 Jun 2004 15:07:58 -0000	1.426.2.24
  +++ CHANGES	27 Jun 2004 11:45:11 -0000	1.426.2.25
  @@ -1,5 +1,8 @@
   Changes with APR 0.9.5
   
  +  *) Fix apr_snprintf() to respect precision for small floating point
  +     numbers.  PR 29621.  [Artur Zaprzala <zybi talex.pl>]
  +
     *) Add command type APR_SHELLCMD_ENV for creating a process
        which is started by the shell and which inherits the parent's
        environment variables.  [Jeff Trawick]
  
  
  
  No                   revision
  No                   revision
  1.35.2.3  +2 -1      apr/strings/apr_snprintf.c
  
  Index: apr_snprintf.c
  ===================================================================
  RCS file: /home/cvs/apr/strings/apr_snprintf.c,v
  retrieving revision 1.35.2.2
  retrieving revision 1.35.2.3
  diff -u -r1.35.2.2 -r1.35.2.3
  --- apr_snprintf.c	4 Apr 2004 15:21:08 -0000	1.35.2.2
  +++ apr_snprintf.c	27 Jun 2004 11:45:11 -0000	1.35.2.3
  @@ -132,11 +132,12 @@
       p1 = &buf[ndigits];
       if (eflag == 0)
           p1 += r2;
  -    *decpt = r2;
       if (p1 < &buf[0]) {
  +        *decpt = -ndigits;
           buf[0] = '\0';
           return (buf);
       }
  +    *decpt = r2;
       while (p <= p1 && p < &buf[NDIG]) {
           arg *= 10;
           arg = modf(arg, &fj);
  
  
  
  No                   revision
  No                   revision
  1.16.2.3  +19 -0     apr/test/teststr.c
  
  Index: teststr.c
  ===================================================================
  RCS file: /home/cvs/apr/test/teststr.c,v
  retrieving revision 1.16.2.2
  retrieving revision 1.16.2.3
  diff -u -r1.16.2.2 -r1.16.2.3
  --- teststr.c	4 Apr 2004 15:21:08 -0000	1.16.2.2
  +++ teststr.c	27 Jun 2004 11:45:11 -0000	1.16.2.3
  @@ -142,6 +142,24 @@
       CuAssertStrEquals(tc, buf, "3141592653589793238");
   }
   
  +static void snprintf_underflow(CuTest *tc)
  +{
  +    char buf[20];
  +    int rv;
  +
  +    rv = apr_snprintf(buf, sizeof buf, "%.2f", (double)0.0001);
  +    CuAssertIntEquals(tc, 4, rv);
  +    CuAssertStrEquals(tc, "0.00", buf);
  +    
  +    rv = apr_snprintf(buf, sizeof buf, "%.2f", (double)0.001);
  +    CuAssertIntEquals(tc, 4, rv);
  +    CuAssertStrEquals(tc, "0.00", buf);
  +    
  +    rv = apr_snprintf(buf, sizeof buf, "%.2f", (double)0.01);
  +    CuAssertIntEquals(tc, 4, rv);
  +    CuAssertStrEquals(tc, "0.01", buf);
  +}
  +
   static void string_error(CuTest *tc)
   {
        char buf[128], *rv;
  @@ -271,6 +289,7 @@
       SUITE_ADD_TEST(suite, snprintf_0nonNULL);
       SUITE_ADD_TEST(suite, snprintf_noNULL);
       SUITE_ADD_TEST(suite, snprintf_int64);
  +    SUITE_ADD_TEST(suite, snprintf_underflow);
       SUITE_ADD_TEST(suite, test_strtok);
       SUITE_ADD_TEST(suite, string_error);
       SUITE_ADD_TEST(suite, string_long);
  
  
  

Mime
View raw message