From d0e3a1a210c6a2ea5eb3e92db4c248added8ec9b Mon Sep 17 00:00:00 2001 From: cddiffz Date: Fri, 17 May 2024 18:43:42 +0200 Subject: [PATCH] Fix crash in Column Editor Avoid division by zero (due to an arithmetic overflow). Fix #15144, close #15152 --- .../ScintillaComponent/ScintillaEditView.cpp | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp index 83fa63773..69f48c548 100644 --- a/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp @@ -165,24 +165,17 @@ LanguageNameInfo ScintillaEditView::_langNameInfoArray[L_EXTERNAL + 1] = { int getNbDigits(int aNum, int base) { - int nbChiffre = 1; - int diviseur = base; + int nbDigits = 0; - for (;;) + do { - int result = aNum / diviseur; - if (!result) - break; - else - { - diviseur *= base; - ++nbChiffre; - } - } - if ((base == 16) && (nbChiffre % 2 != 0)) - nbChiffre += 1; + ++nbDigits; + aNum /= base; + } while (aNum != 0); + if (base == 16 && nbDigits % 2 != 0) + ++nbDigits; - return nbChiffre; + return nbDigits; } bool isCharSingleQuote(__inout wchar_t const c)