diff --git a/ext/standard/array.c b/ext/standard/array.c index a2fef8b145283..ca217179bdc7d 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -445,7 +445,6 @@ static bucket_compare_func_t php_get_data_compare_func(zend_long sort_type, int } else { return php_array_data_compare_numeric; } - break; case PHP_SORT_STRING: if (sort_type & PHP_SORT_FLAG_CASE) { @@ -461,7 +460,6 @@ static bucket_compare_func_t php_get_data_compare_func(zend_long sort_type, int return php_array_data_compare_string; } } - break; case PHP_SORT_NATURAL: if (sort_type & PHP_SORT_FLAG_CASE) { @@ -477,7 +475,6 @@ static bucket_compare_func_t php_get_data_compare_func(zend_long sort_type, int return php_array_natural_compare; } } - break; case PHP_SORT_LOCALE_STRING: if (reverse) { @@ -485,7 +482,6 @@ static bucket_compare_func_t php_get_data_compare_func(zend_long sort_type, int } else { return php_array_data_compare_string_locale; } - break; case PHP_SORT_REGULAR: default: @@ -494,9 +490,8 @@ static bucket_compare_func_t php_get_data_compare_func(zend_long sort_type, int } else { return php_array_data_compare; } - break; } - return NULL; + ZEND_UNREACHABLE(); } /* }}} */ @@ -509,7 +504,6 @@ static bucket_compare_func_t php_get_data_compare_func_unstable(zend_long sort_t } else { return php_array_data_compare_numeric_unstable; } - break; case PHP_SORT_STRING: if (sort_type & PHP_SORT_FLAG_CASE) { @@ -525,7 +519,6 @@ static bucket_compare_func_t php_get_data_compare_func_unstable(zend_long sort_t return php_array_data_compare_string_unstable; } } - break; case PHP_SORT_NATURAL: if (sort_type & PHP_SORT_FLAG_CASE) { @@ -541,7 +534,6 @@ static bucket_compare_func_t php_get_data_compare_func_unstable(zend_long sort_t return php_array_natural_compare_unstable; } } - break; case PHP_SORT_LOCALE_STRING: if (reverse) { @@ -549,7 +541,6 @@ static bucket_compare_func_t php_get_data_compare_func_unstable(zend_long sort_t } else { return php_array_data_compare_string_locale_unstable; } - break; case PHP_SORT_REGULAR: default: @@ -558,9 +549,8 @@ static bucket_compare_func_t php_get_data_compare_func_unstable(zend_long sort_t } else { return php_array_data_compare_unstable; } - break; } - return NULL; + ZEND_UNREACHABLE(); } /* }}} */ diff --git a/ext/standard/exec.c b/ext/standard/exec.c index 8ebca90bce396..3807c0206358a 100644 --- a/ext/standard/exec.c +++ b/ext/standard/exec.c @@ -119,9 +119,6 @@ PHPAPI int php_exec(int type, const char *cmd, zval *array, zval *return_value) size_t buflen, bufl = 0; #if PHP_SIGCHILD void (*sig_handler)() = NULL; -#endif - -#if PHP_SIGCHILD sig_handler = signal (SIGCHLD, SIG_DFL); #endif @@ -272,8 +269,7 @@ PHP_FUNCTION(passthru) Escape all chars that could possibly be used to break out of a shell command - This function emalloc's a string and returns the pointer. - Remember to efree it when done with it. + This function allocates a new zend_string, remember to free it when done. *NOT* safe for binary strings */ diff --git a/ext/standard/html.c b/ext/standard/html.c index 92cee224e068b..0c6231d590d88 100644 --- a/ext/standard/html.c +++ b/ext/standard/html.c @@ -451,7 +451,7 @@ static inline unsigned char unimap_bsearch(const uni_to_enc *table, unsigned cod /* }}} */ /* {{{ map_from_unicode */ -static inline int map_from_unicode(unsigned code, enum entity_charset charset, unsigned *res) +static inline zend_result map_from_unicode(unsigned code, enum entity_charset charset, unsigned *res) { unsigned char found; const uni_to_enc *table; @@ -667,7 +667,7 @@ static inline int numeric_entity_is_allowed(unsigned uni_cp, int document_type) * On input, *buf should point to the first character after # and on output, it's the last * byte read, no matter if there was success or insuccess. */ -static inline int process_numeric_entity(const char **buf, unsigned *code_point) +static inline zend_result process_numeric_entity(const char **buf, unsigned *code_point) { zend_long code_l; int hexadecimal = (**buf == 'x' || **buf == 'X'); /* TODO: XML apparently disallows "X" */ @@ -703,7 +703,7 @@ static inline int process_numeric_entity(const char **buf, unsigned *code_point) /* }}} */ /* {{{ process_named_entity */ -static inline int process_named_entity_html(const char **buf, const char **start, size_t *length) +static inline zend_result process_named_entity_html(const char **buf, const char **start, size_t *length) { *start = *buf; @@ -732,7 +732,7 @@ static inline int process_named_entity_html(const char **buf, const char **start /* }}} */ /* {{{ resolve_named_entity_html */ -static int resolve_named_entity_html(const char *start, size_t length, const entity_ht *ht, unsigned *uni_cp1, unsigned *uni_cp2) +static zend_result resolve_named_entity_html(const char *start, size_t length, const entity_ht *ht, unsigned *uni_cp1, unsigned *uni_cp2) { const entity_cp_map *s; zend_ulong hash = zend_inline_hash_func(start, length); @@ -780,9 +780,7 @@ static inline size_t write_octet_sequence(unsigned char *buf, enum entity_charse #if 0 return php_mb2_int_to_char(buf, code); #else -#if ZEND_DEBUG - assert(code <= 0xFFU); -#endif + ZEND_ASSERT(code <= 0xFFU); *buf = code; return 1; #endif @@ -791,9 +789,7 @@ static inline size_t write_octet_sequence(unsigned char *buf, enum entity_charse #if 0 /* idem */ return php_mb2_int_to_char(buf, code); #else -#if ZEND_DEBUG - assert(code <= 0xFFU); -#endif + ZEND_ASSERT(code <= 0xFFU); *buf = code; return 1; #endif diff --git a/ext/standard/iptc.c b/ext/standard/iptc.c index e4dd38637570a..84d8dd450aacb 100644 --- a/ext/standard/iptc.c +++ b/ext/standard/iptc.c @@ -73,14 +73,12 @@ #define M_APP15 0xef /* {{{ php_iptc_put1 */ -static int php_iptc_put1(FILE *fp, int spool, unsigned char c, unsigned char **spoolbuf) +static void php_iptc_put1(FILE *fp, int spool, unsigned char c, unsigned char **spoolbuf) { if (spool > 0) PUTC(c); if (spoolbuf) *(*spoolbuf)++ = c; - - return c; } /* }}} */ @@ -106,32 +104,28 @@ static int php_iptc_get1(FILE *fp, int spool, unsigned char **spoolbuf) /* }}} */ /* {{{ php_iptc_read_remaining */ -static int php_iptc_read_remaining(FILE *fp, int spool, unsigned char **spoolbuf) +static void php_iptc_read_remaining(FILE *fp, int spool, unsigned char **spoolbuf) { while (php_iptc_get1(fp, spool, spoolbuf) != EOF) continue; - - return M_EOI; } /* }}} */ /* {{{ php_iptc_skip_variable */ -static int php_iptc_skip_variable(FILE *fp, int spool, unsigned char **spoolbuf) +static void php_iptc_skip_variable(FILE *fp, int spool, unsigned char **spoolbuf) { unsigned int length; int c1, c2; - if ((c1 = php_iptc_get1(fp, spool, spoolbuf)) == EOF) return M_EOI; + if ((c1 = php_iptc_get1(fp, spool, spoolbuf)) == EOF) return; - if ((c2 = php_iptc_get1(fp, spool, spoolbuf)) == EOF) return M_EOI; + if ((c2 = php_iptc_get1(fp, spool, spoolbuf)) == EOF) return; length = (((unsigned char) c1) << 8) + ((unsigned char) c2); length -= 2; while (length--) - if (php_iptc_get1(fp, spool, spoolbuf) == EOF) return M_EOI; - - return 0; + if (php_iptc_get1(fp, spool, spoolbuf) == EOF) return; } /* }}} */ diff --git a/ext/standard/mail.c b/ext/standard/mail.c index 35c23a0be76c0..f8c2243bd5952 100644 --- a/ext/standard/mail.c +++ b/ext/standard/mail.c @@ -109,7 +109,7 @@ static php_mail_header_value_error_type php_mail_build_headers_check_field_value } -static bool php_mail_build_headers_check_field_name(zend_string *key) +static zend_result php_mail_build_headers_check_field_name(zend_string *key) { size_t len = 0; @@ -151,10 +151,8 @@ static void php_mail_build_headers_elem(smart_str *s, zend_string *key, zval *va case CONTAINS_NULL: zend_value_error("Header \"%s\" contains NULL character that is not allowed in the header", ZSTR_VAL(key)); return; - default: - // fallback - zend_value_error("Header \"%s\" has invalid format, or contains invalid characters", ZSTR_VAL(key)); - return; + // All cases of php_mail_header_value_error_type enum handled + EMPTY_SWITCH_DEFAULT_CASE(); } smart_str_append(s, key); smart_str_appendl(s, ": ", 2); @@ -616,7 +614,7 @@ PHPAPI bool php_mail(const char *to, const char *subject, const char *message, c MAIL_RET(false); } - MAIL_RET(true); /* never reached */ + ZEND_UNREACHABLE(); } /* }}} */ diff --git a/ext/standard/math.c b/ext/standard/math.c index 142d473864f75..796849a60c695 100644 --- a/ext/standard/math.c +++ b/ext/standard/math.c @@ -389,77 +389,38 @@ PHP_FUNCTION(round) } /* }}} */ -/* {{{ Returns the sine of the number in radians */ -PHP_FUNCTION(sin) -{ - double num; - - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_DOUBLE(num) - ZEND_PARSE_PARAMETERS_END(); - RETURN_DOUBLE(sin(num)); -} -/* }}} */ - -/* {{{ Returns the cosine of the number in radians */ -PHP_FUNCTION(cos) -{ - double num; - - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_DOUBLE(num) - ZEND_PARSE_PARAMETERS_END(); - RETURN_DOUBLE(cos(num)); -} -/* }}} */ - -/* {{{ Returns the tangent of the number in radians */ -PHP_FUNCTION(tan) -{ - double num; +// Lots of the PHP function are just wrappers around a C math function; if they +// - are named the same as the C implementatino +// - take a single parameter, a double +// - return a double +// then they can use this macro for de-duplication +#define MATH_PHP_FUNCTION_WRAPPER(name) \ + PHP_FUNCTION(name) \ + { \ + double num; \ + ZEND_PARSE_PARAMETERS_START(1, 1) \ + Z_PARAM_DOUBLE(num) \ + ZEND_PARSE_PARAMETERS_END(); \ + RETURN_DOUBLE(name(num)); \ + } - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_DOUBLE(num) - ZEND_PARSE_PARAMETERS_END(); - RETURN_DOUBLE(tan(num)); -} -/* }}} */ +/* Returns the sine of the number in radians */ +MATH_PHP_FUNCTION_WRAPPER(sin) -/* {{{ Returns the arc sine of the number in radians */ -PHP_FUNCTION(asin) -{ - double num; +/* Returns the cosine of the number in radians */ +MATH_PHP_FUNCTION_WRAPPER(cos) - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_DOUBLE(num) - ZEND_PARSE_PARAMETERS_END(); - RETURN_DOUBLE(asin(num)); -} -/* }}} */ - -/* {{{ Return the arc cosine of the number in radians */ -PHP_FUNCTION(acos) -{ - double num; +/* Returns the tangent of the number in radians */ +MATH_PHP_FUNCTION_WRAPPER(tan) - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_DOUBLE(num) - ZEND_PARSE_PARAMETERS_END(); - RETURN_DOUBLE(acos(num)); -} -/* }}} */ +/* Returns the arc sine of the number in radians */ +MATH_PHP_FUNCTION_WRAPPER(asin) -/* {{{ Returns the arc tangent of the number in radians */ -PHP_FUNCTION(atan) -{ - double num; +/* Return the arc cosine of the number in radians */ +MATH_PHP_FUNCTION_WRAPPER(acos) - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_DOUBLE(num) - ZEND_PARSE_PARAMETERS_END(); - RETURN_DOUBLE(atan(num)); -} -/* }}} */ +/* Returns the arc tangent of the number in radians */ +MATH_PHP_FUNCTION_WRAPPER(atan) /* {{{ Returns the arc tangent of y/x, with the resulting quadrant determined by the signs of y and x */ PHP_FUNCTION(atan2) @@ -474,77 +435,23 @@ PHP_FUNCTION(atan2) } /* }}} */ -/* {{{ Returns the hyperbolic sine of the number, defined as (exp(number) - exp(-number))/2 */ -PHP_FUNCTION(sinh) -{ - double num; +/* Returns the hyperbolic sine of the number, defined as (exp(number) - exp(-number))/2 */ +MATH_PHP_FUNCTION_WRAPPER(sinh) - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_DOUBLE(num) - ZEND_PARSE_PARAMETERS_END(); - RETURN_DOUBLE(sinh(num)); -} -/* }}} */ +/* Returns the hyperbolic cosine of the number, defined as (exp(number) + exp(-number))/2 */ +MATH_PHP_FUNCTION_WRAPPER(cosh) -/* {{{ Returns the hyperbolic cosine of the number, defined as (exp(number) + exp(-number))/2 */ -PHP_FUNCTION(cosh) -{ - double num; +/* Returns the hyperbolic tangent of the number, defined as sinh(number)/cosh(number) */ +MATH_PHP_FUNCTION_WRAPPER(tanh) - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_DOUBLE(num) - ZEND_PARSE_PARAMETERS_END(); - RETURN_DOUBLE(cosh(num)); -} -/* }}} */ +/* Returns the inverse hyperbolic sine of the number, i.e. the value whose hyperbolic sine is number */ +MATH_PHP_FUNCTION_WRAPPER(asinh) -/* {{{ Returns the hyperbolic tangent of the number, defined as sinh(number)/cosh(number) */ -PHP_FUNCTION(tanh) -{ - double num; +/* Returns the inverse hyperbolic cosine of the number, i.e. the value whose hyperbolic cosine is number */ +MATH_PHP_FUNCTION_WRAPPER(acosh) - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_DOUBLE(num) - ZEND_PARSE_PARAMETERS_END(); - RETURN_DOUBLE(tanh(num)); -} -/* }}} */ - -/* {{{ Returns the inverse hyperbolic sine of the number, i.e. the value whose hyperbolic sine is number */ -PHP_FUNCTION(asinh) -{ - double num; - - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_DOUBLE(num) - ZEND_PARSE_PARAMETERS_END(); - RETURN_DOUBLE(asinh(num)); -} -/* }}} */ - -/* {{{ Returns the inverse hyperbolic cosine of the number, i.e. the value whose hyperbolic cosine is number */ -PHP_FUNCTION(acosh) -{ - double num; - - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_DOUBLE(num) - ZEND_PARSE_PARAMETERS_END(); - RETURN_DOUBLE(acosh(num)); -} -/* }}} */ - -/* {{{ Returns the inverse hyperbolic tangent of the number, i.e. the value whose hyperbolic tangent is number */ -PHP_FUNCTION(atanh) -{ - double num; - - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_DOUBLE(num) - ZEND_PARSE_PARAMETERS_END(); - RETURN_DOUBLE(atanh(num)); -} -/* }}} */ +/* Returns the inverse hyperbolic tangent of the number, i.e. the value whose hyperbolic tangent is number */ +MATH_PHP_FUNCTION_WRAPPER(atanh) /* {{{ Returns an approximation of pi */ PHP_FUNCTION(pi) @@ -605,44 +512,14 @@ PHP_FUNCTION(pow) } /* }}} */ -/* {{{ Returns e raised to the power of the number */ -PHP_FUNCTION(exp) -{ - double num; +/* Returns e raised to the power of the number */ +MATH_PHP_FUNCTION_WRAPPER(exp) - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_DOUBLE(num) - ZEND_PARSE_PARAMETERS_END(); +/* Returns exp(number) - 1, computed in a way that accurate even when the value of number is close to zero */ +MATH_PHP_FUNCTION_WRAPPER(expm1) - RETURN_DOUBLE(exp(num)); -} -/* }}} */ - -/* {{{ Returns exp(number) - 1, computed in a way that accurate even when the value of number is close to zero */ -PHP_FUNCTION(expm1) -{ - double num; - - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_DOUBLE(num) - ZEND_PARSE_PARAMETERS_END(); - - RETURN_DOUBLE(expm1(num)); -} -/* }}} */ - -/* {{{ Returns log(1 + number), computed in a way that accurate even when the value of number is close to zero */ -PHP_FUNCTION(log1p) -{ - double num; - - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_DOUBLE(num) - ZEND_PARSE_PARAMETERS_END(); - - RETURN_DOUBLE(log1p(num)); -} -/* }}} */ +/* Returns log(1 + number), computed in a way that accurate even when the value of number is close to zero */ +MATH_PHP_FUNCTION_WRAPPER(log1p) /* {{{ Returns the natural logarithm of the number, or the base log if base is specified */ PHP_FUNCTION(log) @@ -680,31 +557,13 @@ PHP_FUNCTION(log) } /* }}} */ -/* {{{ Returns the base-10 logarithm of the number */ -PHP_FUNCTION(log10) -{ - double num; - - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_DOUBLE(num) - ZEND_PARSE_PARAMETERS_END(); +/* Returns the base-10 logarithm of the number */ +MATH_PHP_FUNCTION_WRAPPER(log10) - RETURN_DOUBLE(log10(num)); -} -/* }}} */ +/* Returns the square root of the number */ +MATH_PHP_FUNCTION_WRAPPER(sqrt) -/* {{{ Returns the square root of the number */ -PHP_FUNCTION(sqrt) -{ - double num; - - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_DOUBLE(num) - ZEND_PARSE_PARAMETERS_END(); - - RETURN_DOUBLE(sqrt(num)); -} -/* }}} */ +#undef MATH_PHP_FUNCTION_WRAPPER /* {{{ Returns sqrt(num1*num1 + num2*num2) */ PHP_FUNCTION(hypot) diff --git a/ext/standard/proc_open.c b/ext/standard/proc_open.c index 20b2ce09fbb41..38264fe291689 100644 --- a/ext/standard/proc_open.c +++ b/ext/standard/proc_open.c @@ -693,11 +693,6 @@ static void init_startup_info(STARTUPINFOW *si, descriptorspec_item *descriptors } } -static void init_process_info(PROCESS_INFORMATION *pi) -{ - memset(&pi, 0, sizeof(pi)); -} - static zend_result convert_command_to_use_shell(wchar_t **cmdw, size_t cmdw_len) { size_t len = sizeof(COMSPEC_NT) + sizeof(" /s /c ") + cmdw_len + 3; @@ -1270,7 +1265,7 @@ PHP_FUNCTION(proc_open) } init_startup_info(&si, descriptors, ndesc); - init_process_info(&pi); + memset(&pi, 0, sizeof(pi)); if (suppress_errors) { old_error_mode = SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOGPFAULTERRORBOX);