public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "vda dot linux at googlemail dot com" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sources.redhat.com
Subject: [Bug libc/364] strerror_r does not copy error string to user supplied buffer
Date: Tue, 04 Jul 2006 11:22:00 -0000	[thread overview]
Message-ID: <20060704112249.32764.qmail@sourceware.org> (raw)
In-Reply-To: <20040902190535.364.dancasimiro@alum.rpi.edu>


------- Additional Comments From vda dot linux at googlemail dot com  2006-07-04 11:22 -------
glibc 2.4 include/string.h says:

#if defined __USE_XOPEN2K || defined __USE_MISC
/* Reentrant version of `strerror'.
   There are 2 flavors of `strerror_r', GNU which returns the string
   and may or may not use the supplied temporary buffer and POSIX one
   which fills the string into the buffer.
   To use the POSIX version, -D_XOPEN_SOURCE=600 or -D_POSIX_C_SOURCE=200112L
   without -D_GNU_SOURCE is needed, otherwise the GNU version is
   preferred.  */
# if defined __USE_XOPEN2K && !defined __USE_GNU
/* Fill BUF with a string describing the meaning of the `errno' code in
   ERRNUM.  */
#  ifdef __REDIRECT_NTH
extern int __REDIRECT_NTH (strerror_r,
                           (int __errnum, char *__buf, size_t __buflen),
                           __xpg_strerror_r) __nonnull ((2));
#  else
extern int __xpg_strerror_r (int __errnum, char *__buf, size_t __buflen)
     __THROW __nonnull ((2));
#   define strerror_r __xpg_strerror_r
#  endif
# else
/* If a temporary buffer is required, at most BUFLEN bytes of BUF will be
   used.  */
extern char *strerror_r (int __errnum, char *__buf, size_t __buflen)
     __THROW __nonnull ((2));
# endif
#endif

Manpage says the same. However the testcase below shows that
POSIX version of strerr_r is selected _without_ -D_XOPEN_SOURCE=600
or -D_POSIX_C_SOURCE=200112L:

#include <errno.h>
#include <string.h>
#include <stdio.h>
main()
{
  int i;
  char buf[1024] = "junk";
  i = strerror_r(ERANGE, buf, 5);
  printf("%d:%s\n",i,buf);
  i = strerror_r(ERANGE, buf, 1024);
  printf("%d:%s\n",i,buf);
  return 0;
}

See? It returns int, not char*.

# ./a.out
-1:junk
0:Numerical result out of range


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |


http://sourceware.org/bugzilla/show_bug.cgi?id=364

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


  parent reply	other threads:[~2006-07-04 11:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-02 19:05 [Bug libc/364] New: " dancasimiro at alum dot rpi dot edu
2004-09-02 19:07 ` [Bug libc/364] " dancasimiro at alum dot rpi dot edu
2004-09-02 21:07 ` schwab at suse dot de
2006-07-04 11:22 ` vda dot linux at googlemail dot com [this message]
2006-07-04 11:40 ` jakub at redhat dot com
2006-07-04 11:57 ` vda dot linux at googlemail dot com
2006-07-04 13:32 ` vda dot linux at googlemail dot com

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

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

  git send-email \
    --in-reply-to=20060704112249.32764.qmail@sourceware.org \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sources.redhat.com \
    /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).