[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::digital_unix

Title:DIGITAL UNIX(FORMERLY KNOWN AS DEC OSF/1)
Notice:Welcome to the Digital UNIX Conference
Moderator:SMURF::DENHAM
Created:Thu Mar 16 1995
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:10068
Total number of notes:35879

9545.0. "sprintf and trailing %" by RDGENG::newdial_p12.reo.dec.com::readings_r () Fri Apr 18 1997 08:05

sprintf() on Digital UNIX gets confused by a trailing %, which really shouldn't 
be there anyway (should be %s, %d, ..., %%, or nothing at all).

For example the following code:

#include <stdio.h>
#include <errno.h>

main()
{
        extern int errno;
        char * g_outBuf = (char *) malloc(1024);
        int r, count = 5;

        r = sprintf (g_outBuf, "SET^DOSET^%s^%d%", "source", count);

        printf ("count = %d, g_outBuf = <%s>\n", count, g_outBuf);
        printf ("r = %d, errno = %d\n", r, errno);
}

prints this under Digital UNIX:

        count = 5, g_outBuf = <>
        r = -1, errno = 0

but under other OS's, e.g. NT:

count = 5, g_outBuf = <SET^DOSET^source^5>
r = 18, errno = 0

Boris Gubenko in a reply to my original posting in the DECC conference (note 
2149) advises:

  NT exhibits the correct behavior. A single "%" presents an illegal conversion
  specification. The result of processing such specification in not specified
  by the standard.

  From XPG4, for example,  "if a conversion specification does not match one
  of the above forms, the behavior is undefined".

  However, each legal conversion specification must result in fetching one or
  more arguments and converting, formatting and printing them.

  The function also should not return -1 due to illegal conversion
  specification.

  From the Return Value section:

  ... these function return ... a negative value if an output error was
  encountered.

Should I QAR this?

Richard

T.RTitleUserPersonal
Name
DateLines
9545.1QUARRY::nethCraig NethFri Apr 18 1997 10:413
>Should I QAR this?

Yup.