Fix divide-by-zero crash for zero-sized cropped images

Authored by twitt on May 24 2020, 12:57 AM.


Group Reviewers

Gwenview crashes when built as debug version if the cropped tool is executed after an image was cropped to a zero sized image (width or height set to zero). It results in the following assert error:

ASSERT: "!qFuzzyIsNull(c)" in file /usr/include/qt/QtCore/qsize.h, line 202

The origin of this crash is the initialization of the image's ratio in the ratio combobox (to keep a ratio during the crop operation). If width and height are set to zero, the division operation in QRect will crash.

This patch tests if the divisor is zero and will return a ratio of {0, 0} in this case. Those values are valid as a further crop operation is not working anyway, but they prevent the application from crashing.

Test Plan
  1. build Gwenview in debug mode and execute it
  2. open an image
  3. start the crop tool, set width or height to 0, apply the cropping
  4. start the cropping tool again (the application should crash now, without this patch)

Diff Detail

R260 Gwenview
Lint Skipped
Unit Tests Skipped
twitt requested review of this revision.May 24 2020, 12:57 AM
twitt created this revision.
twitt added a comment.Jun 6 2020, 3:03 PM

Hi, is there anybody who can help review?

Also a more general question. Is it better for you to have a big commit or smaller commits for adding features that require several code changes?

anthonyfieroni added inline comments.

Use qFuzzyIsNull(divisor)

twitt added inline comments.Jun 6 2020, 6:10 PM

qFuzzyIsNull is only necessary for float or double variables. It is save to test the integer for zero in this case.

anthonyfieroni accepted this revision.Jun 6 2020, 6:49 PM
This revision is now accepted and ready to land.Jun 6 2020, 6:49 PM
twitt added a comment.Jun 6 2020, 6:50 PM

thanks for reviewing!

Thanks! Can you provide an email address so we can land this with correct git authorship information?

twitt added a comment.Jun 17 2020, 3:46 PM

I hope it's okay to just add it here as a comment:
Tobias Witt <>

Next time I might try out gitlab :)