array of string

John (J5) Palmieri johnp at redhat.com
Sun Oct 30 08:23:16 PST 2005


I was offline on my last reply so I didn't see this one.  How could that
be a dbus problem?  What do you mean by it doesn't work?  Does it fail
while sending?  Or do you get buffer overflows?  Your code looks really
complicated (#define P (*((char***)info))[x]) and I am guessing you are
overflowing a buffer somewhere.  The reason it might work for j=60 and
not j=61 is that you are overwriting something important when j=61 and
when j=60 the program just goes on its way without knowing something
went wrong.  Stack trashing is a weird beast.  You should run your stuff
under valgrind and if you are running a gcc that supports it, add -
D_FORTIFY_SOURCE=2 to your CFLAGS.  That will add bounds checking.  Also
using glib will save you a lot of headaches when dealing with pointers
(i.e. g_strdup_printf). Other than that I think you have moved into the
realm of standard C memory management errors and might be better helped
in a C forum where there are people who might be able to spot what you
are doing wrong more readily than here.

On Sun, 2005-10-30 at 08:56 -0600, yohann (yrc) coppel wrote:
> Ok, It doesn't seems to be the problem, I've found something else:
> 
> if I do something like that:
> 
> 	#define P (*((char***)info))[x]
> 	int j = 60;
> 	int jj = j > strlen(argv[i]) ? strlen(argv[i]) : j;
> 	P=(char*) calloc(jj+1,sizeof(char));
> 	if(P)
> 		strncpy(P, argv[i], jj);
> 
> (one more time, it's not a final code, just for debugging ;-) )
> it works with my argv[i]. But, if I replace j = 60 by j = 61, it
> doesn't! (all my testing strings are lager than 60 chars...)
> 
> So, is-it a DBus limitation ? What can-I do ?
> 
> Thanks!
> 
> yrc
> 
> Le samedi 29 octobre 2005 à 21:51 -0500, yohann (yrc) coppel a écrit :
> > After searching all the day long, I've found something strange (for
> > me...)
> > 
> > Somewhere in my code, I have:
> > 
> > strcpy((*((char***)info))[x], argv[i]);
> > 
> > With this line, I have the problem at the *reception* of the message...
> > But, if I replace it (with the apropriate modification in the calloc
> > arguments two lines before) by :
> > 
> > strcpy((*((char***)info))[x], "aaa"  );
> > 
> > I works fine !??!?!
> > One more time:
> > 
> > strcpy((*((char***)info))[x], argv[i]);
> > strcpy((*((char***)info))[x], "aaa"  );
> > 
> > ...!!!...
> > with: char **argv
> > 
> > the void pointer info is more or less a pointer to the array I gona give
> > to the function dbus_message_append_args later....
> > 
> > Is it one another very special thing of C... I don't know.... Or I'm too
> > tired to see my error....
> > 
> > I've said at the *reception*, because if I do a dbus_message_get_args
> > juste before sending the message in the server code (who send the
> > message), i can read in both cases my strings... uh?
> > 
> > I don't know what to do... It's not realy a DBus problem but so now you
> > can forget my previous messages...
> > 
> > Regards,
> > yrc.
> > 
> > P.S. I've tried with memcpy, it's exactly the same result.
> > 
> > _______________________________________________
> > dbus mailing list
> > dbus at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/dbus
> 
> _______________________________________________
> dbus mailing list
> dbus at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dbus
-- 
John (J5) Palmieri <johnp at redhat.com>



More information about the dbus mailing list