mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-09-28 01:57:14 +02:00
Handle NULL strings like g_strdup. s/g_strconcat_a/g_strconcat3_a/ to
* glib.h: (g_strdup_a, g_strndup_a): Handle NULL strings like g_strdup. s/g_strconcat_a/g_strconcat3_a/ to reflect fixed number of args * testglib.c: Added g_strdup, g_strconcat checks. Added str==NULL checks for alloca string macros. s/g_strconcat_a/g_strconcat3_a/
This commit is contained in:
11
ChangeLog
11
ChangeLog
@@ -1,3 +1,14 @@
|
|||||||
|
Fri Jan 1 21:58:40 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
|
||||||
|
* glib.h:
|
||||||
|
(g_strdup_a, g_strndup_a): Handle NULL strings like g_strdup.
|
||||||
|
s/g_strconcat_a/g_strconcat3_a/ to reflect fixed number of args
|
||||||
|
|
||||||
|
* testglib.c:
|
||||||
|
Added g_strdup, g_strconcat checks.
|
||||||
|
Added str==NULL checks for alloca string macros.
|
||||||
|
s/g_strconcat_a/g_strconcat3_a/
|
||||||
|
|
||||||
Fri Jan 1 18:30:41 PST 1999 Manish Singh <yosh@gimp.org>
|
Fri Jan 1 18:30:41 PST 1999 Manish Singh <yosh@gimp.org>
|
||||||
|
|
||||||
* testglib.c: made the alloca tests follow the testglib style
|
* testglib.c: made the alloca tests follow the testglib style
|
||||||
|
@@ -1,3 +1,14 @@
|
|||||||
|
Fri Jan 1 21:58:40 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
|
||||||
|
* glib.h:
|
||||||
|
(g_strdup_a, g_strndup_a): Handle NULL strings like g_strdup.
|
||||||
|
s/g_strconcat_a/g_strconcat3_a/ to reflect fixed number of args
|
||||||
|
|
||||||
|
* testglib.c:
|
||||||
|
Added g_strdup, g_strconcat checks.
|
||||||
|
Added str==NULL checks for alloca string macros.
|
||||||
|
s/g_strconcat_a/g_strconcat3_a/
|
||||||
|
|
||||||
Fri Jan 1 18:30:41 PST 1999 Manish Singh <yosh@gimp.org>
|
Fri Jan 1 18:30:41 PST 1999 Manish Singh <yosh@gimp.org>
|
||||||
|
|
||||||
* testglib.c: made the alloca tests follow the testglib style
|
* testglib.c: made the alloca tests follow the testglib style
|
||||||
|
@@ -1,3 +1,14 @@
|
|||||||
|
Fri Jan 1 21:58:40 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
|
||||||
|
* glib.h:
|
||||||
|
(g_strdup_a, g_strndup_a): Handle NULL strings like g_strdup.
|
||||||
|
s/g_strconcat_a/g_strconcat3_a/ to reflect fixed number of args
|
||||||
|
|
||||||
|
* testglib.c:
|
||||||
|
Added g_strdup, g_strconcat checks.
|
||||||
|
Added str==NULL checks for alloca string macros.
|
||||||
|
s/g_strconcat_a/g_strconcat3_a/
|
||||||
|
|
||||||
Fri Jan 1 18:30:41 PST 1999 Manish Singh <yosh@gimp.org>
|
Fri Jan 1 18:30:41 PST 1999 Manish Singh <yosh@gimp.org>
|
||||||
|
|
||||||
* testglib.c: made the alloca tests follow the testglib style
|
* testglib.c: made the alloca tests follow the testglib style
|
||||||
|
@@ -1,3 +1,14 @@
|
|||||||
|
Fri Jan 1 21:58:40 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
|
||||||
|
* glib.h:
|
||||||
|
(g_strdup_a, g_strndup_a): Handle NULL strings like g_strdup.
|
||||||
|
s/g_strconcat_a/g_strconcat3_a/ to reflect fixed number of args
|
||||||
|
|
||||||
|
* testglib.c:
|
||||||
|
Added g_strdup, g_strconcat checks.
|
||||||
|
Added str==NULL checks for alloca string macros.
|
||||||
|
s/g_strconcat_a/g_strconcat3_a/
|
||||||
|
|
||||||
Fri Jan 1 18:30:41 PST 1999 Manish Singh <yosh@gimp.org>
|
Fri Jan 1 18:30:41 PST 1999 Manish Singh <yosh@gimp.org>
|
||||||
|
|
||||||
* testglib.c: made the alloca tests follow the testglib style
|
* testglib.c: made the alloca tests follow the testglib style
|
||||||
|
@@ -1,3 +1,14 @@
|
|||||||
|
Fri Jan 1 21:58:40 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
|
||||||
|
* glib.h:
|
||||||
|
(g_strdup_a, g_strndup_a): Handle NULL strings like g_strdup.
|
||||||
|
s/g_strconcat_a/g_strconcat3_a/ to reflect fixed number of args
|
||||||
|
|
||||||
|
* testglib.c:
|
||||||
|
Added g_strdup, g_strconcat checks.
|
||||||
|
Added str==NULL checks for alloca string macros.
|
||||||
|
s/g_strconcat_a/g_strconcat3_a/
|
||||||
|
|
||||||
Fri Jan 1 18:30:41 PST 1999 Manish Singh <yosh@gimp.org>
|
Fri Jan 1 18:30:41 PST 1999 Manish Singh <yosh@gimp.org>
|
||||||
|
|
||||||
* testglib.c: made the alloca tests follow the testglib style
|
* testglib.c: made the alloca tests follow the testglib style
|
||||||
|
@@ -1,3 +1,14 @@
|
|||||||
|
Fri Jan 1 21:58:40 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
|
||||||
|
* glib.h:
|
||||||
|
(g_strdup_a, g_strndup_a): Handle NULL strings like g_strdup.
|
||||||
|
s/g_strconcat_a/g_strconcat3_a/ to reflect fixed number of args
|
||||||
|
|
||||||
|
* testglib.c:
|
||||||
|
Added g_strdup, g_strconcat checks.
|
||||||
|
Added str==NULL checks for alloca string macros.
|
||||||
|
s/g_strconcat_a/g_strconcat3_a/
|
||||||
|
|
||||||
Fri Jan 1 18:30:41 PST 1999 Manish Singh <yosh@gimp.org>
|
Fri Jan 1 18:30:41 PST 1999 Manish Singh <yosh@gimp.org>
|
||||||
|
|
||||||
* testglib.c: made the alloca tests follow the testglib style
|
* testglib.c: made the alloca tests follow the testglib style
|
||||||
|
@@ -1,3 +1,14 @@
|
|||||||
|
Fri Jan 1 21:58:40 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
|
||||||
|
* glib.h:
|
||||||
|
(g_strdup_a, g_strndup_a): Handle NULL strings like g_strdup.
|
||||||
|
s/g_strconcat_a/g_strconcat3_a/ to reflect fixed number of args
|
||||||
|
|
||||||
|
* testglib.c:
|
||||||
|
Added g_strdup, g_strconcat checks.
|
||||||
|
Added str==NULL checks for alloca string macros.
|
||||||
|
s/g_strconcat_a/g_strconcat3_a/
|
||||||
|
|
||||||
Fri Jan 1 18:30:41 PST 1999 Manish Singh <yosh@gimp.org>
|
Fri Jan 1 18:30:41 PST 1999 Manish Singh <yosh@gimp.org>
|
||||||
|
|
||||||
* testglib.c: made the alloca tests follow the testglib style
|
* testglib.c: made the alloca tests follow the testglib style
|
||||||
|
@@ -1,3 +1,14 @@
|
|||||||
|
Fri Jan 1 21:58:40 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
|
||||||
|
* glib.h:
|
||||||
|
(g_strdup_a, g_strndup_a): Handle NULL strings like g_strdup.
|
||||||
|
s/g_strconcat_a/g_strconcat3_a/ to reflect fixed number of args
|
||||||
|
|
||||||
|
* testglib.c:
|
||||||
|
Added g_strdup, g_strconcat checks.
|
||||||
|
Added str==NULL checks for alloca string macros.
|
||||||
|
s/g_strconcat_a/g_strconcat3_a/
|
||||||
|
|
||||||
Fri Jan 1 18:30:41 PST 1999 Manish Singh <yosh@gimp.org>
|
Fri Jan 1 18:30:41 PST 1999 Manish Singh <yosh@gimp.org>
|
||||||
|
|
||||||
* testglib.c: made the alloca tests follow the testglib style
|
* testglib.c: made the alloca tests follow the testglib style
|
||||||
|
36
glib.h
36
glib.h
@@ -1461,26 +1461,32 @@ gpointer g_memdup (gconstpointer mem,
|
|||||||
#if G_HAVE_ALLOCA
|
#if G_HAVE_ALLOCA
|
||||||
|
|
||||||
# define g_strdup_a(newstr,str) G_STMT_START { \
|
# define g_strdup_a(newstr,str) G_STMT_START { \
|
||||||
const char *__old = (str); \
|
if ((str) == NULL) (newstr) = NULL; \
|
||||||
char *__new; \
|
else { \
|
||||||
size_t __len = strlen (__old) + 1; \
|
const char *__old = (str); \
|
||||||
__new = alloca (__len); \
|
char *__new; \
|
||||||
memcpy (__new, __old, __len); \
|
size_t __len = strlen (__old) + 1; \
|
||||||
(newstr) = __new; \
|
__new = alloca (__len); \
|
||||||
|
memcpy (__new, __old, __len); \
|
||||||
|
(newstr) = __new; \
|
||||||
|
} \
|
||||||
} G_STMT_END
|
} G_STMT_END
|
||||||
|
|
||||||
# define g_strndup_a(newstr,str,n) G_STMT_START { \
|
# define g_strndup_a(newstr,str,n) G_STMT_START { \
|
||||||
const char *__old = (str); \
|
if ((str) == NULL) (newstr) = NULL; \
|
||||||
char *__new; \
|
else { \
|
||||||
size_t __len = strlen (__old); \
|
const char *__old = (str); \
|
||||||
if (__len > (n)) __len = (n); \
|
char *__new; \
|
||||||
__new = alloca (__len + 1); \
|
size_t __len = strlen (__old); \
|
||||||
memcpy (__new, __old, __len); \
|
if (__len > (n)) __len = (n); \
|
||||||
__new[__len] = 0; \
|
__new = alloca (__len + 1); \
|
||||||
(newstr) = __new; \
|
memcpy (__new, __old, __len); \
|
||||||
|
__new[__len] = 0; \
|
||||||
|
(newstr) = __new; \
|
||||||
|
} \
|
||||||
} G_STMT_END
|
} G_STMT_END
|
||||||
|
|
||||||
# define g_strconcat_a(newstr,str1,str2,str3) G_STMT_START { \
|
# define g_strconcat3_a(newstr,str1,str2,str3) G_STMT_START { \
|
||||||
size_t __len1 = ((str1) == (gchar*)NULL) ? 0 : strlen((str1)); \
|
size_t __len1 = ((str1) == (gchar*)NULL) ? 0 : strlen((str1)); \
|
||||||
size_t __len2 = ((str2) == (gchar*)NULL) ? 0 : strlen((str2)); \
|
size_t __len2 = ((str2) == (gchar*)NULL) ? 0 : strlen((str2)); \
|
||||||
size_t __len3 = ((str3) == (gchar*)NULL) ? 0 : strlen((str3)); \
|
size_t __len3 = ((str3) == (gchar*)NULL) ? 0 : strlen((str3)); \
|
||||||
|
36
glib/glib.h
36
glib/glib.h
@@ -1461,26 +1461,32 @@ gpointer g_memdup (gconstpointer mem,
|
|||||||
#if G_HAVE_ALLOCA
|
#if G_HAVE_ALLOCA
|
||||||
|
|
||||||
# define g_strdup_a(newstr,str) G_STMT_START { \
|
# define g_strdup_a(newstr,str) G_STMT_START { \
|
||||||
const char *__old = (str); \
|
if ((str) == NULL) (newstr) = NULL; \
|
||||||
char *__new; \
|
else { \
|
||||||
size_t __len = strlen (__old) + 1; \
|
const char *__old = (str); \
|
||||||
__new = alloca (__len); \
|
char *__new; \
|
||||||
memcpy (__new, __old, __len); \
|
size_t __len = strlen (__old) + 1; \
|
||||||
(newstr) = __new; \
|
__new = alloca (__len); \
|
||||||
|
memcpy (__new, __old, __len); \
|
||||||
|
(newstr) = __new; \
|
||||||
|
} \
|
||||||
} G_STMT_END
|
} G_STMT_END
|
||||||
|
|
||||||
# define g_strndup_a(newstr,str,n) G_STMT_START { \
|
# define g_strndup_a(newstr,str,n) G_STMT_START { \
|
||||||
const char *__old = (str); \
|
if ((str) == NULL) (newstr) = NULL; \
|
||||||
char *__new; \
|
else { \
|
||||||
size_t __len = strlen (__old); \
|
const char *__old = (str); \
|
||||||
if (__len > (n)) __len = (n); \
|
char *__new; \
|
||||||
__new = alloca (__len + 1); \
|
size_t __len = strlen (__old); \
|
||||||
memcpy (__new, __old, __len); \
|
if (__len > (n)) __len = (n); \
|
||||||
__new[__len] = 0; \
|
__new = alloca (__len + 1); \
|
||||||
(newstr) = __new; \
|
memcpy (__new, __old, __len); \
|
||||||
|
__new[__len] = 0; \
|
||||||
|
(newstr) = __new; \
|
||||||
|
} \
|
||||||
} G_STMT_END
|
} G_STMT_END
|
||||||
|
|
||||||
# define g_strconcat_a(newstr,str1,str2,str3) G_STMT_START { \
|
# define g_strconcat3_a(newstr,str1,str2,str3) G_STMT_START { \
|
||||||
size_t __len1 = ((str1) == (gchar*)NULL) ? 0 : strlen((str1)); \
|
size_t __len1 = ((str1) == (gchar*)NULL) ? 0 : strlen((str1)); \
|
||||||
size_t __len2 = ((str2) == (gchar*)NULL) ? 0 : strlen((str2)); \
|
size_t __len2 = ((str2) == (gchar*)NULL) ? 0 : strlen((str2)); \
|
||||||
size_t __len3 = ((str3) == (gchar*)NULL) ? 0 : strlen((str3)); \
|
size_t __len3 = ((str3) == (gchar*)NULL) ? 0 : strlen((str3)); \
|
||||||
|
29
testglib.c
29
testglib.c
@@ -748,6 +748,29 @@ main (int argc,
|
|||||||
|
|
||||||
g_print ("ok\n");
|
g_print ("ok\n");
|
||||||
|
|
||||||
|
g_print ("checking g_strdup...");
|
||||||
|
g_assert(g_strdup(NULL) == NULL);
|
||||||
|
string = g_strdup(GLIB_TEST_STRING);
|
||||||
|
g_assert(string != NULL);
|
||||||
|
g_assert(strcmp(string, GLIB_TEST_STRING) == 0);
|
||||||
|
g_free(string);
|
||||||
|
|
||||||
|
g_print ("ok\n");
|
||||||
|
|
||||||
|
g_print ("checking g_strconcat...");
|
||||||
|
string = g_strconcat(GLIB_TEST_STRING, NULL);
|
||||||
|
g_assert(string != NULL);
|
||||||
|
g_assert(strcmp(string, GLIB_TEST_STRING) == 0);
|
||||||
|
g_free(string);
|
||||||
|
string = g_strconcat(GLIB_TEST_STRING, GLIB_TEST_STRING,
|
||||||
|
GLIB_TEST_STRING, NULL);
|
||||||
|
g_assert(string != NULL);
|
||||||
|
g_assert(strcmp(string, GLIB_TEST_STRING GLIB_TEST_STRING
|
||||||
|
GLIB_TEST_STRING) == 0);
|
||||||
|
g_free(string);
|
||||||
|
|
||||||
|
g_print ("ok\n");
|
||||||
|
|
||||||
/* g_debug (argv[0]); */
|
/* g_debug (argv[0]); */
|
||||||
|
|
||||||
/* Relation tests */
|
/* Relation tests */
|
||||||
@@ -879,13 +902,17 @@ main (int argc,
|
|||||||
g_strdup_a(string, GLIB_TEST_STRING);
|
g_strdup_a(string, GLIB_TEST_STRING);
|
||||||
g_assert(string != NULL);
|
g_assert(string != NULL);
|
||||||
g_assert(strcmp(string, GLIB_TEST_STRING) == 0);
|
g_assert(strcmp(string, GLIB_TEST_STRING) == 0);
|
||||||
|
g_strdup_a(string, NULL);
|
||||||
|
g_assert(string == NULL);
|
||||||
|
|
||||||
g_strndup_a(string, GLIB_TEST_STRING, 5);
|
g_strndup_a(string, GLIB_TEST_STRING, 5);
|
||||||
g_assert(string != NULL);
|
g_assert(string != NULL);
|
||||||
g_assert(strlen(string) == 5);
|
g_assert(strlen(string) == 5);
|
||||||
g_assert(strcmp(string, GLIB_TEST_STRING_5) == 0);
|
g_assert(strcmp(string, GLIB_TEST_STRING_5) == 0);
|
||||||
|
g_strndup_a(string, NULL, 20);
|
||||||
|
g_assert(string == NULL);
|
||||||
|
|
||||||
g_strconcat_a(string, GLIB_TEST_STRING, GLIB_TEST_STRING, GLIB_TEST_STRING);
|
g_strconcat3_a(string, GLIB_TEST_STRING, GLIB_TEST_STRING, GLIB_TEST_STRING);
|
||||||
g_assert(string != NULL);
|
g_assert(string != NULL);
|
||||||
g_assert(strcmp(string, GLIB_TEST_STRING GLIB_TEST_STRING
|
g_assert(strcmp(string, GLIB_TEST_STRING GLIB_TEST_STRING
|
||||||
GLIB_TEST_STRING) == 0);
|
GLIB_TEST_STRING) == 0);
|
||||||
|
@@ -748,6 +748,29 @@ main (int argc,
|
|||||||
|
|
||||||
g_print ("ok\n");
|
g_print ("ok\n");
|
||||||
|
|
||||||
|
g_print ("checking g_strdup...");
|
||||||
|
g_assert(g_strdup(NULL) == NULL);
|
||||||
|
string = g_strdup(GLIB_TEST_STRING);
|
||||||
|
g_assert(string != NULL);
|
||||||
|
g_assert(strcmp(string, GLIB_TEST_STRING) == 0);
|
||||||
|
g_free(string);
|
||||||
|
|
||||||
|
g_print ("ok\n");
|
||||||
|
|
||||||
|
g_print ("checking g_strconcat...");
|
||||||
|
string = g_strconcat(GLIB_TEST_STRING, NULL);
|
||||||
|
g_assert(string != NULL);
|
||||||
|
g_assert(strcmp(string, GLIB_TEST_STRING) == 0);
|
||||||
|
g_free(string);
|
||||||
|
string = g_strconcat(GLIB_TEST_STRING, GLIB_TEST_STRING,
|
||||||
|
GLIB_TEST_STRING, NULL);
|
||||||
|
g_assert(string != NULL);
|
||||||
|
g_assert(strcmp(string, GLIB_TEST_STRING GLIB_TEST_STRING
|
||||||
|
GLIB_TEST_STRING) == 0);
|
||||||
|
g_free(string);
|
||||||
|
|
||||||
|
g_print ("ok\n");
|
||||||
|
|
||||||
/* g_debug (argv[0]); */
|
/* g_debug (argv[0]); */
|
||||||
|
|
||||||
/* Relation tests */
|
/* Relation tests */
|
||||||
@@ -879,13 +902,17 @@ main (int argc,
|
|||||||
g_strdup_a(string, GLIB_TEST_STRING);
|
g_strdup_a(string, GLIB_TEST_STRING);
|
||||||
g_assert(string != NULL);
|
g_assert(string != NULL);
|
||||||
g_assert(strcmp(string, GLIB_TEST_STRING) == 0);
|
g_assert(strcmp(string, GLIB_TEST_STRING) == 0);
|
||||||
|
g_strdup_a(string, NULL);
|
||||||
|
g_assert(string == NULL);
|
||||||
|
|
||||||
g_strndup_a(string, GLIB_TEST_STRING, 5);
|
g_strndup_a(string, GLIB_TEST_STRING, 5);
|
||||||
g_assert(string != NULL);
|
g_assert(string != NULL);
|
||||||
g_assert(strlen(string) == 5);
|
g_assert(strlen(string) == 5);
|
||||||
g_assert(strcmp(string, GLIB_TEST_STRING_5) == 0);
|
g_assert(strcmp(string, GLIB_TEST_STRING_5) == 0);
|
||||||
|
g_strndup_a(string, NULL, 20);
|
||||||
|
g_assert(string == NULL);
|
||||||
|
|
||||||
g_strconcat_a(string, GLIB_TEST_STRING, GLIB_TEST_STRING, GLIB_TEST_STRING);
|
g_strconcat3_a(string, GLIB_TEST_STRING, GLIB_TEST_STRING, GLIB_TEST_STRING);
|
||||||
g_assert(string != NULL);
|
g_assert(string != NULL);
|
||||||
g_assert(strcmp(string, GLIB_TEST_STRING GLIB_TEST_STRING
|
g_assert(strcmp(string, GLIB_TEST_STRING GLIB_TEST_STRING
|
||||||
GLIB_TEST_STRING) == 0);
|
GLIB_TEST_STRING) == 0);
|
||||||
|
Reference in New Issue
Block a user