From 44e5e4c76564d127cd2e3ae6dae9c1a2c6d219f3 Mon Sep 17 00:00:00 2001 From: Harald Oehlmann Date: Mon, 29 Mar 2021 13:19:14 +0200 Subject: [PATCH] Fix for ticket #179 "division by 0" proposed by SergeySlice --- src/nanosvg.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/nanosvg.h b/src/nanosvg.h index 4c03ee5..3511664 100644 --- a/src/nanosvg.h +++ b/src/nanosvg.h @@ -2187,7 +2187,12 @@ static void nsvg__pathArcTo(NSVGparser* p, float* cpx, float* cpy, float* args, // The loop assumes an iteration per end point (including start and end), this +1. ndivs = (int)(fabsf(da) / (NSVG_PI*0.5f) + 1.0f); hda = (da / (float)ndivs) / 2.0f; - kappa = fabsf(4.0f / 3.0f * (1.0f - cosf(hda)) / sinf(hda)); + // Fix for ticket #179: division by 0: avoid cotangens around 0 (infinite) + if ((hda < 1e-3f) && (hda > -1e-3f)) + hda *= 0.5f; + else + hda = (1.0f - cosf(hda)) / sinf(hda); + kappa = fabsf(4.0f / 3.0f * hda); if (da < 0.0f) kappa = -kappa;