Skip to content

Commit b1b68c0

Browse files
committed
Convert some warnings to Errors in BZip2
1 parent 2ede8db commit b1b68c0

File tree

7 files changed

+92
-61
lines changed

7 files changed

+92
-61
lines changed

ext/bz2/bz2.c

Lines changed: 10 additions & 10 deletions
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,15 +367,15 @@ 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 */
375375
if (Z_TYPE_P(file) == IS_STRING) {
376376
if (Z_STRLEN_P(file) == 0) {
377-
php_error_docref(NULL, E_WARNING, "filename cannot be empty");
378-
RETURN_FALSE;
377+
zend_value_error("filename cannot be empty");
378+
return;
379379
}
380380

381381
if (CHECK_ZVAL_NULL_PATH(file)) {
@@ -429,8 +429,8 @@ static PHP_FUNCTION(bzopen)
429429

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

436436
if (stream) {
@@ -569,9 +569,9 @@ static PHP_FUNCTION(bzdecompress)
569569
size = (bzs.total_out_hi32 * (unsigned int) -1) + bzs.total_out_lo32;
570570
#if !ZEND_ENABLE_ZVAL_LONG64
571571
if (UNEXPECTED(size > SIZE_MAX)) {
572-
php_error_docref(NULL, E_WARNING, "Decompressed size too big, max is %zd", SIZE_MAX);
572+
zend_value_error("Decompressed size too big, max is %zd", SIZE_MAX);
573573
zend_string_efree(dest);
574-
RETVAL_LONG(BZ_MEM_ERROR);
574+
return;
575575
} else
576576
#endif
577577
{

ext/bz2/bz2_filter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ static php_stream_filter *php_bz2_filter_create(const char *filtername, zval *fi
360360
/* How much memory to allocate (1 - 9) x 100kb */
361361
zend_long blocks = zval_get_long(tmpzval);
362362
if (blocks < 1 || blocks > 9) {
363-
php_error_docref(NULL, E_WARNING, "Invalid parameter given for number of blocks to allocate. (" ZEND_LONG_FMT ")", blocks);
363+
zend_value_error("Invalid parameter given for number of blocks to allocate. (" ZEND_LONG_FMT ")", blocks);
364364
} else {
365365
blockSize100k = (int) blocks;
366366
}
@@ -370,7 +370,7 @@ static php_stream_filter *php_bz2_filter_create(const char *filtername, zval *fi
370370
/* Work Factor (0 - 250) */
371371
zend_long work = zval_get_long(tmpzval);
372372
if (work < 0 || work > 250) {
373-
php_error_docref(NULL, E_WARNING, "Invalid parameter given for work factor. (" ZEND_LONG_FMT ")", work);
373+
zend_value_error("Invalid parameter given for work factor. (" ZEND_LONG_FMT ")", work);
374374
} else {
375375
workFactor = (int) work;
376376
}

ext/bz2/tests/001.phpt

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,53 @@ bzopen() and invalid parameters
55
--FILE--
66
<?php
77

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

1544
$fp = fopen(__FILE__,"r");
1645
var_dump(bzopen($fp, "r"));
1746

18-
echo "Done\n";
1947
?>
2048
--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)
23-
24-
Warning: bzopen(): filename cannot be empty in %s on line %d
25-
bool(false)
26-
27-
Warning: bzopen(): filename cannot be empty in %s on line %d
28-
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)
49+
'' is not a valid mode for bzopen(). Only 'w' and 'r' are supported.
50+
filename cannot be empty
51+
filename cannot be empty
52+
'x' is not a valid mode for bzopen(). Only 'w' and 'r' are supported.
53+
'rw' is not a valid mode for bzopen(). Only 'w' and 'r' are supported.
3554

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

ext/bz2/tests/002.phpt

Lines changed: 12 additions & 10 deletions
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

Lines changed: 9 additions & 7 deletions
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

Lines changed: 9 additions & 7 deletions
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/bug72447.phpt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,19 @@ $input = "AAAAAAAA";
88
$param = array('blocks' => $input);
99

1010
$fp = fopen('testfile', 'w');
11-
stream_filter_append($fp, 'bzip2.compress', STREAM_FILTER_WRITE, $param);
11+
12+
13+
try {
14+
stream_filter_append($fp, 'bzip2.compress', STREAM_FILTER_WRITE, $param);
15+
} catch (\ValueError $e) {
16+
echo $e->getMessage() . \PHP_EOL;
17+
}
18+
1219
fclose($fp);
1320
?>
1421
--CLEAN--
1522
<?php
1623
unlink('testfile');
1724
?>
18-
--EXPECTF--
19-
Warning: stream_filter_append(): Invalid parameter given for number of blocks to allocate. (0) in %s%ebug72447.php on line %d
25+
--EXPECT--
26+
Invalid parameter given for number of blocks to allocate. (0)

0 commit comments

Comments
 (0)