Skip to content

Commit 94771ed

Browse files
committed
Convert some SPL Exceptions to normal Errors in spl_dllist.c
1 parent cf96f8e commit 94771ed

12 files changed

+52
-67
lines changed

ext/spl/spl_dllist.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetGet)
779779
index = spl_offset_convert_to_long(zindex);
780780

781781
if (index < 0 || index >= intern->llist->count) {
782-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid or out of range", 0);
782+
zend_value_error("Offset invalid or out of range");
783783
RETURN_THROWS();
784784
}
785785

@@ -790,7 +790,8 @@ SPL_METHOD(SplDoublyLinkedList, offsetGet)
790790

791791
ZVAL_COPY_DEREF(return_value, value);
792792
} else {
793-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid", 0);
793+
zend_value_error("Offset invalid");
794+
RETURN_THROWS();
794795
}
795796
} /* }}} */
796797

@@ -818,7 +819,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetSet)
818819
index = spl_offset_convert_to_long(zindex);
819820

820821
if (index < 0 || index >= intern->llist->count) {
821-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid or out of range", 0);
822+
zend_value_error("Offset invalid or out of range");
822823
RETURN_THROWS();
823824
}
824825

@@ -841,7 +842,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetSet)
841842
}
842843
} else {
843844
zval_ptr_dtor(value);
844-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid", 0);
845+
zend_value_error("Offset invalid");
845846
RETURN_THROWS();
846847
}
847848
}
@@ -866,7 +867,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetUnset)
866867
llist = intern->llist;
867868

868869
if (index < 0 || index >= intern->llist->count) {
869-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset out of range", 0);
870+
zend_value_error("Offset out of range");
870871
RETURN_THROWS();
871872
}
872873

@@ -907,7 +908,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetUnset)
907908

908909
SPL_LLIST_DELREF(element);
909910
} else {
910-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid", 0);
911+
zend_value_error("Offset invalid");
911912
RETURN_THROWS();
912913
}
913914
} /* }}} */
@@ -1293,7 +1294,7 @@ SPL_METHOD(SplDoublyLinkedList, add)
12931294
index = spl_offset_convert_to_long(zindex);
12941295

12951296
if (index < 0 || index > intern->llist->count) {
1296-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid or out of range", 0);
1297+
zend_value_error("Offset invalid or out of range");
12971298
RETURN_THROWS();
12981299
}
12991300

ext/spl/tests/SplDoublyLinkedList_add_invalid_offset.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ Check that SplDoublyLinkedList::add throws an exception with an invalid offset a
55
try {
66
$dll = new SplDoublyLinkedList();
77
var_dump($dll->add(12,'Offset 12 should not exist'));
8-
} catch (OutOfRangeException $e) {
9-
echo "Exception: ".$e->getMessage()."\n";
8+
} catch (\ValueError $e) {
9+
echo $e->getMessage()."\n";
1010
}
1111
?>
1212
--EXPECT--
13-
Exception: Offset invalid or out of range
13+
Offset invalid or out of range

ext/spl/tests/SplDoublyLinkedList_add_null_offset.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ Check that SplDoublyLinkedList::add throws an exception with an invalid offset a
55
try {
66
$dll = new SplDoublyLinkedList();
77
var_dump($dll->add(NULL,2));
8-
} catch (OutOfRangeException $e) {
9-
echo "Exception: ".$e->getMessage()."\n";
8+
} catch (\ValueError $e) {
9+
echo $e->getMessage()."\n";
1010
}
1111
?>
1212
--EXPECT--
13-
Exception: Offset invalid or out of range
13+
Offset invalid or out of range

ext/spl/tests/SplDoublyLinkedList_offsetGet_param_array.phpt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ PHPNW Test Fest 2009 - Jordan Hatch
77

88
$array = new SplDoublyLinkedList( );
99

10-
$get = $array->offsetGet( array( 'fail' ) );
10+
try {
11+
$array->offsetGet( array( 'fail' ) );
12+
} catch(\ValueError $e) {
13+
echo $e->getMessage();
14+
}
1115

1216
?>
13-
--EXPECTF--
14-
Fatal error: Uncaught OutOfRangeException: Offset invalid or out of range in %s
15-
Stack trace:
16-
#0 %s
17-
#1 {main}
18-
thrown in %s on line %d
17+
--EXPECT--
18+
Offset invalid or out of range

ext/spl/tests/SplDoublyLinkedList_offsetGet_param_string.phpt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ PHPNW Test Fest 2009 - Jordan Hatch
77

88
$array = new SplDoublyLinkedList( );
99

10-
$get = $array->offsetGet( 'fail' );
10+
try {
11+
$array->offsetGet( 'fail' );
12+
} catch(\ValueError $e) {
13+
echo $e->getMessage();
14+
}
1115

