lighttransport / nanort

NanoRT, single header only modern ray tracing kernel.
MIT License
1.07k stars 89 forks source link

Potential issue in examples/common/imgui/imgui.cpp: Unchecked return from initialization function #64

Closed monocle-ai closed 4 years ago

monocle-ai commented 4 years ago

What is a Conditionally Uninitialized Variable? The return value of a function that is potentially used to initialize a local variable is not checked. Therefore, reading the local variable may result in undefined behavior.

2 instances of this defect were found in the following locations:


Instance 1 File : examples/common/imgui/imgui.cpp Enclosing Function : UpdateManualResize@ImGui Function : ButtonBehavior@ImGui https://github.com/lighttransport/nanort/blob/135a452385a2903592db7518fbb80479d99ab9c3/examples/common/imgui/imgui.cpp#L4405 Issue in: held, hovered

Code extract:

        if (resize_rect.Min.x > resize_rect.Max.x) ImSwap(resize_rect.Min.x, resize_rect.Max.x);
        if (resize_rect.Min.y > resize_rect.Max.y) ImSwap(resize_rect.Min.y, resize_rect.Max.y);
        bool hovered, held;
        ButtonBehavior(resize_rect, window->GetID((void*)(intptr_t)resize_grip_n), &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus); <------ HERE
        if (hovered || held)
            g.MouseCursor = (resize_grip_n & 1) ? ImGuiMouseCursor_ResizeNESW : ImGuiMouseCursor_ResizeNWSE;

How can I fix it? Fix provided in corresponding Pull Request.


Instance 2 File : examples/common/imgui/imgui.cpp Enclosing Function : UpdateManualResize@ImGui Function : ButtonBehavior@ImGui https://github.com/lighttransport/nanort/blob/135a452385a2903592db7518fbb80479d99ab9c3/examples/common/imgui/imgui.cpp#L4431 Issue in: held, hovered

Code extract:

        const float BORDER_APPEAR_TIMER = 0.05f; // Reduce visual noise
        bool hovered, held;
        ImRect border_rect = GetResizeBorderRect(window, border_n, grip_hover_size, BORDER_SIZE);
        ButtonBehavior(border_rect, window->GetID((void*)(intptr_t)(border_n + 4)), &hovered, &held, ImGuiButtonFlags_FlattenChildren); <------ HERE
        if ((hovered && g.HoveredIdTimer > BORDER_APPEAR_TIMER) || held)
        {

How can I fix it? Fix provided in corresponding Pull Request.

syoyo commented 4 years ago

Please report the issue to imgui project, not here.