What tool did you use to find these issues?
PVS Studio? Do you have a license for it or do you use the free license option?
@amitdo
Yes, it's PVS studio. I have a license)
This is their new offering:
https://www.viva64.com/en/b/0600/
As far as I see only the 2nd points at a real problem.
@stweil why do you think division by zero is safe?
It's conditionally, and the condition is never true if the difference is 0 (unless there is a negative line_size which should never happen).
@stweil can you please explain the reason it is never true if the difference is 0?
It's not clear to me
The division is only executed if last_x - left_x > block->line_size * 2. A division by zero would occur if last_x - left_x == 0, that means only if 0 > block->line_size * 2 or rearranged block->line_size < 0.