GNOME Bugzilla – Bug 169611
g_try_new and g_try_new0
Last modified: 2011-02-18 16:14:11 UTC
glib imho needs g_try_new and g_try_new0. We use g_new0 for memory allocation. This is a problem, when the number of elements is determined by user input. When the user inputs a large number, the programm aborts and he loses his work. The addition of g_try_new and g_try_new0 would solve this problem.
for completness here is what we use now localy -- gmem.h -- #define g_try_new(struct_type, n_structs) \ g_try_malloc(sizeof(struct_type)*n_structs) #define g_try_new0(struct_type, n_structs) \ g_try_malloc0(sizeof(struct_type)*n_structs) -- gmem.c -- gpointer g_try_malloc0(gulong n_bytes) { gpointer mem; if((mem=g_try_malloc(n_bytes))) { memset(mem,0,n_bytes); } return(mem); }
2005-03-21 Matthias Clasen <mclasen@redhat.com> * glib/gmem.h: Add g_try_new, g_try_new0, g_try_renew and g_try_malloc0. (#169611, Stefan Kost) * glib/gmem.c: Implement g_try_malloc0.