-
-
Notifications
You must be signed in to change notification settings - Fork 741
Issue 15678: BigInt("") should not break array bounds #3995
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
Conversation
data = 0UL; | ||
sign = false; | ||
assert(isZero()); | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decided to just initialize a zero BigInt instead of throwing or asserting, as I didn't want to introduce possible breakage in nothrow
code, and the original bug report was complaining about array overrun in -release
(no-assert) mode.
In my opinion, it would have been better if the constructor threw, but I see your point about not wanting to break |
Also, if we define BigInt("") to be zero I guess it should be documented. |
ff5f8a9
to
1273a78
Compare
I noticed the comment too, but wasn't sure whether to actually make the constructor throwing. It does date from quite a few years back, and things have changed since. Anyway, updated the ddoc comment. I changed it from |
I have little experience with I see Moreover, if the constructor throws, an important semantic invariant like |
Well, got my hands on a D compiler now to answer my own questions.
|
Point 1 shows that the constructor is not nothrow anyway, so this is not a concern. As to point 2, it already provides an undocumented exception to the semantic invariant. I should note that converting "" to "0" is less innocent than converting "-0" or "00" to "0": additionally, it might break some tokenization routines when converting back and forth. At any rate, I don't see a use case for silently handling "" in a defined way instead of issuing a prominent error. |
@GassaFM: You are absolutely right, thanks for checking this! It seems that
It seems that this needs some more cleaning-up. Now I definitely think that the constructor should throw, and it should throw the same exception whether something is an empty string, an invalid hex string or an invalid decimal string. |
From another point of view: How can a |
1273a78
to
2c3d2be
Compare
Modified to throw exception on empty string instead. |
Throws exception on empty string instead. Update ddoc. Also throw on invalid digit strings.
2c3d2be
to
de7504b
Compare
Also changed current code to throw on invalid digit string. |
@GassaFM OutOfMemory errors, AFAIK, are Errors, not Exceptions, so they can be thrown even in |
de7504b
to
887414b
Compare
Weird autotester failure, doesn't seem related to this PR? Am I missing something here? |
OK, seems to be passing now. |
ping @kyllingstad |
Auto-merge toggled on |
Sorry, slipped my mind :-/ |
Issue 15678: BigInt("") should not break array bounds
No problem, thanks! |
Fixes: https://issues.dlang.org/show_bug.cgi?id=15678