public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [hurd,commited 0/2] fix strerror functions
@ 2022-08-27 13:48 Samuel Thibault
  2022-08-27 13:48 ` [hurd,commited 1/2] mach: Fix incoherency between perror and strerror Samuel Thibault
  2022-08-27 13:48 ` [hurd,commited 2/2] mach: Make xpg_strerror_r set a message on error Samuel Thibault
  0 siblings, 2 replies; 4+ messages in thread
From: Samuel Thibault @ 2022-08-27 13:48 UTC (permalink / raw)
  To: libc-alpha; +Cc: Samuel Thibault, commit-hurd

Samuel Thibault (2):
  mach: Fix incoherency between perror and strerror
  mach: Make xpg_strerror_r set a message on error

 sysdeps/mach/_strerror.c    |  2 +-
 sysdeps/mach/xpg-strerror.c | 16 ++++++++++------
 2 files changed, 11 insertions(+), 7 deletions(-)

-- 
2.35.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [hurd,commited 1/2] mach: Fix incoherency between perror and strerror
  2022-08-27 13:48 [hurd,commited 0/2] fix strerror functions Samuel Thibault
@ 2022-08-27 13:48 ` Samuel Thibault
  2022-08-27 13:48   ` [hurd, commited " Samuel Thibault
  2022-08-27 13:48 ` [hurd,commited 2/2] mach: Make xpg_strerror_r set a message on error Samuel Thibault
  1 sibling, 1 reply; 4+ messages in thread
From: Samuel Thibault @ 2022-08-27 13:48 UTC (permalink / raw)
  To: libc-alpha; +Cc: Samuel Thibault, commit-hurd

08d2024b4167 ("string: Simplify strerror_r") inadvertently made
__strerror_r print unknown error system in decimal while the original
code was printing it in hexadecimal. perror was kept printing in
hexadecimal in 725eeb4af14c ("string: Use tls-internal on strerror_l"),
let us keep both coherent.

This also fixes a duplicate ':'

Spotted by the libunistring testsuite test-perror2
---
 sysdeps/mach/_strerror.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sysdeps/mach/_strerror.c b/sysdeps/mach/_strerror.c
index b179c440d3..acc00612bb 100644
--- a/sysdeps/mach/_strerror.c
+++ b/sysdeps/mach/_strerror.c
@@ -40,7 +40,7 @@ __strerror_r (int errnum, char *buf, size_t buflen)
 
   if (system > err_max_system || ! __mach_error_systems[system].bad_sub)
     {
-      __snprintf (buf, buflen, "%s: %d", _("Error in unknown error system: "),
+      __snprintf (buf, buflen, "%s%X", _("Error in unknown error system: "),
 		  errnum);
       return buf;
     }
-- 
2.35.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [hurd, commited 1/2] mach: Fix incoherency between perror and strerror
  2022-08-27 13:48 ` [hurd,commited 1/2] mach: Fix incoherency between perror and strerror Samuel Thibault
@ 2022-08-27 13:48   ` Samuel Thibault
  0 siblings, 0 replies; 4+ messages in thread
From: Samuel Thibault @ 2022-08-27 13:48 UTC (permalink / raw)
  To: libc-alpha; +Cc: Samuel Thibault, commit-hurd

08d2024b4167 ("string: Simplify strerror_r") inadvertently made
__strerror_r print unknown error system in decimal while the original
code was printing it in hexadecimal. perror was kept printing in
hexadecimal in 725eeb4af14c ("string: Use tls-internal on strerror_l"),
let us keep both coherent.

This also fixes a duplicate ':'

Spotted by the libunistring testsuite test-perror2
---
 sysdeps/mach/_strerror.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sysdeps/mach/_strerror.c b/sysdeps/mach/_strerror.c
index b179c440d3..acc00612bb 100644
--- a/sysdeps/mach/_strerror.c
+++ b/sysdeps/mach/_strerror.c
@@ -40,7 +40,7 @@ __strerror_r (int errnum, char *buf, size_t buflen)
 
   if (system > err_max_system || ! __mach_error_systems[system].bad_sub)
     {
-      __snprintf (buf, buflen, "%s: %d", _("Error in unknown error system: "),
+      __snprintf (buf, buflen, "%s%X", _("Error in unknown error system: "),
 		  errnum);
       return buf;
     }
-- 
2.35.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [hurd,commited 2/2] mach: Make xpg_strerror_r set a message on error
  2022-08-27 13:48 [hurd,commited 0/2] fix strerror functions Samuel Thibault
  2022-08-27 13:48 ` [hurd,commited 1/2] mach: Fix incoherency between perror and strerror Samuel Thibault
@ 2022-08-27 13:48 ` Samuel Thibault
  1 sibling, 0 replies; 4+ messages in thread
From: Samuel Thibault @ 2022-08-27 13:48 UTC (permalink / raw)
  To: libc-alpha; +Cc: Samuel Thibault, commit-hurd

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
---
 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;
 }
-- 
2.35.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-08-27 13:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-27 13:48 [hurd,commited 0/2] fix strerror functions Samuel Thibault
2022-08-27 13:48 ` [hurd,commited 1/2] mach: Fix incoherency between perror and strerror Samuel Thibault
2022-08-27 13:48   ` [hurd, commited " Samuel Thibault
2022-08-27 13:48 ` [hurd,commited 2/2] mach: Make xpg_strerror_r set a message on error Samuel Thibault

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).