Skip to content

Some miscellaneous ext/standard cleanup #15953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the point of this?


case PHP_SORT_STRING:
if (sort_type & PHP_SORT_FLAG_CASE) {
Expand All @@ -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) {
Expand All @@ -477,15 +475,13 @@ 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) {
return php_array_reverse_data_compare_string_locale;
} else {
return php_array_data_compare_string_locale;
}
break;

case PHP_SORT_REGULAR:
default:
Expand All @@ -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();
}
/* }}} */

Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -541,15 +534,13 @@ 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) {
return php_array_reverse_data_compare_string_locale_unstable;
} else {
return php_array_data_compare_string_locale_unstable;
}
break;

case PHP_SORT_REGULAR:
default:
Expand All @@ -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();
}
/* }}} */

Expand Down
6 changes: 1 addition & 5 deletions ext/standard/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well technically alloc can be also persistent, emalloc and efree are not (unless zend alloc disabled) so it might be a bit less clear now. Not a big deal as we usually don't have any comments.


*NOT* safe for binary strings
*/
Expand Down
16 changes: 6 additions & 10 deletions ext/standard/html.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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" */
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
18 changes: 6 additions & 12 deletions ext/standard/iptc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
/* }}} */

Expand All @@ -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;
}
/* }}} */

Expand Down
10 changes: 4 additions & 6 deletions ext/standard/mail.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
/* }}} */

Expand Down
Loading
Loading