Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault occurs when sequence array element is undefined or partially defined #1994

Open
Orbuild opened this issue May 7, 2024 · 1 comment

Comments

@Orbuild
Copy link

Orbuild commented May 7, 2024

  • When I use the code from the master branch, I ran a simple publish-subscribe program, where the message format is as follows:
module MyTestData
{ 
  struct Msg {
    @key long id;
    sequence<octet> data[10];
  };
};
  • If the sequence array is not defined or only some elements in the array are defined, the segmentation fault will occur in the program. I would like to ask if this is the agreed behavior (all elements in the sequence array need to be defined), or is this a problem? Looking forward to your response!
for (int i = 0; i < 5; i++) {
    msg->data[i]._buffer = dds_alloc(100);
    msg->data[i]._length = 100;
    msg->data[i]._release = true;
}
=== [MyTestPublisher]  Waiting for a reader to be discovered ...
[MyTestPublisher]  Writing : Segmentation fault (core dumped)
@eboasson
Copy link
Contributor

Yes, in general samples that you pass into the API need to be valid. That means:

  • strings must point to a null-terminated string or be a null pointer
  • sequences need _length_maximum and _buffer may not be a null pointer if _length > 0
  • the sequence buffer will not be allocated/resized/freed if _release is false except that if everything is 0 it will take over ownership in read/take and allocate and that it is somewhat forgiving of _maximum < _length
  • all elements of an array need to be initialized
  • the union case identified by the discriminant must be correctly initialized
  • @external pointers may never be a null pointer on write.

Maybe I forgot something, maybe not 😂 I'm sure you understand. That exception noted above about sequences exists so you can memset everything 0 and you'll be good for read and take.

There are few functions that only care about the values of the key fields, for example dds_dispose. Those ignore all other fields, so in your example, you can call dds_dispose with id set correctly and everything else garbage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants