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
py_getrandom() uses an int for syscall() result #71465
Comments
syscall() result type is long. Moreover, long type might can smaller than the size type, so we may need to add: n = Py_MIN(size, LONG_MAX); |
According to <http://man7.org/linux/man-pages/man2/getrandom.2.html\>, getrandom() returns no more than 32 MiB as an int on Linux. Doesn’t that mean you can rely on syscall()’s long return value fitting in an int? Maybe just cast n = (int)sycall(...) to be explicit. But it does make sense to cap n to LONG_MAX just in case there is some strange platform where it matters :) |
Make that INT_MAX. Or change n from an int to a Py_ssize_t. Both Linux and Solaris versions or getrandom() are documented as accepting size_t buflen. |
New changeset e028e86a5b73 by Victor Stinner in branch '3.5': New changeset 0d39bd9028e8 by Victor Stinner in branch 'default': |
Martin: What do you think of my change? Is it enough? Or would you prefer an explicit cast on syscall() result? I hesitated to use a wider type since the manual page shows an "int" type, not long. |
Yeah I think your change is enough. Adding a cast would solve this compiler warning: Python/random.c:168:17: warning: conversion to ‘int’ from ‘long int’ may alter its value [-Wconversion] But on the other hand, when I just recompiled Python with -Wconversion, I got hundreds of other warnings, so maybe there is a good reason we don’t enable that warning. |
New changeset 193f50babfa4 by Victor Stinner in branch '3.5': |
I changed the code to use the long type. It should fix the warning, even if it was no more a real bug: the original bug was already fixed. I close the issue, it's now solved. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: