From 88fbc31ee08238750ed1070ca5181fb2d67d0927 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 29 Mar 2022 14:23:30 +0200 Subject: [PATCH] stb_truetype: fix a division by zero (unused chain of result, but triggering debuggers). (#5139, #5075) Amend 0cff5ac (mislabeled as stb_textedit) --- imstb_truetype.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/imstb_truetype.h b/imstb_truetype.h index bd143556..643d3789 100644 --- a/imstb_truetype.h +++ b/imstb_truetype.h @@ -3200,8 +3200,11 @@ static void stbtt__fill_active_edges_new(float *scanline, float *scanline_fill, // check if final y_crossing is blown up; no test case for this if (y_final > y_bottom) { + int denom = (x2 - (x1+1)); y_final = y_bottom; - dy = (y_final - y_crossing ) / (x2 - (x1+1)); // if denom=0, y_final = y_crossing, so y_final <= y_bottom + if (denom != 0) { // [DEAR IMGUI] Avoid div by zero (https://github.com/nothings/stb/issues/1316) + dy = (y_final - y_crossing ) / denom; // if denom=0, y_final = y_crossing, so y_final <= y_bottom + } } // in second pixel, area covered by line segment found in first pixel