Skip to content

Commit 3eb1bc7

Browse files
committed
Convert some warnings into ValueErrors in standard file.c
1 parent 8baf63c commit 3eb1bc7

26 files changed

+716
-8220
lines changed

ext/standard/file.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,8 @@ PHP_FUNCTION(flock)
351351

352352
act = operation & 3;
353353
if (act < 1 || act > 3) {
354-
php_error_docref(NULL, E_WARNING, "Illegal operation argument");
355-
RETURN_FALSE;
354+
zend_value_error("Illegal operation argument");
355+
return;
356356
}
357357

358358
if (wouldblock) {
@@ -745,8 +745,8 @@ PHP_FUNCTION(file)
745745
ZEND_PARSE_PARAMETERS_END();
746746

747747
if (flags < 0 || flags > (PHP_FILE_USE_INCLUDE_PATH | PHP_FILE_IGNORE_NEW_LINES | PHP_FILE_SKIP_EMPTY_LINES | PHP_FILE_NO_DEFAULT_CONTEXT)) {
748-
php_error_docref(NULL, E_WARNING, "'" ZEND_LONG_FMT "' flag is not supported", flags);
749-
RETURN_FALSE;
748+
zend_value_error("'" ZEND_LONG_FMT "' flag is not supported", flags);
749+
return;
750750
}
751751

752752
use_include_path = flags & PHP_FILE_USE_INCLUDE_PATH;
@@ -1042,8 +1042,8 @@ PHPAPI PHP_FUNCTION(fgets)
10421042
efree(buf);
10431043
} else if (argc > 1) {
10441044
if (len <= 0) {
1045-
php_error_docref(NULL, E_WARNING, "Length parameter must be greater than 0");
1046-
RETURN_FALSE;
1045+
zend_value_error("Length parameter must be greater than 0");
1046+
return;
10471047
}
10481048

10491049
str = zend_string_alloc(len, 0);
@@ -1497,8 +1497,8 @@ PHP_NAMED_FUNCTION(php_if_ftruncate)
14971497
ZEND_PARSE_PARAMETERS_END();
14981498

14991499
if (size < 0) {
1500-
php_error_docref(NULL, E_WARNING, "Negative size is not supported");
1501-
RETURN_FALSE;
1500+
zend_value_error("Negative size is not supported");
1501+
return;
15021502
}
15031503

15041504
PHP_STREAM_TO_ZVAL(stream, fp);
@@ -1752,8 +1752,8 @@ PHPAPI PHP_FUNCTION(fread)
17521752
PHP_STREAM_TO_ZVAL(stream, res);
17531753

17541754
if (len <= 0) {
1755-
php_error_docref(NULL, E_WARNING, "Length parameter must be greater than 0");
1756-
RETURN_FALSE;
1755+
zend_value_error("Length parameter must be greater than 0");
1756+
return;
17571757
}
17581758

17591759
str = php_stream_read_to_str(stream, len);
@@ -1831,8 +1831,8 @@ PHP_FUNCTION(fputcsv)
18311831
if (delimiter_str != NULL) {
18321832
/* Make sure that there is at least one character in string */
18331833
if (delimiter_str_len < 1) {
1834-
php_error_docref(NULL, E_WARNING, "delimiter must be a character");
1835-
RETURN_FALSE;
1834+
zend_value_error("delimiter must be a character");
1835+
return;
18361836
} else if (delimiter_str_len > 1) {
18371837
php_error_docref(NULL, E_NOTICE, "delimiter must be a single character");
18381838
}
@@ -1843,8 +1843,8 @@ PHP_FUNCTION(fputcsv)
18431843

18441844
if (enclosure_str != NULL) {
18451845
if (enclosure_str_len < 1) {
1846-
php_error_docref(NULL, E_WARNING, "enclosure must be a character");
1847-
RETURN_FALSE;
1846+
zend_value_error("enclosure must be a character");
1847+
return;
18481848
} else if (enclosure_str_len > 1) {
18491849
php_error_docref(NULL, E_NOTICE, "enclosure must be a single character");
18501850
}
@@ -1969,8 +1969,8 @@ PHP_FUNCTION(fgetcsv)
19691969
if (delimiter_str != NULL) {
19701970
/* Make sure that there is at least one character in string */
19711971
if (delimiter_str_len < 1) {
1972-
php_error_docref(NULL, E_WARNING, "delimiter must be a character");
1973-
RETURN_FALSE;
1972+
zend_value_error("delimiter must be a character");
1973+
return;
19741974
} else if (delimiter_str_len > 1) {
19751975
php_error_docref(NULL, E_NOTICE, "delimiter must be a single character");
19761976
}
@@ -1981,8 +1981,8 @@ PHP_FUNCTION(fgetcsv)
19811981

19821982
if (enclosure_str != NULL) {
19831983
if (enclosure_str_len < 1) {
1984-
php_error_docref(NULL, E_WARNING, "enclosure must be a character");
1985-
RETURN_FALSE;
1984+
zend_value_error("enclosure must be a character");
1985+
return;
19861986
} else if (enclosure_str_len > 1) {
19871987
php_error_docref(NULL, E_NOTICE, "enclosure must be a single character");
19881988
}
@@ -2006,8 +2006,8 @@ PHP_FUNCTION(fgetcsv)
20062006
if (len_zv != NULL && Z_TYPE_P(len_zv) != IS_NULL) {
20072007
len = zval_get_long(len_zv);
20082008
if (len < 0) {
2009-
php_error_docref(NULL, E_WARNING, "Length parameter may not be negative");
2010-
RETURN_FALSE;
2009+
zend_value_error("Length parameter may not be negative");
2010+
return;
20112011
} else if (len == 0) {
20122012
len = -1;
20132013
}

ext/standard/tests/file/bug71882.phpt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ Bug #71882 (Negative ftruncate() on php://memory exhausts memory)
33
--FILE--
44
<?php
55
$fd = fopen("php://memory", "w+");
6-
var_dump(ftruncate($fd, -1));
6+
try {
7+
var_dump(ftruncate($fd, -1));
8+
} catch (\ValueError $e) {
9+
echo $e->getMessage() . \PHP_EOL;
10+
}
711
?>
8-
--EXPECTF--
9-
Warning: ftruncate(): Negative size is not supported in %s%ebug71882.php on line %d
10-
bool(false)
12+
--EXPECT--
13+
Negative size is not supported
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"water",fruit
2+
This is line of text without csv fields
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
--TEST--
2+
Various fgetcsv() error conditions
3+
--FILE--
4+
<?php
5+
6+
$file_name = __DIR__ . '/fgetcsv_error_conditions.csv';
7+
$file_handle = fopen($file_name, 'r');
8+
9+
$length = 1024;
10+
$delimiter = ',';
11+
$enclosure = '"';
12+
13+
echo 'fgetcsv() with negative length' . \PHP_EOL;
14+
try {
15+
var_dump( fgetcsv($file_handle, -10) );
16+
} catch (\ValueError $e) {
17+
echo $e->getMessage() . \PHP_EOL;
18+
}
19+
try {
20+
var_dump( fgetcsv($file_handle, -10, $delimiter) );
21+
} catch (\ValueError $e) {
22+
echo $e->getMessage() . \PHP_EOL;
23+
}
24+
try {
25+
var_dump( fgetcsv($file_handle, -10, $delimiter, $enclosure) );
26+
} catch (\ValueError $e) {
27+
echo $e->getMessage() . \PHP_EOL;
28+
}
29+
30+
echo 'fgetcsv() with delimiter as NULL' . \PHP_EOL;
31+
try {
32+
var_dump( fgetcsv($file_handle, $length, NULL, $enclosure) );
33+
} catch (\ValueError $e) {
34+
echo $e->getMessage() . \PHP_EOL;
35+
}
36+
37+
echo 'fgetcsv() with enclosure as NULL' . \PHP_EOL;
38+
try {
39+
var_dump( fgetcsv($file_handle, $length, $delimiter, NULL) );
40+
} catch (\ValueError $e) {
41+
echo $e->getMessage() . \PHP_EOL;
42+
}
43+
44+
echo 'fgetcsv() with delimiter & enclosure as NULL' . \PHP_EOL;
45+
try {
46+
var_dump( fgetcsv($file_handle, $length, NULL, NULL) );
47+
} catch (\ValueError $e) {
48+
echo $e->getMessage() . \PHP_EOL;
49+
}
50+
?>
51+
--EXPECT--
52+
fgetcsv() with negative length
53+
Length parameter may not be negative
54+
Length parameter may not be negative
55+
Length parameter may not be negative
56+
fgetcsv() with delimiter as NULL
57+
delimiter must be a character
58+
fgetcsv() with enclosure as NULL
59+
enclosure must be a character
60+
fgetcsv() with delimiter & enclosure as NULL
61+
delimiter must be a character

0 commit comments

Comments
 (0)