1216
?>
13-
--EXPECTF--
14-
Fatal error: Uncaught OutOfRangeException: Offset invalid or out of range in %s
15-
Stack trace:
16-
#0 %s
17-
#1 {main}
18-
thrown in %s on line %d
17+
--EXPECT--
18+
Offset invalid or out of range

ext/spl/tests/SplDoublyLinkedList_offsetUnset_greater_than_elements.phpt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@ $ll->push('2');
1111
$ll->push('3');
1212

1313
try {
14-
15-
$ll->offsetUnset($ll->count() + 1);
16-
17-
var_dump($ll);
18-
19-
} catch(Exception $e) {
20-
echo $e->getMessage();
14+
$ll->offsetUnset($ll->count() + 1);
15+
var_dump($ll);
16+
} catch(\ValueError $e) {
17+
echo $e->getMessage();
2118
}
2219

2320
?>

ext/spl/tests/SplDoublyLinkedList_offsetUnset_negative-parameter.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ PHPNW Testfest 2009 - Paul Court ( g@rgoyle.com )
1414

1515
try {
1616
$dll->offsetUnset(-1);
17-
}
18-
catch (Exception $e) {
17+
} catch (\ValueError $e) {
1918
echo $e->getMessage() . "\n";
2019
}
2120
?>

ext/spl/tests/SplDoublyLinkedList_offsetUnset_parameter-larger-num-elements.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ PHPNW Testfest 2009 - Paul Court ( g@rgoyle.com )
1414

1515
try {
1616
$dll->offsetUnset(3);
17-
}
18-
catch (Exception $e) {
17+
} catch (\ValueError $e) {
1918
echo $e->getMessage() . "\n";
2019
}
2120
?>

ext/spl/tests/bug46160.phpt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
Bug #46160 (SPL - Memory leak when exception is throwed in offsetSet method)
33
--FILE--
44
<?php
5-
65
try {
76
$x = new splqueue;
87
$x->offsetSet(0, 0);
9-
} catch (Exception $e) { }
10-
8+
} catch (\ValueError $e) {
9+
echo $e->getMessage()."\n";
10+
}
1111
?>
12-
DONE
1312
--EXPECT--
14-
DONE
13+
Offset invalid or out of range

ext/spl/tests/bug71735.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Bug #71735 (Double-free in SplDoublyLinkedList::offsetSet)
33
--FILE--
44
<?php
55
try {
6-
$var_1=new SplStack();
7-
$var_1->offsetSet(100,new DateTime('2000-01-01'));
8-
} catch(OutOfRangeException $e) {
6+
$var_1=new SplStack();
7+
$var_1->offsetSet(100,new DateTime('2000-01-01'));
8+
} catch(\ValueError $e) {
99
print $e->getMessage()."\n";
1010
}
1111
?>

ext/spl/tests/dllist_006.phpt

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,20 @@ echo "Unsetting..\n";
1919
var_dump($a[2]);
2020
unset($a[2]);
2121
var_dump($a[2]);
22-
23-
24-
try {
25-
var_dump($a["1"]);
26-
} catch (OutOfRangeException $e) {
27-
echo "Exception: ".$e->getMessage()."\n";
28-
}
22+
var_dump($a["1"]);
2923

3024
try {
3125
var_dump($a["a"]);
32-
} catch (OutOfRangeException $e) {
33-
echo "Exception: ".$e->getMessage()."\n";
26+
} catch (\ValueError $e) {
27+
echo $e->getMessage()."\n";
3428
}
3529

36-
try {
37-
var_dump($a["0"]);
38-
} catch (OutOfRangeException $e) {
39-
echo "Exception: ".$e->getMessage()."\n";
40-
}
30+
var_dump($a["0"]);
4131

4232
try {
4333
var_dump($a["9"]);
44-
} catch (OutOfRangeException $e) {
45-
echo "Exception: ".$e->getMessage()."\n";
34+
} catch (\ValueError $e) {
35+
echo $e->getMessage()."\n";
4636
}
4737
?>
4838
--EXPECT--
@@ -54,6 +44,6 @@ Unsetting..
5444
int(3)
5545
int(4)
5646
int(2)
57-
Exception: Offset invalid or out of range
47+
Offset invalid or out of range
5848
int(1)
59-
Exception: Offset invalid or out of range
49+
Offset invalid or out of range

ext/spl/tests/dllist_013.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ $dll = new SplDoublyLinkedList();
66
// errors
77
try {
88
$dll->add(2,5);
9-
} catch (OutOfRangeException $e) {
10-
echo "Exception: ".$e->getMessage()."\n";
9+
} catch (\ValueError $e) {
10+
echo $e->getMessage()."\n";
1111
}
1212

1313
$dll->add(0,6); // 6
@@ -31,7 +31,7 @@ echo $dll->pop()."\n";
3131
echo $dll->pop()."\n";
3232
?>
3333
--EXPECT--
34-
Exception: Offset invalid or out of range
34+
Offset invalid or out of range
3535
7
3636
7
3737
6

0 commit comments

Comments
 (0)