bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

vasnprintf: fix overflow detection on OSF/1 5.1


From: Bruno Haible
Subject: vasnprintf: fix overflow detection on OSF/1 5.1
Date: Sat, 3 Nov 2007 15:26:41 +0100
User-agent: KMail/1.5.4

On OSF/1 5.1, the printf() and fprintf() replacements no longer produced
output of more than 1999 bytes. Wheeee...


2007-11-03  Bruno Haible  <address@hidden>

        * lib/vasnprintf.c (VASNPRINTF): Don't assume that snprintf's return
        value is C99 compliant.
        Needed for OSF/1 5.1.

*** lib/vasnprintf.c.orig       2007-11-03 15:20:09.000000000 +0100
--- lib/vasnprintf.c    2007-11-03 15:20:02.000000000 +0100
***************
*** 3658,3665 ****
                      }
  
  #if USE_SNPRINTF
!                   /* Handle overflow of the allocated buffer.  */
!                   if (count >= maxlen)
                      {
                        /* If maxlen already has attained its allowed maximum,
                           allocating more memory will not increase maxlen.
--- 3658,3669 ----
                      }
  
  #if USE_SNPRINTF
!                   /* Handle overflow of the allocated buffer.
!                      If such an overflow occurs, a C99 compliant snprintf()
!                      returns a count >= maxlen.  However, a non-compliant
!                      snprintf() function returns only count = maxlen - 1.  To
!                      cover both cases, test whether count >= maxlen - 1.  */
!                   if ((unsigned int) count + 1 >= maxlen)
                      {
                        /* If maxlen already has attained its allowed maximum,
                           allocating more memory will not increase maxlen.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]