Page MenuHome

BLF: UI_fontstyle_draw Usage
ClosedPublic

Authored by Harley Acheson (harley) on Jan 11 2022, 1:39 AM.

Details

Summary

Add maximum string length argument to UI_fontstyle_draw to reduce usage
of BLF_DRAW_STR_DUMMY_MAX


Function UI_fontstyle_draw takes a pointer to a character array to print, but does not have a maximum length argument. Instead it calls another function - UI_fontstyle_draw_ex which does, and passes BLF_DRAW_STR_DUMMY_MAX (1024). This is despite the fact that almost all uses of UI_fontstyle_draw involves a static character array where the size is known. The maximum argument is there for safety. Operations will stop when the terminating zero is hit or the maximum length is reached. But in these cases this maximum is beyond the allocated memory size so will cause buffer overflow if the string is not null-terminated.

So this patch just adds a len argument and fixes the uses of it. The only interesting exception is in interface_region_tooltip.c. Its uses are on string pointers of unknown length so I define UI_TIP_STR_MAX 1024 and use that so that maximum string lengths of tooltips can be set/changed separately from other uses of BLF_DRAW_STR_DUMMY_MAX.

This last bit is because we have been asked to consider increasing the maximum string length on tooltips - T94611: Limitations of Cyrillic characters. - and I can't imagine doing that by changing BLF_DRAW_STR_DUMMY_MAX.

Diff Detail

Repository
rB Blender

Event Timeline

Harley Acheson (harley) requested review of this revision.Jan 11 2022, 1:39 AM
Harley Acheson (harley) created this revision.

Requesting minor changes, no need for an extra review iteration.

source/blender/editors/include/UI_interface.h
2959

Keep the length argument paired with the string (directly after the) str argument, it can also str_len to make it more obvious it's the length of the string.

Same for other declarations.

2962

const is only needed in the implementation (some recent cleanups removed these redundant consts).

This revision is now accepted and ready to land.Jan 11 2022, 5:41 AM

Changing order of arguments to keep string length just after string itself. Removing redundant const.

This revision was automatically updated to reflect the committed changes.