Coverity: CID 400006: Division or modulo by zero
authorNelson Ferreira <nelson.ferreira@ieee.org>
Tue, 6 Mar 2012 00:53:42 +0000 (19:53 -0500)
committerNelson Ferreira <nelson.ferreira@ieee.org>
Tue, 6 Mar 2012 00:53:42 +0000 (19:53 -0500)
* src/ui/window.c (Fwindow_displayed_text_pixel_height): Make sure
no division by 0 is attempted and use "best heuristic" of just
adding 3.

Signed-off-by: Nelson Ferreira <nelson.ferreira@ieee.org>
src/ui/window.c

index 4ec1d6d..92fe992 100644 (file)
@@ -1422,14 +1422,16 @@ is non-nil, do not include space occupied by clipped lines.
                            || Dynarr_atp(cache, i)->end >= eobuf)
                                return make_int(height);
                }
-
+               
                /* get here => need more cache lines.  try again. */
                assert(height > prev_height);   /* progress? */
                prev_height = height;
-
-               needed +=
-                   ((hlimit - height) * (nelt - elt) + height - 1) / height +
-                   3;
+               
+               needed += 3;
+               if ( height != 0)
+                       needed += ((hlimit - height) * 
+                                  (nelt - elt) + 
+                                  height - 1) / height;
        }
 
        RETURN_NOT_REACHED(make_int(0)) /* shut up compiler */