| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fix overflow when creating very large dict. |
| Back | FazBrowse Home | New Git URL |
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI am asking for my curiosity(to become familiar with cpython); How does casting the result of 1<<log2_size to size_t fix the overflow in the dict?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality1 is int. And int is 32bit on most platforms. So 1 << 32 will overflow.
Here is example:
$ cat x.c #include <stdio.h> #include <stdlib.h> #define USABLE_FRACTION(n) (((n) << 1)/3) int main() { size_t x = USABLE_FRACTION(1 << 31); size_t y = USABLE_FRACTION((size_t)1 << 31); printf("x=%zd y=%zd\n", x, y); } $ gcc x.c && ./a.out x.c:7:16: warning: shifting a negative signed value is undefined [-Wshift-negative-value] size_t x = USABLE_FRACTION(1 << 31); ^~~~~~~~~~~~~~~~~~~~~~~~ x.c:4:34: note: expanded from macro 'USABLE_FRACTION' #define USABLE_FRACTION(n) (((n) << 1)/3) ~~~ ^ 1 warning generated. x=0 y=1431655765Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThanks!
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.