Skip to content

Commit 78e06fc

Browse files
committed
Convert some warnings into ValueErrors in standard file.c
1 parent 99db00b commit 78e06fc

26 files changed

+715
-8219
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;
@@ -1040,8 +1040,8 @@ PHPAPI PHP_FUNCTION(fgets)
10401040
efree(buf);
10411041
} else if (argc > 1) {
10421042
if (len <= 0) {
1043-
php_error_docref(NULL, E_WARNING, "Length parameter must be greater than 0");
1044-
RETURN_FALSE;
1043+
zend_value_error("Length parameter must be greater than 0");
1044+
return;
10451045
}
10461046

10471047
str = zend_string_alloc(len, 0);
@@ -1495,8 +1495,8 @@ PHP_NAMED_FUNCTION(php_if_ftruncate)
14951495
ZEND_PARSE_PARAMETERS_END();
14961496

14971497
if (size < 0) {
1498-
php_error_docref(NULL, E_WARNING, "Negative size is not supported");
1499-
RETURN_FALSE;
1498+
zend_value_error("Negative size is not supported");
1499+
return;
15001500
}
15011501

15021502
PHP_STREAM_TO_ZVAL(stream, fp);
@@ -1750,8 +1750,8 @@ PHPAPI PHP_FUNCTION(fread)
17501750
PHP_STREAM_TO_ZVAL(stream, res);
17511751

17521752
if (len <= 0) {
1753-
php_error_docref(NULL, E_WARNING, "Length parameter must be greater than 0");
1754-
RETURN_FALSE;
1753+
zend_value_error("Length parameter must be greater than 0");
1754+
return;
17551755
}
17561756

17571757
str = php_stream_read_to_str(stream, len);
@@ -1829,8 +1829,8 @@ PHP_FUNCTION(fputcsv)
18291829
if (delimiter_str != NULL) {
18301830
/* Make sure that there is at least one character in string */
18311831
if (delimiter_str_len < 1) {
1832-
php_error_docref(NULL, E_WARNING, "delimiter must be a character");
1833-
RETURN_FALSE;
1832+
zend_value_error("delimiter must be a character");
1833+
return;
18341834
} else if (delimiter_str_len > 1) {
18351835
php_error_docref(NULL, E_NOTICE, "delimiter must be a single character");
18361836
}
@@ -1841,8 +1841,8 @@ PHP_FUNCTION(fputcsv)
18411841

18421842
if (enclosure_str != NULL) {
18431843
if (enclosure_str_len < 1) {
1844-
php_error_docref(NULL, E_WARNING, "enclosure must be a character");
1845-
RETURN_FALSE;
1844+
zend_value_error("enclosure must be a character");
1845+
return;
18461846
} else if (enclosure_str_len > 1) {
18471847
php_error_docref(NULL, E_NOTICE, "enclosure must be a single character");
18481848
}
@@ -1967,8 +1967,8 @@ PHP_FUNCTION(fgetcsv)
19671967
if (delimiter_str != NULL) {
19681968
/* Make sure that there is at least one character in string */
19691969
if (delimiter_str_len < 1) {
1970-
php_error_docref(NULL, E_WARNING, "delimiter must be a character");
1971-
RETURN_FALSE;
1970+
zend_value_error("delimiter must be a character");
1971+
return;
19721972
} else if (delimiter_str_len > 1) {
19731973
php_error_docref(NULL, E_NOTICE, "delimiter must be a single character");
19741974
}
@@ -1979,8 +1979,8 @@ PHP_FUNCTION(fgetcsv)
19791979

19801980
if (enclosure_str != NULL) {
19811981
if (enclosure_str_len < 1) {
1982-
php_error_docref(NULL, E_WARNING, "enclosure must be a character");
1983-
RETURN_FALSE;
1982+
zend_value_error("enclosure must be a character");
1983+
return;
19841984
} else if (enclosure_str_len > 1) {
19851985
php_error_docref(NULL, E_NOTICE, "enclosure must be a single character");
19861986
}
@@ -2004,8 +2004,8 @@ PHP_FUNCTION(fgetcsv)
20042004
if (len_zv != NULL && Z_TYPE_P(len_zv) != IS_NULL) {
20052005
len = zval_get_long(len_zv);
20062006
if (len < 0) {
2007-
php_error_docref(NULL, E_WARNING, "Length parameter may not be negative");
2008-
RETURN_FALSE;
2007+
zend_value_error("Length parameter may not be negative");
2008+
return;
20092009
} else if (len == 0) {
20102010
len = -1;
20112011
}

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)