diff options
-rw-r--r-- | sysdeps/mach/xpg-strerror.c | 16 |
1 files 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; } |