-
Notifications
You must be signed in to change notification settings - Fork 119
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
C api bug (strings not null-terminated) #577
Comments
if you want to reproduce my problem, you can refer this:https://github.com/dora-rs/autoware.universe/tree/feature/autoware_dora/tools/read_id_test |
Because You can push a '\0' at this line to see how these been changed. dora/libraries/core/src/config.rs Lines 86 to 90 in 01c4047
|
by the way, please use |
impl From<String> for DataId {
fn from(id: String) -> Self {
let mut id = id;
id.push('\0');
Self(id)
}
} I tried this, but it fails when parsing dataflow.yml. I think pushing 0 directly will cause many problems. |
Or learn from I thing that let user release id-string is error-prone. |
Only C uses null-terminated strings, all other languages (including C++) use length-terminated strings. So I don't think that we should force all other languages to reallocate their The proper way to use strings returned by dora in C is to use length-aware functions (e.g. If you're using the C-API from C++, you can simply do: char *id_ptr;
size_t id_len;
read_dora_input_id(event, &id_ptr, &id_len);
std::string id(id_ptr, id_len); I'm open to add convenience functions for these conversions to the API, but I don't think that we should change the What do you think? |
And there is a interesting phenomenon. we have a node which input_id is So there is a problem with |
By re-reading those message it seems @starlitxiling is not using: std::string id(id_ptr, id_len); Such that it looks like this: char *id_ptr;
size_t id_len;
read_dora_input_id(event, &id_ptr, &id_len);
std::string id(id_ptr, id_len) Could you try to add this to the code? As philipp mentioned, this should fix your problem |
Ok,i will do this. |
This has been solved with:
|
When I use the C API, I find that some unpredictable id appear in read_dora_input_id, and it will be the same string I create after that. If I don't create it after that, it will be a segment of id plus a strange hexadecimal number (like BCAG). I think there is a pointer error phenomenon. I don't know if this is related to #540

The text was updated successfully, but these errors were encountered: