]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
py_getrandom(): use long type for the syscall() result
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 16 Jun 2016 21:53:47 +0000 (23:53 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Thu, 16 Jun 2016 21:53:47 +0000 (23:53 +0200)
Issue #27278. It should fix a conversion warning.

In practice, the Linux kernel doesn't return more than 32 MB per call to the
getrandom() syscall.

Python/random.c

index 8ce0b3edf67d058df8b50190c9cd050d41c0aae2..3119872abd6df20a81726d87b90f9dda94d92bcb 100644 (file)
@@ -132,7 +132,7 @@ py_getrandom(void *buffer, Py_ssize_t size, int raise)
      * see https://bugs.python.org/issue26839. To avoid this, use the
      * GRND_NONBLOCK flag. */
     const int flags = GRND_NONBLOCK;
-    int n;
+    long n;
 
     if (!getrandom_works)
         return 0;
@@ -143,7 +143,7 @@ py_getrandom(void *buffer, Py_ssize_t size, int raise)
            to 1024 bytes */
         n = Py_MIN(size, 1024);
 #else
-        n = Py_MIN(size, INT_MAX);
+        n = Py_MIN(size, LONG_MAX);
 #endif
 
         errno = 0;