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

Fix Crash When wb_supervisor_field_get_name is Called With NULL #6647

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/reference/changelog-r2024.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ Released on December **th, 2023.
- Fixed connection errors when using long robot names in some environments ([#6635](https://github.com/cyberbotics/webots/pull/6635)).
- Fixed crash on macos when closing Webots under some circumstances ([#6635](https://github.com/cyberbotics/webots/pull/6635)).
- Fixed error on macos when when putting displays and cameras in separate windows ([#6635](https://github.com/cyberbotics/webots/pull/6635)).
- Fixed crash when `wb_supervisor_field_get_name` is called with NULL ([#6647](https://github.com/cyberbotics/webots/pull/6647))
omichel marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions src/controller/c/supervisor.c
Original file line number Diff line number Diff line change
Expand Up @@ -2831,6 +2831,9 @@ const double *wb_supervisor_virtual_reality_headset_get_orientation() {
}

const char *wb_supervisor_field_get_name(WbFieldRef field) {
if (!check_field(field, __FUNCTION__, WB_NO_FIELD, false, NULL, false, false))
return "";

return field->name;
}

Expand Down
7 changes: 7 additions & 0 deletions tests/api/controllers/supervisor_field/supervisor_field.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ int main(int argc, char **argv) {
int i;
double d;

ts_assert_string_equal(wb_supervisor_field_get_name(NULL), "",
"wb_supervisor_field_get_name(NULL) should return the empty string");
ts_assert_int_equal(wb_supervisor_field_get_type(NULL), 0, "wb_supervisor_field_get_type(NULL) should return 0");
ts_assert_string_equal(wb_supervisor_field_get_type_name(NULL), "",
"wb_supervisor_field_get_type_name(NULL) should return the empty string");
ts_assert_int_equal(wb_supervisor_field_get_count(NULL), -1, "wb_supervisor_field_get_count(NULL) should return -1");

root = wb_supervisor_node_get_root();
ts_assert_pointer_not_null(root, "Root node is not found");

Expand Down
Loading