Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix division by zero #15152

Closed
wants to merge 1 commit into from
Closed

Conversation

cddiffz
Copy link
Contributor

@cddiffz cddiffz commented May 17, 2024

Fix #15144

@@ -165,20 +165,13 @@ LanguageNameInfo ScintillaEditView::_langNameInfoArray[L_EXTERNAL + 1] = {

int getNbDigits(int aNum, int base)
{
int nbChiffre = 1;
int diviseur = base;
int nbChiffre = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not take the opportunity to convert the code to English at this time?
Suggest nbChiffre become nbDigits.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. As this is my first contribution, I wanted to change as little as possible. I found more bugs, so I'll know better next time.

Copy link
Contributor Author

@cddiffz cddiffz May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed identifier as suggested
Fixed author

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@donho Hopefully it is ok for me to make the suggestion to convert French to English in the code. I know that when I submitted some Column Editor code changes previously, I did such language updates and it was accepted...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alankilborn @cddiffz
Yes, it's good.
I did it (using inconsistently French word) because both are not my mother tongue.
However, the code should be done by a international language for the sake that everyone can understand so everyone can maintain it.

@cddiffz cddiffz requested a review from alankilborn May 17, 2024 17:32
@chcg chcg added the crash issue causing N++ to crash label May 18, 2024
{
int result = aNum / diviseur;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cddiffz Did the division by zero happen here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the divisor can become zero due to an arithmetic overflow.

Copy link
Contributor

@chcg chcg May 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I see, because also in the new code a div by zero is possible if the provided base parameter is already zero by the caller. Maybe an additional check for that makes sense also currently just base 10, 16, 8, 2 is in use. But there is no description that just these bases could be used.

Copy link
Contributor Author

@cddiffz cddiffz May 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual calling code first sets the base to 10, then possibly changes it to either 2, 8 or 16. If zero were passed as the base, the calling code would be flawed anyway, wouldn't it? Bases smaller than 2 are unusable for positional numeral systems. There is no point in trying to catch them here.

++nbDigits;
aNum /= base;
} while (aNum != 0);
if (base == 16 && nbDigits % 2 != 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cddiffz For input aNum = 0 and base =16 this would result in nbDigits = 1 from do-while above already here and as 1%2 = 1 != 0 would result in another increment to nbDigits.

Copy link
Contributor Author

@cddiffz cddiffz May 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that was already the case before. I didn't change the semantics at all, just fixed the bug.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is correct also it seems to be strange.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another bug for me. With "Format" set to "Hex", e.g. instead of "100", "100 " is inserted because of the rounding to the next even number.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chcg

For input aNum = 0 and base =16 this would result in nbDigits = 1 from do-while above already here and as 1%2 = 1 != 0 would result in another increment to nbDigits.

If aNum is 0 & the base is 16, then nbDigits will be 2: I don't see why it's a bug since we present HEX as 0x00.

@cddiffz

instead of "100", "100 " is inserted because of the rounding to the next even number.

I don't quite follow you. Could you provide step by step instructions to reproduce the bug please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #15168

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted crash issue causing N++ to crash
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Inserting numbers with Column Editor causes crash
4 participants