Skip to content

Commit 09a7077

Browse files
committed
random: Mark EG(exception) branches as UNEXPECTED
see php#13138 (comment)
1 parent cc934d0 commit 09a7077

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

ext/random/engine_mt19937.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ PHP_METHOD(Random_Engine_Mt19937, generate)
296296
ZEND_PARSE_PARAMETERS_NONE();
297297

298298
php_random_result generated = engine->algo->generate(engine->status);
299-
if (EG(exception)) {
299+
if (UNEXPECTED(EG(exception))) {
300300
RETURN_THROWS();
301301
}
302302

@@ -361,7 +361,7 @@ PHP_METHOD(Random_Engine_Mt19937, __unserialize)
361361
RETURN_THROWS();
362362
}
363363
object_properties_load(&engine->std, Z_ARRVAL_P(t));
364-
if (EG(exception)) {
364+
if (UNEXPECTED(EG(exception))) {
365365
zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(engine->std.ce->name));
366366
RETURN_THROWS();
367367
}

ext/random/engine_user.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static php_random_result generate(php_random_status *status)
3030

3131
zend_call_known_instance_method_with_0_params(s->generate_method, s->object, &retval);
3232

33-
if (EG(exception)) {
33+
if (UNEXPECTED(EG(exception))) {
3434
return (php_random_result){
3535
.size = sizeof(uint64_t),
3636
.result = 0,

ext/random/random.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ PHPAPI uint32_t php_random_range32(const php_random_algo *algo, php_random_statu
8686
php_random_result r = algo->generate(status);
8787
result = result | (((uint32_t) r.result) << (total_size * 8));
8888
total_size += r.size;
89-
if (EG(exception)) {
89+
if (UNEXPECTED(EG(exception))) {
9090
return 0;
9191
}
9292
} while (total_size < sizeof(uint32_t));
@@ -121,7 +121,7 @@ PHPAPI uint32_t php_random_range32(const php_random_algo *algo, php_random_statu
121121
php_random_result r = algo->generate(status);
122122
result = result | (((uint32_t) r.result) << (total_size * 8));
123123
total_size += r.size;
124-
if (EG(exception)) {
124+
if (UNEXPECTED(EG(exception))) {
125125
return 0;
126126
}
127127
} while (total_size < sizeof(uint32_t));
@@ -142,7 +142,7 @@ PHPAPI uint64_t php_random_range64(const php_random_algo *algo, php_random_statu
142142
php_random_result r = algo->generate(status);
143143
result = result | (r.result << (total_size * 8));
144144
total_size += r.size;
145-
if (EG(exception)) {
145+
if (UNEXPECTED(EG(exception))) {
146146
return 0;
147147
}
148148
} while (total_size < sizeof(uint64_t));
@@ -177,7 +177,7 @@ PHPAPI uint64_t php_random_range64(const php_random_algo *algo, php_random_statu
177177
php_random_result r = algo->generate(status);
178178
result = result | (r.result << (total_size * 8));
179179
total_size += r.size;
180-
if (EG(exception)) {
180+
if (UNEXPECTED(EG(exception))) {
181181
return 0;
182182
}
183183
} while (total_size < sizeof(uint64_t));

ext/random/randomizer.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ PHP_METHOD(Random_Randomizer, __construct)
8181

8282
OBJ_RELEASE(Z_OBJ_P(&engine));
8383

84-
if (EG(exception)) {
84+
if (UNEXPECTED(EG(exception))) {
8585
RETURN_THROWS();
8686
}
8787

@@ -104,7 +104,7 @@ PHP_METHOD(Random_Randomizer, nextFloat)
104104
php_random_result r = randomizer->algo->generate(randomizer->status);
105105
result = result | (r.result << (total_size * 8));
106106
total_size += r.size;
107-
if (EG(exception)) {
107+
if (UNEXPECTED(EG(exception))) {
108108
RETURN_THROWS();
109109
}
110110
} while (total_size < sizeof(uint64_t));
@@ -212,7 +212,7 @@ PHP_METHOD(Random_Randomizer, nextInt)
212212
ZEND_PARSE_PARAMETERS_NONE();
213213

214214
php_random_result result = randomizer->algo->generate(randomizer->status);
215-
if (EG(exception)) {
215+
if (UNEXPECTED(EG(exception))) {
216216
RETURN_THROWS();
217217
}
218218
if (result.size > sizeof(zend_long)) {
@@ -257,7 +257,7 @@ PHP_METHOD(Random_Randomizer, getInt)
257257
result = randomizer->algo->range(randomizer->status, min, max);
258258
}
259259

260-
if (EG(exception)) {
260+
if (UNEXPECTED(EG(exception))) {
261261
RETURN_THROWS();
262262
}
263263

@@ -286,7 +286,7 @@ PHP_METHOD(Random_Randomizer, getBytes)
286286

287287
while (total_size < length) {
288288
php_random_result result = randomizer->algo->generate(randomizer->status);
289-
if (EG(exception)) {
289+
if (UNEXPECTED(EG(exception))) {
290290
zend_string_free(retval);
291291
RETURN_THROWS();
292292
}
@@ -405,7 +405,7 @@ PHP_METHOD(Random_Randomizer, getBytesFromString)
405405
while (total_size < length) {
406406
uint64_t offset = randomizer->algo->range(randomizer->status, 0, max_offset);
407407

408-
if (EG(exception)) {
408+
if (UNEXPECTED(EG(exception))) {
409409
zend_string_free(retval);
410410
RETURN_THROWS();
411411
}
@@ -425,7 +425,7 @@ PHP_METHOD(Random_Randomizer, getBytesFromString)
425425
int failures = 0;
426426
while (total_size < length) {
427427
php_random_result result = randomizer->algo->generate(randomizer->status);
428-
if (EG(exception)) {
428+
if (UNEXPECTED(EG(exception))) {
429429
zend_string_free(retval);
430430
RETURN_THROWS();
431431
}
@@ -497,7 +497,7 @@ PHP_METHOD(Random_Randomizer, __unserialize)
497497
RETURN_THROWS();
498498
}
499499
object_properties_load(&randomizer->std, Z_ARRVAL_P(members_zv));
500-
if (EG(exception)) {
500+
if (UNEXPECTED(EG(exception))) {
501501
zend_throw_exception(NULL, "Invalid serialization data for Random\\Randomizer object", 0);
502502
RETURN_THROWS();
503503
}

0 commit comments

Comments
 (0)