Skip to content

Commit a3695ba

Browse files
committed
Convert some warnings to Errors in BZip2
1 parent b8609e2 commit a3695ba

File tree

5 files changed

+64
-45
lines changed

5 files changed

+64
-45
lines changed

ext/bz2/bz2.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,8 @@ static PHP_FUNCTION(bzread)
339339
php_stream_from_zval(stream, bz);
340340

341341
if ((len + 1) < 1) {
342-
php_error_docref(NULL, E_WARNING, "length may not be negative");
343-
RETURN_FALSE;
342+
zend_value_error("length cannot be negative");
343+
return;
344344
}
345345

346346
data = php_stream_read_to_str(stream, len);
@@ -367,8 +367,8 @@ static PHP_FUNCTION(bzopen)
367367
}
368368

369369
if (mode_len != 1 || (mode[0] != 'r' && mode[0] != 'w')) {
370-
php_error_docref(NULL, E_WARNING, "'%s' is not a valid mode for bzopen(). Only 'w' and 'r' are supported.", mode);
371-
RETURN_FALSE;
370+
zend_value_error("'%s' is not a valid mode for bzopen(). Only 'w' and 'r' are supported.", mode);
371+
return;
372372
}
373373

374374
/* If it's not a resource its a string containing the filename to open */
@@ -430,8 +430,8 @@ static PHP_FUNCTION(bzopen)
430430

431431
stream = php_stream_bz2open_from_BZFILE(bz, mode, stream);
432432
} else {
433-
php_error_docref(NULL, E_WARNING, "first parameter has to be string or file-resource");
434-
RETURN_FALSE;
433+
zend_type_error("First parameter has to be string or file-resource");
434+
return;
435435
}
436436

