Skip to content

Commit f079aa2

Browse files
authored
random: Fix return type of php_random_(bytes|int) (#10687)
These return a `zend_result`, not `int`.
1 parent e9c8621 commit f079aa2

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

ext/random/csprng.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "php.h"
2727

28+
#include "zend_result.h"
2829
#include "Zend/zend_exceptions.h"
2930

3031
#include "php_random.h"
@@ -60,7 +61,7 @@
6061
# include <sanitizer/msan_interface.h>
6162
#endif
6263

63-
PHPAPI int php_random_bytes(void *bytes, size_t size, bool should_throw)
64+
PHPAPI zend_result php_random_bytes(void *bytes, size_t size, bool should_throw)
6465
{
6566
#ifdef PHP_WIN32
6667
/* Defer to CryptGenRandom on Windows */
@@ -209,7 +210,7 @@ PHPAPI int php_random_bytes(void *bytes, size_t size, bool should_throw)
209210
return SUCCESS;
210211
}
211212

212-
PHPAPI int php_random_int(zend_long min, zend_long max, zend_long *result, bool should_throw)
213+
PHPAPI zend_result php_random_int(zend_long min, zend_long max, zend_long *result, bool should_throw)
213214
{
214215
zend_ulong umax;
215216
zend_ulong trial;

ext/random/php_random.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#ifndef PHP_RANDOM_H
3232
# define PHP_RANDOM_H
3333

34+
# include "zend_result.h"
35+
3436
PHPAPI double php_combined_lcg(void);
3537

3638
/*
@@ -198,8 +200,8 @@ static inline uint64_t php_random_pcgoneseq128xslrr64_rotr64(php_random_uint128_
198200
# define php_random_int_throw(min, max, result) php_random_int((min), (max), (result), 1)
199201
# define php_random_int_silent(min, max, result) php_random_int((min), (max), (result), 0)
200202

201-
PHPAPI int php_random_bytes(void *bytes, size_t size, bool should_throw);
202-
PHPAPI int php_random_int(zend_long min, zend_long max, zend_long *result, bool should_throw);
203+
PHPAPI zend_result php_random_bytes(void *bytes, size_t size, bool should_throw);
204+
PHPAPI zend_result php_random_int(zend_long min, zend_long max, zend_long *result, bool should_throw);
203205

204206
typedef struct _php_random_status_ {
205207
size_t last_generated_size;

0 commit comments

Comments
 (0)