summaryrefslogtreecommitdiff
path: root/tests/strerror_r.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2022-10-24 22:25:44 +0200
committerJörg Frings-Fürst <debian@jff.email>2022-10-24 22:25:44 +0200
commitcb4186bef1b44691db4221406d001a8d40c65b4b (patch)
tree285662381eaa0514f988142bff0c8a9685c84dc0 /tests/strerror_r.c
parentcc0876a2fa9e703b1064992ab535f3eed57e9c71 (diff)
parent26112352a774737e1ce5580c93654a26c1e82b39 (diff)
Update upstream source from tag 'upstream/1.1'
Update to upstream version '1.1' with Debian dir acc8a9214de592a0bbbdb680385559210b329d52
Diffstat (limited to 'tests/strerror_r.c')
-rw-r--r--tests/strerror_r.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/tests/strerror_r.c b/tests/strerror_r.c
index 85a2189..b154c29 100644
--- a/tests/strerror_r.c
+++ b/tests/strerror_r.c
@@ -166,16 +166,19 @@ strerror_r (int errnum, char *buf, size_t buflen)
# if HAVE___XPG_STRERROR_R
ret = __xpg_strerror_r (errnum, buf, buflen);
- if (ret < 0)
- ret = errno;
+ /* ret is 0 upon success, or EINVAL or ERANGE upon failure. */
# endif
if (!*buf)
{
- /* glibc 2.13 would not touch buf on err, so we have to fall
- back to GNU strerror_r which always returns a thread-safe
- untruncated string to (partially) copy into our buf. */
- char *errstring = strerror_r (errnum, buf, buflen);
+ /* glibc 2.13 ... 2.34 (at least) don't touch buf upon failure.
+ Therefore we have to fall back to strerror_r which, for valid
+ errnum, returns a thread-safe untruncated string. For invalid
+ errnum, though, it returns a truncated string, which does not
+ allow us to determine whether to return ERANGE or 0. Thus we
+ need to pass a sufficiently large buffer. */
+ char stackbuf[80];
+ char *errstring = strerror_r (errnum, stackbuf, sizeof stackbuf);
ret = errstring ? safe_copy (buf, buflen, errstring) : errno;
}
}