[Geany-devel] Code review: suggest reorder of condition to put bounds check before use

Daniel Marjamäki daniel.marjamaki at xxxxx
Sat Aug 6 14:03:50 UTC 2011


I saw this code in src/symbols.c at line 1917:

       while (sci_get_style_at(sci, start) != fn_style
               && start < max_pos) start++;

If start >= max_pos then sci_get_style_at will be called (with out of
bounds value?) and then the loop will bail out.

I suggest that the condition is reordered as:

       while (start < max_pos
               && sci_get_style_at(sci, start) != fn_style)

Then sci_get_style_at will only be called if start is less than max_pos.

It is just my humble suggestion.

Best regards,

More information about the Devel mailing list