Re: Crash processing g_object_new arguments



David NeÄas wrote: 

On Mon, Nov 09, 2009 at 03:24:04AM -0500, Braden McDaniel wrote: 
OpenvrmlXembedBrowser * const browser = 
OPENVRML_XEMBED_BROWSER( 
g_object_new(OPENVRML_XEMBED_TYPE_BROWSER, 
"control-host-proxy", host_proxy, 
"control-host-name", host_name, 
"dbus-thread-context", dbus_thread_context, 
"expect-initial-stream", expect_initial_stream, 
0)); 

0 is not NULL. 
0 has the size of int while NULL has the size of void*. 
Matters a lot in vararg list. 

This requires clarification.

0 *is* NULL, in pointer contexts.  In fact, some compilers define NULL
using

   #define NULL 0

So using NULL instead of 0, by itself, won't necessarily address the
problem, although it will if the definition happens to be

   #define NULL (void *)0

The problem is that this particular NULL appears in the arguments of a
function that accepts a variable number of arguments.  The compiler
therefore doesn't know that any particular argument is a pointer and
can't perform the proper type conversion.

Arguably, the real problem is the design of g_object_new(), and another
way to avoid it is the use of g_object_newv().

- Ernie



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]