Commit: 9b86741ae75ff6c697088b01773f94899f49ec10 Author: Germano Cavalcante Date: Wed Feb 1 15:29:21 2023 -0300 Branches: master https://developer.blender.org/rB9b86741ae75ff6c697088b01773f94899f49ec10
FIx possible return of string without null character `WM_modalkeymap_items_to_string` is expected to always return a string. But in the special case of zero length, the returned string was not terminated with `'\0'`. This can cause problems with the header of the knife tool for example. It always uses the returned string. (This issue was observed when investigating T103804). =================================================================== M source/blender/windowmanager/intern/wm_keymap.c =================================================================== diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c index 9e322228884..f033a5d9970 100644 --- a/source/blender/windowmanager/intern/wm_keymap.c +++ b/source/blender/windowmanager/intern/wm_keymap.c @@ -1238,25 +1238,26 @@ int WM_modalkeymap_items_to_string(const wmKeyMap *km, char *result, const int result_len) { + BLI_assert(result_len > 0); + + const wmKeyMapItem *kmi; + if (km == NULL || (kmi = WM_modalkeymap_find_propvalue(km, propvalue)) == NULL) { + *result = '\0'; + return 0; + } + int totlen = 0; - bool add_sep = false; + do { + totlen += WM_keymap_item_to_string(kmi, compact, &result[totlen], result_len - totlen); - if (km) { - const wmKeyMapItem *kmi; - - /* Find all shortcuts related to that propvalue! */ - for (kmi = WM_modalkeymap_find_propvalue(km, propvalue); kmi && totlen < (result_len - 2); - kmi = wm_modalkeymap_find_propvalue_iter(km, kmi, propvalue)) { - if (add_sep) { - result[totlen++] = '/'; - result[totlen] = '\0'; - } - else { - add_sep = true; - } - totlen += WM_keymap_item_to_string(kmi, compact, &result[totlen], result_len - totlen); + if ((kmi = wm_modalkeymap_find_propvalue_iter(km, kmi, propvalue)) == NULL || + totlen >= (result_len - 2)) { + break; } - } + + result[totlen++] = '/'; + result[totlen] = '\0'; + } while (true); return totlen; } _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs