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:46:42 GMT
trawick     2004/06/27 04:46:42

  Modified:    .        CHANGES
               strings  apr_snprintf.c
               test     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
  1.477     +3 -0      apr/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apr/CHANGES,v
  retrieving revision 1.476
  retrieving revision 1.477
  diff -u -r1.476 -r1.477
  --- CHANGES	23 Jun 2004 15:32:32 -0000	1.476
  +++ CHANGES	27 Jun 2004 11:46:42 -0000	1.477
  @@ -142,6 +142,9 @@
   
   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]
  
  
  
  1.39      +2 -1      apr/strings/apr_snprintf.c
  
  Index: apr_snprintf.c
  ===================================================================
  RCS file: /home/cvs/apr/strings/apr_snprintf.c,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- apr_snprintf.c	4 Apr 2004 11:50:17 -0000	1.38
  +++ apr_snprintf.c	27 Jun 2004 11:46:42 -0000	1.39
  @@ -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);
  
  
  
  1.24      +19 -0     apr/test/teststr.c
  
  Index: teststr.c
  ===================================================================
  RCS file: /home/cvs/apr/test/teststr.c,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- teststr.c	25 May 2004 12:46:15 -0000	1.23
  +++ teststr.c	27 Jun 2004 11:46:42 -0000	1.24
  @@ -125,6 +125,24 @@
       ABTS_ASSERT(tc, "buff unmangled", strcmp(buff, "FOOBAR") != 0);
   }
   
  +static void snprintf_underflow(abts_case *tc, void *data)
  +{
  +    char buf[20];
  +    int rv;
  +
  +    rv = apr_snprintf(buf, sizeof buf, "%.2f", (double)0.0001);
  +    ABTS_INT_EQUAL(tc, 4, rv);
  +    ABTS_STR_EQUAL(tc, "0.00", buf);
  +    
  +    rv = apr_snprintf(buf, sizeof buf, "%.2f", (double)0.001);
  +    ABTS_INT_EQUAL(tc, 4, rv);
  +    ABTS_STR_EQUAL(tc, "0.00", buf);
  +    
  +    rv = apr_snprintf(buf, sizeof buf, "%.2f", (double)0.01);
  +    ABTS_INT_EQUAL(tc, 4, rv);
  +    ABTS_STR_EQUAL(tc, "0.01", buf);
  +}
  +
   static void string_error(abts_case *tc, void *data)
   {
        char buf[128], *rv;
  @@ -267,6 +285,7 @@
       abts_run_test(suite, snprintf_0NULL, NULL);
       abts_run_test(suite, snprintf_0nonNULL, NULL);
       abts_run_test(suite, snprintf_noNULL, NULL);
  +    abts_run_test(suite, snprintf_underflow, NULL);
       abts_run_test(suite, test_strtok, NULL);
       abts_run_test(suite, string_error, NULL);
       abts_run_test(suite, string_long, NULL);
  
  
  

Mime
View raw message