Skip to content

Commit ad528e7

Browse files
committed
Add test about invalid comparison with GMP objects
Also remove some dead code
1 parent 6c3b69b commit ad528e7

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

ext/gmp/gmp.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,7 @@ static int gmp_compare(zval *op1, zval *op2) /* {{{ */
429429
zval result;
430430

431431
gmp_cmp(&result, op1, op2);
432-
if (Z_TYPE(result) == IS_FALSE) {
433-
return 1;
434-
}
432+
/* result can only be a zend_long if gmp_cmp hasn't thrown an Error */
435433
return Z_LVAL(result);
436434
}
437435
/* }}} */

ext/gmp/tests/comparison_invalid.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Overloaded GMP comparison in sort() etc
3+
--SKIPIF--
4+
<?php if (!extension_loaded("gmp")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
8+
try {
9+
var_dump("hapfegfbu" > gmp_init(0));
10+
} catch (\Error $e) {
11+
echo $e::class, ': ', $e->getMessage(), \PHP_EOL;
12+
}
13+
14+
try {
15+
var_dump((new DateTime()) > gmp_init(0));
16+
} catch (\Error $e) {
17+
echo $e::class, ': ', $e->getMessage(), \PHP_EOL;
18+
}
19+
20+
?>
21+
--EXPECT--
22+
TypeError: main(): Argument #2 is not an integer string
23+
TypeError: main(): Argument #2 must be of type GMP|string|int, DateTime given

0 commit comments

Comments
 (0)