After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 169611 - g_try_new and g_try_new0
g_try_new and g_try_new0
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
2.6.x
Other All
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2005-03-08 15:24 UTC by Stefan Sauer (gstreamer, gtkdoc dev)
Modified: 2011-02-18 16:14 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Stefan Sauer (gstreamer, gtkdoc dev) 2005-03-08 15:24:41 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.
Comment 1 Stefan Sauer (gstreamer, gtkdoc dev) 2005-03-20 15:20:42 UTC
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);
}
Comment 2 Matthias Clasen 2005-03-22 04:10:01 UTC
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.