diff options
| author | Thomas Herzog <thomas.herzog@mail.com> | 2018-01-17 08:43:14 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-01-17 08:43:14 +0100 |
| commit | dc2896dc89ebd7722b3afd1f936f3dd579f98a80 (patch) | |
| tree | 84eec8a546b1cfd9aba1395496bda0c4e65c4e8e | |
| parent | b9b06b5fbcd58a63c01eef6784f6082f528a1e3f (diff) | |
| parent | e7202cef8b7d39058bb28defa226268b3d09f416 (diff) | |
| download | redot-cpp-dc2896dc89ebd7722b3afd1f936f3dd579f98a80.tar.gz | |
Merge pull request #70 from Zylann/fix_register_signal
Fix potential malloc(0)
| -rw-r--r-- | include/core/Godot.hpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/include/core/Godot.hpp b/include/core/Godot.hpp index cb49e63..6d7f0de 100644 --- a/include/core/Godot.hpp +++ b/include/core/Godot.hpp @@ -448,9 +448,11 @@ void register_signal(String name, Dictionary args = Dictionary()) signal.num_args = args.size(); signal.num_default_args = 0; - signal.args = (godot_signal_argument*) godot::api->godot_alloc(sizeof(godot_signal_argument) * signal.num_args); - memset((void *) signal.args, 0, sizeof(godot_signal_argument) * signal.num_args); - + // Need to check because malloc(0) is platform-dependent. Zero arguments will leave args to NULL. + if(signal.num_args != 0) { + signal.args = (godot_signal_argument*) godot::api->godot_alloc(sizeof(godot_signal_argument) * signal.num_args); + memset((void *) signal.args, 0, sizeof(godot_signal_argument) * signal.num_args); + } for (int i = 0; i < signal.num_args; i++) { // Array entry = args[i]; @@ -471,7 +473,9 @@ void register_signal(String name, Dictionary args = Dictionary()) godot::api->godot_string_destroy(&signal.args[i].name); } - godot::api->godot_free(signal.args); + if(signal.args) { + godot::api->godot_free(signal.args); + } } |
