Prevent the division by 0 in getNbDigits function

Ref: https://github.com/notepad-plus-plus/notepad-plus-plus/pull/15152#discussion_r1605845654

Close #15157
This commit is contained in:
Don Ho 2024-05-19 05:05:18 +02:00
parent 13eede938e
commit 382c33e99a

View File

@ -165,6 +165,8 @@ LanguageNameInfo ScintillaEditView::_langNameInfoArray[L_EXTERNAL + 1] = {
int getNbDigits(int aNum, int base) int getNbDigits(int aNum, int base)
{ {
if (base <= 0) return 0;
int nbDigits = 0; int nbDigits = 0;
do do
@ -172,6 +174,7 @@ int getNbDigits(int aNum, int base)
++nbDigits; ++nbDigits;
aNum /= base; aNum /= base;
} while (aNum != 0); } while (aNum != 0);
if (base == 16 && nbDigits % 2 != 0) if (base == 16 && nbDigits % 2 != 0)
++nbDigits; ++nbDigits;
@ -3660,7 +3663,7 @@ bool ScintillaEditView::expandWordSelection()
TCHAR* int2str(TCHAR* str, int strLen, int number, int base, int nbDigits, ColumnEditorParam::leadingChoice lead) TCHAR* int2str(TCHAR* str, int strLen, int number, int base, int nbDigits, ColumnEditorParam::leadingChoice lead)
{ {
if (nbDigits >= strLen) return NULL; if (nbDigits <= 0 || nbDigits >= strLen) return NULL;
if (base == 2) if (base == 2)
{ {