mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-10 19:03:30 +00:00
signed overflow in "slider s32 full" demo widget #6675
Labels
No labels
accidentally closed
android
backends
bug
building
clipper
coloredit
color spaces
cplusplus
data types
demo
disabled
doc
docking
dpi
drag drop
drawing/drawlist
dropped
dx12
enhancement
focus
font/text
gallery
help wanted
idle/power saving
ime
in progress
inputs
inputtext
internals
label/id and id stack
language bindings
layout
linux/bsd
menus
multi-contexts
multi-threading
multi-viewports
nav
news/info
opengl
optimization
osx/ios
overlap
plot/graph
popups
question
scrolling
selection
settings
sliders/drags
style
tables/columns
tabs
test wanted
tools
tooltips
tree
tricks & tips
useful widgets
vulkan
web
window pos/depth
window sizing
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ocornut/imgui#6675
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Version/Branch of Dear ImGui:
My Issue/Question:
The demo widget "slider s32 full" creates an integer overflow that my compiler in debug traps with an illegal instruction. Signed overflow is UB IIRC.
Concretely, the issue is with
v_range + 1here:ocornut/imgui@f7eea63872/imgui_widgets.cpp (L2781-L2782)With
v_rangefor "slider s32 full" being 2147483647 = 231-1.Oh, quite true that, same for 64 bits. The expected behavior would be a division by a large negative number, resulting in a small negative number that then gets clamped to
style.GrabMinSize, so no actual problem. But while the actual behavior is known, it technically is undefined, and that should be avoided.@ocornut: replacing
(float)(slider_sz / (v_range + 1))withslider_sz / ((float)v_range + 1.0f))should be safe there.I changed the definition of
v_rangeto float because the only other usageocornut/imgui@f7eea63872/imgui_widgets.cpp (L2851-L2852)treats it like float anyway. That makes it a one word change and the typecast on the division can also be removed.Merged
b7a7d673b9, thanks!