Browse Source

Prevent the division by 0 in getNbDigits function

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

Close #15157
pull/15166/head
Don Ho 6 months ago
parent
commit
382c33e99a
  1. 5
      PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp

5
PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp

@ -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)
{ {

Loading…
Cancel
Save