Skip to content
Tcl Source Code View Ticket
Login

View Ticket

TclStringCmp() calls functions through pointer to incorrect type

Closed / Fixedabd489a1cf4782f0255f307c42370d3a5e27c464Created 3 years agoUpdated 3 years ago
Descriptionwiki2023-10-13 07:20:01
Example UBSan -fsanitize=function error:
% string compare a b
tcl/generic/tclCmdMZ.c:2863:10: runtime error: call to function TclpUtfNcmp2 through pointer to incorrect function type 'int (*)(const void *, const void *, unsigned long)'
tclUtf.c:1233: note: TclpUtfNcmp2 defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior tcl/generic/tclCmdMZ.c:2863:10 in 
-1

Some of the compare functions are public APIs, so I would suggest either using an enum to call functions directly, or wrapper functions (as done by the attached patch).

jan.nijtmanswiki2023-10-13 14:09:39

Thanks for the patch! Looks good.

In this case, it's slightly better to do the wrapping slightly different: [6d9d5ac6a75d7832].

jan.nijtmanswiki2023-12-30 00:20:14

This should be fixed in all branches now

Log in (anonymous is fine) to add a comment.

Attachments: