bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: John David Anglin <dave.anglin@bell.net>
To: "bug-gnulib@gnu.org List" <bug-gnulib@gnu.org>
Subject: snprintf function is not C99 compliant on PA-RISC HP-UX 11.00 through 11.11
Date: Wed, 22 Sep 2021 14:27:05 -0400	[thread overview]
Message-ID: <8fef0faa-3a5f-4ae6-bcc2-b4a387379747@bell.net> (raw)

When I run configure on applications using the gnulib (e.g., bison), I get the following defines
in config.h:

/* Define if the return value of the snprintf function is the number of of
   bytes (excluding the terminating NUL) that would have been produced if the
   buffer had been large enough. */
#define HAVE_SNPRINTF_RETVAL_C99 1

/* Define if the string produced by the snprintf function is always NUL
   terminated. */
#define HAVE_SNPRINTF_TRUNCATION_C99 1

The HAVE_SNPRINTF_RETVAL define is definitely incorrect for HP-UX 11.11:

 RETURN VALUE
      Each function returns the number of bytes transmitted (excluding the
      \0 in the case of sprintf() or a negative value if an output error was
      encountered.

I would not trust that the string is always null terminated when an error occurs.

The behavior on 11.31 may be correct when application is compiled for UNIX 2003 but maybe it's best
to assume snprintf is not C99 compliant on all versions of HP-UX.  Changing the defines as follows
seems to work fine:

/* Define if the return value of the snprintf function is the number of of
   bytes (excluding the terminating NUL) that would have been produced if the
   buffer had been large enough. */
/* #undef HAVE_SNPRINTF_RETVAL_C99 */

/* Define if the string produced by the snprintf function is always NUL
   terminated. */
/* #undef HAVE_SNPRINTF_TRUNCATION_C99 */

Haven't had time to find why the configure ouput is wrong.

Dave
-- 
John David Anglin  dave.anglin@bell.net


                 reply	other threads:[~2021-09-22 18:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8fef0faa-3a5f-4ae6-bcc2-b4a387379747@bell.net \
    --to=dave.anglin@bell.net \
    --cc=bug-gnulib@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).