public inbox for glibc-cvs@sourceware.org help / color / mirror / Atom feed
From: Samuel Thibault <sthibaul@sourceware.org> To: glibc-cvs@sourceware.org Subject: [glibc] mach: Make xpg_strerror_r set a message on error Date: Sat, 27 Aug 2022 13:48:21 +0000 (GMT) [thread overview] Message-ID: <20220827134821.33044388DD2C@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=cb033e6b0ca7b8873cd00687ffd1828038a595d3 commit cb033e6b0ca7b8873cd00687ffd1828038a595d3 Author: Samuel Thibault <samuel.thibault@ens-lyon.org> Date: Sat Aug 27 14:46:23 2022 +0200 mach: Make xpg_strerror_r set a message on error posix advises to have strerror_r fill a message even when we are returning an error. This makes mach's xpg_strerror_r do this, like the generic version does. Spotted by the libunistring testsuite test-strerror_r Diff: --- sysdeps/mach/xpg-strerror.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/sysdeps/mach/xpg-strerror.c b/sysdeps/mach/xpg-strerror.c index 92bb67e2bc..de75cc84ae 100644 --- a/sysdeps/mach/xpg-strerror.c +++ b/sysdeps/mach/xpg-strerror.c @@ -51,7 +51,11 @@ __xpg_strerror_r (int errnum, char *buf, size_t buflen) code = err_get_code (errnum); if (system > err_max_system || ! __mach_error_systems[system].bad_sub) - return EINVAL; + { + __snprintf (buf, buflen, "%s%X", _("Error in unknown error system: "), + errnum); + return EINVAL; + } es = &__mach_error_systems[system]; @@ -62,11 +66,11 @@ __xpg_strerror_r (int errnum, char *buf, size_t buflen) else estr = (const char *) _(es->subsystem[sub].codes[code]); - size_t estrlen = strlen (estr) + 1; + size_t estrlen = strlen (estr); - if (buflen < estrlen) - return ERANGE; + /* Terminate the string in any case. */ + if (buflen > 0) + *((char *) __mempcpy (buf, estr, MIN (buflen - 1, estrlen))) = '\0'; - memcpy (buf, estr, estrlen); - return 0; + return buflen <= estrlen ? ERANGE : 0; }
reply other threads:[~2022-08-27 13:48 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 * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220827134821.33044388DD2C@sourceware.org \ --to=sthibaul@sourceware.org \ --cc=glibc-cvs@sourceware.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: linkBe 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).