437437
if (stream) {

ext/bz2/tests/001.phpt

+28-15
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,48 @@ bzopen() and invalid parameters
55
--FILE--
66
<?php
77

8-
var_dump(bzopen("", ""));
9-
var_dump(bzopen("", "r"));
8+
try {
9+
var_dump(bzopen("", ""));
10+
} catch (\ValueError $e) {
11+
echo $e->getMessage() . \PHP_EOL;
12+
}
13+
14+
var_dump(bzopen("", "r"));
1015
var_dump(bzopen("", "w"));
11-
var_dump(bzopen("", "x"));
12-
var_dump(bzopen("", "rw"));
13-
var_dump(bzopen("no_such_file", "r"));
16+
17+
try {
18+
var_dump(bzopen("", "x"));
19+
} catch (\ValueError $e) {
20+
echo $e->getMessage() . \PHP_EOL;
21+
}
22+
23+
try {
24+
var_dump(bzopen("", "rw"));
25+
} catch (\ValueError $e) {
26+
echo $e->getMessage() . \PHP_EOL;
27+
}
28+
29+
try {
30+
var_dump(bzopen("no_such_file", "r"));
31+
} catch (\ValueError $e) {
32+
echo $e->getMessage() . \PHP_EOL;
33+
}
1434

1535
$fp = fopen(__FILE__,"r");
1636
var_dump(bzopen($fp, "r"));
1737

18-
echo "Done\n";
1938
?>
2039
--EXPECTF--
21-
Warning: bzopen(): '' is not a valid mode for bzopen(). Only 'w' and 'r' are supported. in %s on line %d
22-
bool(false)
40+
'' is not a valid mode for bzopen(). Only 'w' and 'r' are supported.
2341

2442
Warning: bzopen(): filename cannot be empty in %s on line %d
2543
bool(false)
2644

2745
Warning: bzopen(): filename cannot be empty in %s on line %d
2846
bool(false)
29-
30-
Warning: bzopen(): 'x' is not a valid mode for bzopen(). Only 'w' and 'r' are supported. in %s on line %d
31-
bool(false)
32-
33-
Warning: bzopen(): 'rw' is not a valid mode for bzopen(). Only 'w' and 'r' are supported. in %s on line %d
34-
bool(false)
47+
'x' is not a valid mode for bzopen(). Only 'w' and 'r' are supported.
48+
'rw' is not a valid mode for bzopen(). Only 'w' and 'r' are supported.
3549

3650
Warning: bzopen(no_such_file): failed to open stream: No such file or directory in %s on line %d
3751
bool(false)
3852
resource(%d) of type (stream)
39-
Done

ext/bz2/tests/002.phpt

+12-10
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,18 @@ $fp = fopen("bz_open_002.txt", "wb");
2828
var_dump(bzopen($fp, "w"));
2929

3030
$fp = fopen("bz_open_002.txt", "br");
31-
var_dump(bzopen($fp, "r"));
31+
try {
32+
var_dump(bzopen($fp, "r"));
33+
} catch (\TypeError $e) {
34+
echo $e->getMessage() . \PHP_EOL;
35+
}
3236

3337
$fp = fopen("bz_open_002.txt", "br");
34-
var_dump(bzopen($fp, "w"));
38+
try {
39+
var_dump(bzopen($fp, "w"));
40+
} catch (\TypeError $e) {
41+
echo $e->getMessage() . \PHP_EOL;
42+
}
3543

3644
$fp = fopen("bz_open_002.txt", "r");
3745
var_dump(bzopen($fp, "w"));
@@ -71,7 +79,6 @@ var_dump(bzopen($fp, "w"));
7179

7280
@unlink("bz_open_002.txt");
7381

74-
echo "Done\n";
7582
?>
7683
--EXPECTF--
7784
resource(%d) of type (stream)
@@ -84,14 +91,10 @@ resource(%d) of type (stream)
8491
resource(%d) of type (stream)
8592

8693
Warning: fopen(bz_open_002.txt): failed to open stream: Bad file %s in %s on line %d
87-
88-
Warning: bzopen(): first parameter has to be string or file-resource in %s on line %d
89-
bool(false)
94+
First parameter has to be string or file-resource
9095

9196
Warning: fopen(bz_open_002.txt): failed to open stream: Bad file %s in %s on line %d
92-
93-
Warning: bzopen(): first parameter has to be string or file-resource in %s on line %d
94-
bool(false)
97+
First parameter has to be string or file-resource
9598

9699
Warning: bzopen(): cannot write to a stream opened in read only mode in %s on line %d
97100
bool(false)
@@ -126,4 +129,3 @@ bool(false)
126129
Warning: bzopen(): cannot read from a stream opened in write only mode in %s on line %d
127130
bool(false)
128131
resource(%d) of type (stream)
129-
Done

ext/bz2/tests/003-mb.phpt

+9-7
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@ bzread() tests
77

88
$fd = bzopen(__DIR__."/003私はガラスを食べられます.txt.bz2","r");
99
var_dump(bzread($fd, 0));
10-
var_dump(bzread($fd, -10));
10+
11+
try {
12+
var_dump(bzread($fd, -10));
13+
} catch (\ValueError $e) {
14+
echo $e->getMessage() . \PHP_EOL;
15+
}
16+
1117
var_dump(bzread($fd, 1));
1218
var_dump(bzread($fd, 2));
1319
var_dump(bzread($fd, 100000));
1420

15-
echo "Done\n";
1621
?>
17-
--EXPECTF--
22+
--EXPECT--
1823
string(0) ""
19-
20-
Warning: bzread(): length may not be negative in %s on line %d
21-
bool(false)
24+
length cannot be negative
2225
string(1) "R"
2326
string(2) "is"
2427
string(251) "ing up from the heart of the desert
@@ -30,4 +33,3 @@ Rising up for Jerusalem
3033
Rising up from the heat of the desert
3134
Heading out for Jerusalem
3235
"
33-
Done

ext/bz2/tests/003.phpt

+9-7
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@ bzread() tests
77

88
$fd = bzopen(__DIR__."/003.txt.bz2","r");
99
var_dump(bzread($fd, 0));
10-
var_dump(bzread($fd, -10));
10+
11+
try {
12+
var_dump(bzread($fd, -10));
13+
} catch (\ValueError $e) {
14+
echo $e->getMessage() . \PHP_EOL;
15+
}
16+
1117
var_dump(bzread($fd, 1));
1218
var_dump(bzread($fd, 2));
1319
var_dump(bzread($fd, 100000));
1420

15-
echo "Done\n";
1621
?>
17-
--EXPECTF--
22+
--EXPECT--
1823
string(0) ""
19-
20-
Warning: bzread(): length may not be negative in %s on line %d
21-
bool(false)
24+
length cannot be negative
2225
string(1) "R"
2326
string(2) "is"
2427
string(251) "ing up from the heart of the desert
@@ -30,4 +33,3 @@ Rising up for Jerusalem
3033
Rising up from the heat of the desert
3134
Heading out for Jerusalem
3235
"
33-
Done

0 commit comments

Comments
 (0)