[glib/3v1n0/strerror_r-int-variant-support: 2/2] gstrfuncs: Handle the case strerror_r returns an error




commit b5d5fd622d0b32a001769e0f3080c2a1a03a9a53
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Wed Jul 6 23:54:14 2022 +0200

    gstrfuncs: Handle the case strerror_r returns an error
    
    In the case strerror_r returns an error (both in the char* variant and
    in the int variant) we should not try to proceed converting the message
    and adding to the errors maps, as that's likely causing errors.
    
    So, let's just return a null string in case this happens

 glib/gstrfuncs.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
---
diff --git a/glib/gstrfuncs.c b/glib/gstrfuncs.c
index 21ec0b578e..5e28c3ee47 100644
--- a/glib/gstrfuncs.c
+++ b/glib/gstrfuncs.c
@@ -1345,13 +1345,22 @@ g_strerror (gint errnum)
 #  if defined(STRERROR_R_CHAR_P)
       msg = strerror_r (errnum, buf, sizeof (buf));
 #  else
-      (void) strerror_r (errnum, buf, sizeof (buf));
-      msg = buf;
+      if (strerror_r (errnum, buf, sizeof (buf)) == 0)
+        msg = buf;
 #  endif /* HAVE_STRERROR_R */
 #else
       g_strlcpy (buf, strerror (errnum), sizeof (buf));
       msg = buf;
 #endif
+
+      if (!msg)
+        {
+          G_UNLOCK (errors);
+
+          errno = saved_errno;
+          return msg;
+        }
+
       if (!g_get_console_charset (NULL))
         {
           msg = g_locale_to_utf8 (msg, -1, NULL, NULL, &error);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]