Skip to content

Commit eed811b

Browse files
CoolSpy3omichel
andauthored
Fix Crash When wb_supervisor_field_get_name is Called With NULL (#6647)
* 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 <[email protected]> --------- Co-authored-by: Olivier Michel <[email protected]>
1 parent 2a0c4ea commit eed811b

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

docs/reference/changelog-r2024.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ Released on December **th, 2023.
2828
- Fixed connection errors when using long robot names in some environments ([#6635](https://github.com/cyberbotics/webots/pull/6635)).
2929
- Fixed crash on macos when closing Webots under some circumstances ([#6635](https://github.com/cyberbotics/webots/pull/6635)).
3030
- Fixed error on macos when when putting displays and cameras in separate windows ([#6635](https://github.com/cyberbotics/webots/pull/6635)).
31+
- Fixed crash when `wb_supervisor_field_get_name` was called with NULL ([#6647](https://github.com/cyberbotics/webots/pull/6647)).

src/controller/c/supervisor.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2831,6 +2831,9 @@ const double *wb_supervisor_virtual_reality_headset_get_orientation() {
28312831
}
28322832

28332833
const char *wb_supervisor_field_get_name(WbFieldRef field) {
2834+
if (!check_field(field, __FUNCTION__, WB_NO_FIELD, false, NULL, false, false))
2835+
return "";
2836+
28342837
return field->name;
28352838
}
28362839

tests/api/controllers/supervisor_field/supervisor_field.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ int main(int argc, char **argv) {
2525
int i;
2626
double d;
2727

28+
ts_assert_string_equal(wb_supervisor_field_get_name(NULL), "",
29+
"wb_supervisor_field_get_name(NULL) should return the empty string");
30+
ts_assert_int_equal(wb_supervisor_field_get_type(NULL), 0, "wb_supervisor_field_get_type(NULL) should return 0");
31+
ts_assert_string_equal(wb_supervisor_field_get_type_name(NULL), "",
32+
"wb_supervisor_field_get_type_name(NULL) should return the empty string");
33+
ts_assert_int_equal(wb_supervisor_field_get_count(NULL), -1, "wb_supervisor_field_get_count(NULL) should return -1");
34+
2835
root = wb_supervisor_node_get_root();
2936
ts_assert_pointer_not_null(root, "Root node is not found");
3037

0 commit comments

Comments
 (0)