# HG changeset patch # User Jonathan G Rennison # Date 2018-06-06 07:22:58 # Node ID 444c689660a18d196c50a5bcbc9b3798de92c374 # Parent 8c390ff2a96b70f8ffba9ec98f8f047d96ca1807 Codechange: Avoid call to memcpy using null pointer in TooltipsWindow constructor Strictly speaking, calling memcpy with src as a nullptr is undefined behaviour and the optimiser is entitled to delete any null ptr checks which occur afterwards. This removes the warning emitted by UndefinedBehaviorSantizer. diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -656,7 +656,7 @@ struct TooltipsWindow : public Window this->string_id = str; assert_compile(sizeof(this->params[0]) == sizeof(params[0])); assert(paramcount <= lengthof(this->params)); - memcpy(this->params, params, sizeof(this->params[0]) * paramcount); + if (paramcount > 0) memcpy(this->params, params, sizeof(this->params[0]) * paramcount); this->paramcount = paramcount; this->close_cond = close_tooltip;