mirror of
				https://gitlab.gnome.org/GNOME/glib.git
				synced 2025-11-03 17:48:56 +01:00 
			
		
		
		
	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
This commit is contained in:
		@@ -1336,6 +1336,9 @@ g_strerror (gint errnum)
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
      gchar buf[1024];
 | 
					      gchar buf[1024];
 | 
				
			||||||
      GError *error = NULL;
 | 
					      GError *error = NULL;
 | 
				
			||||||
 | 
					#if defined(HAVE_STRERROR_R) && !defined(STRERROR_R_CHAR_P)
 | 
				
			||||||
 | 
					      int ret;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(G_OS_WIN32)
 | 
					#if defined(G_OS_WIN32)
 | 
				
			||||||
      strerror_s (buf, sizeof (buf), errnum);
 | 
					      strerror_s (buf, sizeof (buf), errnum);
 | 
				
			||||||
@@ -1345,13 +1348,23 @@ g_strerror (gint errnum)
 | 
				
			|||||||
#  if defined(STRERROR_R_CHAR_P)
 | 
					#  if defined(STRERROR_R_CHAR_P)
 | 
				
			||||||
      msg = strerror_r (errnum, buf, sizeof (buf));
 | 
					      msg = strerror_r (errnum, buf, sizeof (buf));
 | 
				
			||||||
#  else
 | 
					#  else
 | 
				
			||||||
      (void) strerror_r (errnum, buf, sizeof (buf));
 | 
					      ret = strerror_r (errnum, buf, sizeof (buf));
 | 
				
			||||||
      msg = buf;
 | 
					      if (ret == 0 || ret == EINVAL)
 | 
				
			||||||
 | 
					        msg = buf;
 | 
				
			||||||
#  endif /* HAVE_STRERROR_R */
 | 
					#  endif /* HAVE_STRERROR_R */
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
      g_strlcpy (buf, strerror (errnum), sizeof (buf));
 | 
					      g_strlcpy (buf, strerror (errnum), sizeof (buf));
 | 
				
			||||||
      msg = buf;
 | 
					      msg = buf;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (!msg)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          G_UNLOCK (errors);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          errno = saved_errno;
 | 
				
			||||||
 | 
					          return msg;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (!g_get_console_charset (NULL))
 | 
					      if (!g_get_console_charset (NULL))
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
          msg = g_locale_to_utf8 (msg, -1, NULL, NULL, &error);
 | 
					          msg = g_locale_to_utf8 (msg, -1, NULL, NULL, &error);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user