Re: [PATCH v2] GDB: Fix the overflow in addr_is_displayed()

Pedro Alves
2020-01-06T13:03:29Z

On 1/6/20 12:43 PM, Shahab Vahedi wrote:

> How does this look?
>
> bool is_displayed = false;
> int threshold = SCROLL_THRESHOLD;
>
> - int i = 0;
> - while (i < content.size () - threshold && !is_displayed)
> + if (content.size () < threshold)
> + return is_displayed;
> +

I'd write "false" instead of "is_displayed", to remove the
indirection. Actually, do we really need the "threshold"
variable, btw? Or even, "is_displayed"? Isn't the
following equivalent?

if (content.size () < SCROLL_THRESHOLD)
return false;

for (size_t i = 0;
i < content.size () - SCROLL_THRESHOLD;
i++)
{
if (content[i].line_or_addr.loa == LOA_ADDRESS
&& content[i].line_or_addr.u.addr == addr)
return true;
}

return false;

Anyway, what you have is fine too.

More importantly, doesn't tui_source_window::line_is_displayed
have the exact same issue?

Thanks,
Pedro Alves