-
Notifications
You must be signed in to change notification settings - Fork 106
[Fix]: check division overflow for int32 and int64
#1287
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
|
|
||
| if (typeSymbol.Name != "Int32" && typeSymbol.Name != "Int64") | ||
| { | ||
| // -sbyte, -byte, -short, -ushort, -char -> int, -int, -uint -> long |
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.
unsigned types works with negate?
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.
unsigned types works with negate?
- byte, -ushort -> int
- uint -> long
- ulong -> invalid operation
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.
He is right, - ushort => int
| Push(minValue); | ||
| Jump(OpCode.JMPNE_L, endTarget); | ||
|
|
||
| AddInstruction(OpCode.THROW); |
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.
here you can push an exception message before throw, but not necesssary.
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.
here you can push an exception message before throw, but not necesssary.
No exception message before other similar THROWs.
So no exception message here.
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.
here you can push an exception message before throw, but not necesssary.
No exception message before other similar
THROWs. So no exception message here.
LOL, that is actually a problem in other places, having exception message is the correct behavior, but its ok, no need to update. .
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.
here you can push an exception message before throw, but not necesssary.
No exception message before other similar
THROWs. So no exception message here.LOL, that is actually a problem in other places, having exception message is the correct behavior, but its ok, no need to update. .
This and others will be fixed by later PRs.
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.
We should fix it in a different PR
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.
here you can push an exception message before throw, but not necesssary.
No exception message before other similar
THROWs. So no exception message here.LOL, that is actually a problem in other places, having exception message is the correct behavior, but its ok, no need to update. .
Why LOL?
Many cases were written by you. 😏
* master: fix: always check division overflow for int32 and int64 (#1287) Fix: some compiler warnings (#1288) use INC DEC (#1286) Update neo (#1285) Update: keep same sdk version with 'neo' (#1284) partially fix return in try; optimizer replaces JMP->ENDTRY with only ENDTRY (#1283) update to dotnet 9 (#1257) Added some styles (#1280) [`Fix`]: `checked(-x)` if x is int or long (#1281) Fix continue and goto (#1282) # Conflicts: # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Types_BigInteger.cs
Co-authored-by: Jimmy <[email protected]>
Co-authored-by: Jimmy <[email protected]>
Division overflow if
int.MinValue / -1andlong.MinValue / -1.In C#:
Reference: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/expressions#12103-division-operator
There is no division overflow check in
uncheckedstatement.But division overflow is checked in current .Net implementation.
Division overflow may cause the result to exceed the range of int32 or int64(in unchecked statement).
This issue will be fixed later.