[Zlib-devel] zlib 1.2.2.3 available for testing

Nelson H. F. Beebe beebe at math.utah.edu
Mon May 30 18:00:50 EDT 2005


Greg Roelofs <newt at pobox.com> responds on Mon, 30 May 2005 14:28:33
-0700 to an exchange on this list between me and Mark Adler on the
failure of the zlib-1.2.2.3 tests on OSF/1 4.0 Alpha:

>> ...
>> I don't think this is likely to be relevant, but Ultrix (precursor to
>> OSF/1) was one of the few systems still returning a char pointer from
>> sprintf() as of the mid-1990s.  (SunOS was another.)  I'd be surprised
>> if that were still the case in OSF/1, but one never knows.  (Either way,
>> it's hard to see how that would affect an internally called strlen()
>> unless you overran your buffer.)
>> ...

The manual pages for printf(3) on OSF/1 4.0 say:

>> ...
>> NAME
>>        printf, fprintf, sprintf -  Print formatted output
>> 
>> LIBRARY
>>        Standard C Library (libc.so, libc.a)
>> 
>> SYNOPSIS
>>        #include <stdio.h>
>> ...
>>        int sprintf(
>>                char *string,
>>                const char *format
>>                [,value]...);
>> ...
>> RETURN VALUES
>>        Upon  successful completion, each of these functions returns the number
>>        of bytes  in  the  output  string.   Otherwise,  a  negative  value  is
>>        returned.
>> 
>>        The value returned by the sprintf() function does not include the final
>>        '\0' (null) character.
>> ...

A quick experiment verifies that the return value is a character
count, rather than a pointer to the target buffer:

% cat sprintf-test.c
/***********************************************************************
[30-May-2005]
***********************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int
main(int argc, char* argv[])
{
    int n;
    char buffer[512];

    n = sprintf(buffer, "Hello, world: PI is approximately %.17f", M_PI);
    (void)printf("sprintf() returns %d and sets buffer = \"%s\"\n", n, buffer);

    return (EXIT_SUCCESS);
}

% cc sprintf-test.c && ./a.out
sprintf() returns 53 and sets buffer = "Hello, world: PI is approximately 3.14159265358979310"

% gcc --version
gcc (GCC) 3.3.3
...

% gcc sprintf-test.c && ./a.out
sprintf() returns 53 and sets buffer = "Hello, world: PI is approximately 3.14159265358979310"

% lcc --version
lcc version 4.1.beta.9 [11-May-2001]

% lcc -DM_PI=3.14159265358979310 sprintf-test.c && ./a.out
sprintf() returns 53 and sets buffer = "Hello, world: PI is approximately 3.14159265358979310"

-------------------------------------------------------------------------------
- Nelson H. F. Beebe                    Tel: +1 801 581 5254                  -
- University of Utah                    FAX: +1 801 581 4148                  -
- Department of Mathematics, 110 LCB    Internet e-mail: beebe at math.utah.edu  -
- 155 S 1400 E RM 233                       beebe at acm.org  beebe at computer.org -
- Salt Lake City, UT 84112-0090, USA    URL: http://www.math.utah.edu/~beebe  -
-------------------------------------------------------------------------------




More information about the Zlib-devel mailing list