From 402a1081aef6cd276c0636557413ed5942a771ef Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 18 Jan 2006 03:51:39 +0000 Subject: [PATCH] Add a note about casting the results of g_new() and g_new0(). 2006-01-17 Matthias Clasen * glib/tmpl/memory.sgml: Add a note about casting the results of g_new() and g_new0(). --- ChangeLog | 5 +++++ ChangeLog.pre-2-10 | 5 +++++ ChangeLog.pre-2-12 | 5 +++++ docs/reference/ChangeLog | 5 +++++ docs/reference/glib/tmpl/memory.sgml | 10 ++++++++++ glib/gkeyfile.c | 2 +- 6 files changed, 31 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 595bb98..69de733 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2006-01-17 Matthias Clasen + + * glib/gkeyfile.c (g_key_file_get_groups): Correct a g_new0() + call. (#327421, Morten Welinder) + 2006-01-17 Sebastian Wilhelmi * glib/gthreadpool.c: To avoid deadlocks get rid of the settings diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 595bb98..69de733 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,8 @@ +2006-01-17 Matthias Clasen + + * glib/gkeyfile.c (g_key_file_get_groups): Correct a g_new0() + call. (#327421, Morten Welinder) + 2006-01-17 Sebastian Wilhelmi * glib/gthreadpool.c: To avoid deadlocks get rid of the settings diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 595bb98..69de733 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,8 @@ +2006-01-17 Matthias Clasen + + * glib/gkeyfile.c (g_key_file_get_groups): Correct a g_new0() + call. (#327421, Morten Welinder) + 2006-01-17 Sebastian Wilhelmi * glib/gthreadpool.c: To avoid deadlocks get rid of the settings diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index 4a6ca41..51d51a6 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,8 @@ +2006-01-17 Matthias Clasen + + * glib/tmpl/memory.sgml: Add a note about casting the results + of g_new() and g_new0(). + 2006-01-16 Matthias Clasen * === Released 2.9.3 === diff --git a/docs/reference/glib/tmpl/memory.sgml b/docs/reference/glib/tmpl/memory.sgml index 063b7a9..9805322 100644 --- a/docs/reference/glib/tmpl/memory.sgml +++ b/docs/reference/glib/tmpl/memory.sgml @@ -29,6 +29,11 @@ Allocates @n_structs elements of type @struct_type. The returned pointer is cast to a pointer to the given type. If @n_structs is 0 it returns %NULL. + +Since the returned pointer is already casted to the right type, +it is normally unnecessary to cast it explicitly, and doing +so might hide memory allocation errors. + @struct_type: the type of the elements to allocate. @n_structs: the number of elements to allocate. @@ -41,6 +46,11 @@ Allocates @n_structs elements of type @struct_type, initialized to 0's. The returned pointer is cast to a pointer to the given type. If @n_structs is 0 it returns %NULL. + +Since the returned pointer is already casted to the right type, +it is normally unnecessary to cast it explicitly, and doing +so might hide memory allocation errors. + @struct_type: the type of the elements to allocate. @n_structs: the number of elements to allocate. diff --git a/glib/gkeyfile.c b/glib/gkeyfile.c index d77a1ae..7a8a783 100644 --- a/glib/gkeyfile.c +++ b/glib/gkeyfile.c @@ -1107,7 +1107,7 @@ g_key_file_get_groups (GKeyFile *key_file, * list) is always the comment group at the top, * which we skip */ - groups = (gchar **) g_new0 (gchar **, num_groups); + groups = g_new0 (gchar *, num_groups); group_node = g_list_last (key_file->groups); -- 2.7.4