mirror of
				https://gitlab.gnome.org/GNOME/glib.git
				synced 2025-11-04 10:08:56 +01:00 
			
		
		
		
	Merge branch 'gstrfuncs_param_check' into 'main'
gstrfuncs: Check parameter validity See merge request GNOME/glib!4740
This commit is contained in:
		@@ -416,6 +416,8 @@ g_strndup (const gchar *str,
 | 
			
		||||
 | 
			
		||||
  if (str)
 | 
			
		||||
    {
 | 
			
		||||
      g_return_val_if_fail (n < G_MAXSIZE, NULL);
 | 
			
		||||
 | 
			
		||||
      new_str = g_new (gchar, n + 1);
 | 
			
		||||
      strncpy (new_str, str, n);
 | 
			
		||||
      new_str[n] = '\0';
 | 
			
		||||
@@ -441,6 +443,8 @@ g_strnfill (gsize length,
 | 
			
		||||
{
 | 
			
		||||
  gchar *str;
 | 
			
		||||
 | 
			
		||||
  g_return_val_if_fail (length < G_MAXSIZE, NULL);
 | 
			
		||||
 | 
			
		||||
  str = g_new (gchar, length + 1);
 | 
			
		||||
  memset (str, (guchar)fill_char, length);
 | 
			
		||||
  str[length] = '\0';
 | 
			
		||||
 
 | 
			
		||||
@@ -571,6 +571,16 @@ test_strndup (void)
 | 
			
		||||
  g_assert_nonnull (str);
 | 
			
		||||
  g_assert_cmpstr (str, ==, "aa");
 | 
			
		||||
  g_free (str);
 | 
			
		||||
 | 
			
		||||
  if (g_test_undefined ())
 | 
			
		||||
    {
 | 
			
		||||
      /* Testing degenerated cases */
 | 
			
		||||
      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
 | 
			
		||||
                             "*assertion* < G_MAXSIZE*");
 | 
			
		||||
      g_assert_null (
 | 
			
		||||
          g_strndup ("aaaa", G_MAXSIZE));
 | 
			
		||||
      g_test_assert_expected_messages ();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Testing g_strdup_printf() function with various positive and negative cases */
 | 
			
		||||
@@ -616,6 +626,16 @@ test_strnfill (void)
 | 
			
		||||
  g_assert_nonnull (str);
 | 
			
		||||
  g_assert_cmpstr (str, ==, "aaaaa");
 | 
			
		||||
  g_free (str);
 | 
			
		||||
 | 
			
		||||
  if (g_test_undefined ())
 | 
			
		||||
    {
 | 
			
		||||
      /* Testing degenerated cases */
 | 
			
		||||
      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
 | 
			
		||||
                             "*assertion* < G_MAXSIZE*");
 | 
			
		||||
      g_assert_null (
 | 
			
		||||
          g_strnfill (G_MAXSIZE, 'a'));
 | 
			
		||||
      g_test_assert_expected_messages ();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Testing g_strconcat() function with various positive and negative cases */
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user