Commit b3618d6
committed
menu/ozone: silence UBSan float-to-unsigned conversion in entries draw
UBSan-instrumented run reported:
menu/drivers/ozone.c:6401:13: runtime error: -10.0781 is outside
the range of representable values of type 'unsigned int'
Origin: the value-text y argument to ozone_draw_entry_value() is
declared as unsigned, but the y expression at the call site is
y /* size_t */
+ ozone->dimensions.entry_height / 2 /* int */
+ ozone->fonts.entries_label.line_centre_offset /* int */
+ scroll_y /* float */
The trailing float promotes the whole sum to float. scroll_y is
clamped to (-inf, 0] (lines 10435-10436), so when the topmost
partially-visible row's vertical centre lands above the header
boundary -- reachable during pointer/wheel scrolling -- the sum
goes slightly negative (UBSan saw -10.0781). The implicit
float-to-unsigned conversion of a negative is undefined per C11
6.3.1.4 p1.
Runtime impact: low. Every modern compiler wraps the conversion
to ~UINT_MAX in practice; ozone_draw_entry_value then promotes
that back to float as it forwards into gfx_display_draw_text(),
producing a coordinate around 4.29e9 that the rasteriser clips
off-screen. The value text just doesn't render that frame,
visibly matching the off-screen-row case it would have hit on
the next frame anyway.
Fix: cast the sum through int (defined conversion for the range
these screen coordinates occupy: small positive y plus a bounded
negative scroll_y) so the negative case wraps in a defined
manner rather than triggering UB. Matches the
(int)((float)y + scroll_y) idiom already used at lines 3581,
3595, 5970 and 5985 in the same file for sibling y arguments
that are signed-typed at the callee.
Also folds entry_height / 2 -> entry_height / 2.0f for
consistency with the surrounding label and sublabel y
expressions at lines 6319 and 6346, which already use float
division -- relevant only on the rare odd entry_height where
integer division would round half a pixel below the float
result.1 parent 50f3dd8 commit b3618d6
1 file changed
Lines changed: 21 additions & 3 deletions
File tree
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6398 | 6398 | | |
6399 | 6399 | | |
6400 | 6400 | | |
6401 | | - | |
6402 | | - | |
| 6401 | + | |
| 6402 | + | |
| 6403 | + | |
| 6404 | + | |
| 6405 | + | |
| 6406 | + | |
| 6407 | + | |
| 6408 | + | |
| 6409 | + | |
| 6410 | + | |
| 6411 | + | |
| 6412 | + | |
| 6413 | + | |
| 6414 | + | |
| 6415 | + | |
| 6416 | + | |
| 6417 | + | |
| 6418 | + | |
| 6419 | + | |
| 6420 | + | |
6403 | 6421 | | |
6404 | | - | |
| 6422 | + | |
6405 | 6423 | | |
6406 | 6424 | | |
6407 | 6425 | | |
| |||
0 commit comments