Skip to content

Commit 409cd19

Browse files
committed
Revert "random: fix undefined behaviour"
This reverts commit d5ff87e.
1 parent d5ff87e commit 409cd19

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

ext/random/random.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,14 @@ static zend_object_handlers random_randomizer_object_handlers;
8585
static inline uint32_t rand_range32(const php_random_algo *algo, php_random_status *status, uint32_t umax)
8686
{
8787
uint32_t result, limit, r;
88-
size_t total_size = 0, shift_size = 0;
88+
size_t total_size = 0;
8989
uint32_t count = 0;
9090

9191
result = 0;
9292
total_size = 0;
9393
do {
9494
r = algo->generate(status);
95-
shift_size = (8 * status->last_generated_size);
96-
if ((8 * sizeof(uint32_t)) < shift_size) {
97-
shift_size = 0;
98-
}
99-
result = (result << shift_size) | r;
95+
result = (result << (8 * status->last_generated_size)) | r;
10096
total_size += status->last_generated_size;
10197
if (status->last_unsafe) {
10298
return 0;
@@ -131,11 +127,7 @@ static inline uint32_t rand_range32(const php_random_algo *algo, php_random_stat
131127
total_size = 0;
132128
do {
133129
r = algo->generate(status);
134-
shift_size = (8 * status->last_generated_size);
135-
if ((8 * sizeof(uint32_t)) < shift_size) {
136-
shift_size = 0;
137-
}
138-
result = (result << shift_size) | r;
130+
result = (result << (8 * status->last_generated_size)) | r;
139131
total_size += status->last_generated_size;
140132
if (status->last_unsafe) {
141133
return 0;

0 commit comments

Comments
 (0)