On Mon, Sep 07, 2009 at 04:36:53PM +0200, Josselin Mouette wrote:
Le lundi 07 septembre 2009 à 13:40 +0200, Bernhard R. Link a écrit :
For the record: Noone sane would replace g_strdup_printf with snprintf,
but with asprintf.
Case 1:
char *foo;
if (asprintf(&foo, "%s equals %i", somestring, someint) < 0) {
fprintf(stderr, "Failed to allocate memory");
abort();
}
Case 2:
char *foo = g_strdup_printf ("%s equals %i", somestring,
someint);
Pick your choice.
Case 1, please. Either case 2 fails to handle the allocation error, or glib
is doing its own abort. Neither is acceptable.