Segmentation fault when using va_list
John Palmieri
johnp at redhat.com
Tue Dec 23 11:16:45 PST 2008
When using dbus_message_append_* api all arguments must be pointers:
You have this code:
dbus_send_signal("/IO/Processor","Recorder.Set", "dviRecordingPolicy",
DBUS_TYPE_UINT32,
32,
DBUS_TYPE_UINT32
42);
You should have this code:
int first_arg = 32;
int second_arg = 42;
dbus_send_signal("/IO/Processor","Recorder.Set", "dviRecordingPolicy",
DBUS_TYPE_UINT32,
&first_arg,
DBUS_TYPE_UINT32
&second_arg);
You need to be careful though because this code will also crash due to the way C handles asking for the address of an array (it returns the address of the first element - in essences the same address as the array):
char str_arg[] = "hello";
dbus_send_signal("/IO/Processor","Recorder.Set", "dviRecordingPolicy",
DBUS_TYPE_STR,
&str_arg);
You would want to do one of two things here:
char *str_arg = "hello"
or
char str_arg[] = "hello";
char *str_argp = str_arg;
Strange, and the cause of many frustrating errors, but that is the way C has defined the difference between arrays and pointer.
Check out the dbus_message_append_args documentation at http://dbus.freedesktop.org/doc/dbus/api/html/group__DBusMessage.html#gdf644b7816754d01040cce6dc232469d
It goes over the different cases. There is also a link there to the code which uses append_valist in the background which is basically how you are using the API.
--
John (J5) Palmieri
----- "Priya Raghavendra" <Priya_Raghavendra at mindtree.com> wrote:
> Hi,
>
>
>
> I am a newbie to DBUS. I am trying to create a signal which takes
> va_list as its arguments.
>
>
>
> But the program crashes with “Segmentation Fault” when I execute this
> code.
>
>
>
> The program crashes on this line of code
>
> dbus_message_append_args_valist(message_ptr, first_arg_type, ap)
>
>
>
> Find attached the complete listing of the test code.
>
>
>
> Thanks,
>
> Priya
>
>
>
>
>
> http://www.mindtree.com/email/disclaimer.html
>
> _______________________________________________
> dbus mailing list
> dbus at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dbus
--
--
John (J5) Palmieri
Software Engineer
Red Hat, Inc.
More information about the dbus
mailing list