Skip to content

Commit

Permalink
Fix Crash When wb_supervisor_field_get_name is Called With NULL (#6647
Browse files Browse the repository at this point in the history
)

* fix crash when wb_supervisor_field_get_name is called with NULL

* update changelog

* run clang-format

* use past-tense in changelog

* add period to changelog

Co-authored-by: Olivier Michel <Olivier.Michel@cyberbotics.com>

---------

Co-authored-by: Olivier Michel <Olivier.Michel@cyberbotics.com>
  • Loading branch information
CoolSpy3 and omichel authored Sep 1, 2024
1 parent 2a0c4ea commit eed811b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
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` was called with NULL ([#6647](https://github.com/cyberbotics/webots/pull/6647)).
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

0 comments on commit eed811b

Please sign in to comment.