diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2020-09-22 14:08:13 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-09-22 15:12:05 +0200 |
commit | de77344de27ae2d913432832b4c4484682d15be1 (patch) | |
tree | 0c7ab2734b90966cfdff676ab51dc09a4761675d /ext/standard/pack.c | |
parent | 048cc9ba78f740e4dcd400f372b9ca2876a26117 (diff) | |
download | php-git-de77344de27ae2d913432832b4c4484682d15be1.tar.gz |
Promote pack/unpack format errors
Errors related to invalid format strings (unlike data mismatch
errors) should throw ValueError.
Closes GH-6185.
Diffstat (limited to 'ext/standard/pack.c')
-rw-r--r-- | ext/standard/pack.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/ext/standard/pack.c b/ext/standard/pack.c index bbae59c6ae..bfa6708f66 100644 --- a/ext/standard/pack.c +++ b/ext/standard/pack.c @@ -47,8 +47,8 @@ if ((a) < 0 || ((INT_MAX - outputpos)/((int)b)) < (a)) { \ efree(formatcodes); \ efree(formatargs); \ - php_error_docref(NULL, E_WARNING, "Type %c: integer overflow in format string", code); \ - RETURN_FALSE; \ + zend_value_error("Type %c: integer overflow in format string", code); \ + RETURN_THROWS(); \ } \ outputpos += (a)*(b); @@ -282,8 +282,8 @@ PHP_FUNCTION(pack) if (currentarg >= num_args) { efree(formatcodes); efree(formatargs); - php_error_docref(NULL, E_WARNING, "Type %c: not enough arguments", code); - RETURN_FALSE; + zend_value_error("Type %c: not enough arguments", code); + RETURN_THROWS(); } if (arg < 0) { @@ -313,8 +313,8 @@ PHP_FUNCTION(pack) #if SIZEOF_ZEND_LONG < 8 efree(formatcodes); efree(formatargs); - php_error_docref(NULL, E_WARNING, "64-bit format codes are not available for 32-bit versions of PHP"); - RETURN_FALSE; + zend_value_error("64-bit format codes are not available for 32-bit versions of PHP"); + RETURN_THROWS(); #endif case 'c': case 'C': @@ -346,16 +346,16 @@ PHP_FUNCTION(pack) too_few_args: efree(formatcodes); efree(formatargs); - php_error_docref(NULL, E_WARNING, "Type %c: too few arguments", code); - RETURN_FALSE; + zend_value_error("Type %c: too few arguments", code); + RETURN_THROWS(); } break; default: efree(formatcodes); efree(formatargs); - php_error_docref(NULL, E_WARNING, "Type %c: unknown format code", code); - RETURN_FALSE; + zend_value_error("Type %c: unknown format code", code); + RETURN_THROWS(); } formatcodes[formatcount] = code; @@ -845,9 +845,9 @@ PHP_FUNCTION(unpack) size = 8; break; #else - php_error_docref(NULL, E_WARNING, "64-bit format codes are not available for 32-bit versions of PHP"); + zend_value_error("64-bit format codes are not available for 32-bit versions of PHP"); zend_array_destroy(Z_ARR_P(return_value)); - RETURN_FALSE; + RETURN_THROWS(); #endif /* Use sizeof(float) bytes of input */ @@ -865,10 +865,9 @@ PHP_FUNCTION(unpack) break; default: - php_error_docref(NULL, E_WARNING, "Invalid format type %c", type); + zend_value_error("Invalid format type %c", type); zend_array_destroy(Z_ARR_P(return_value)); - RETURN_FALSE; - break; + RETURN_THROWS(); } if (size != 0 && size != -1 && size < 0) { |