if you are sending strings over opaque, you need to send strlen+1 for the null terminator

2008/4/28 AnÝbal <hannibalevivo@gmail.com>:
I've written an opaque plugin driver and a small client (player version: 2.1.0rc2).

The shared structure is defined as follows:
struct test_data_t {
   uint16_t id;
   uint8_t buffer[128];
   uint16_t buffer_length;

The client sends a request to Player.
The driver prints correctly the information received from the client. Then, the driver sends the reply but the client fails:
segmentation fault (core dumped)

I've used the gdb with the client program, this is the output:

$ gdb ./client
(gdb) run
Starting program: /home/robotica/player/testing_player/example_driver/client
[Thread debugging using libthread_db enabled]
[New Thread -1223178512 (LWP 13654)]
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1223178512 (LWP 13654)]
0xb7d3434c in memcpy () from /lib/tls/i686/cmov/libc.so.6
(gdb) bt
#0  0xb7d3434c in memcpy () from /lib/tls/i686/cmov/libc.so.6
#1  0xb7fbff0a in PlayerCc::OpaqueProxy::SendReq (this=0xbfefecb0, aRequest=0xbfefecd4) at opaqueproxy.cc:97
#2  0x08048cb8 in main ()

line number 97 of opaqueproxy.cc file is:
memcpy(mDevice->data, aReply->data, aReply->data_count);

And finally the client code:

int main(int argc, char* argv[]) {

   test_data_t test_data; // user-defined shared structure
   player_opaque_data_t opaque_data; // opaque data

   PlayerClient client("localhost");
   OpaqueProxy proxy(&client,0);

   opaque_data.data = (uint8_t*) &test_data;
   opaque_data.data_count = sizeof(test_data);

   for(unsigned int i=0; i<10; i++) {
      test_data.id = i;
      sprintf((char*)test_data.buffer, "good morning!");
      test_data.buffer_length = strlen("good morning!");

      proxy.SendReq(&opaque_data); // <----- here the client fails

I don't know if i'm doing something wrong or not.
Thanks in advance

This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
Playerstage-users mailing list

This email is intended for the addressee only and may contain privileged and/or confidential information