From: Nuno Lopes Date: Sat, 22 Jul 2006 12:49:36 +0000 (+0000) Subject: use const keyword where possible X-Git-Tag: php-5.2.0RC1~26 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=083b13335ebcfb31dd807b2ab4d1a147023001b5;p=php use const keyword where possible --- diff --git a/ext/filter/filter.c b/ext/filter/filter.c index 6c975263d3..93be9af9a0 100644 --- a/ext/filter/filter.c +++ b/ext/filter/filter.c @@ -31,7 +31,7 @@ ZEND_DECLARE_MODULE_GLOBALS(filter) #include "filter_private.h" typedef struct filter_list_entry { - char *name; + const char *name; int id; void (*function)(PHP_INPUT_FILTER_PARAM_DECL); } filter_list_entry; diff --git a/ext/filter/logical_filters.c b/ext/filter/logical_filters.c index 2631a8ced7..4887c64d70 100644 --- a/ext/filter/logical_filters.c +++ b/ext/filter/logical_filters.c @@ -515,7 +515,7 @@ void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ void php_filter_validate_email(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ { /* From http://cvs.php.net/co.php/pear/HTML_QuickForm/QuickForm/Rule/Email.php?r=1.4 */ - const char *regexp = "/^((\\\"[^\\\"\\f\\n\\r\\t\\v\\b]+\\\")|([\\w\\!\\#\\$\\%\\&\\'\\*\\+\\-\\~\\/\\^\\`\\|\\{\\}]+(\\.[\\w\\!\\#\\$\\%\\&\\'\\*\\+\\-\\~\\/\\^\\`\\|\\{\\}]+)*))@((\\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\\-])+\\.)+[A-Za-z\\-]+))$/"; + const char regexp[] = "/^((\\\"[^\\\"\\f\\n\\r\\t\\v\\b]+\\\")|([\\w\\!\\#\\$\\%\\&\\'\\*\\+\\-\\~\\/\\^\\`\\|\\{\\}]+(\\.[\\w\\!\\#\\$\\%\\&\\'\\*\\+\\-\\~\\/\\^\\`\\|\\{\\}]+)*))@((\\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\\-])+\\.)+[A-Za-z\\-]+))$/"; pcre *re = NULL; pcre_extra *pcre_extra = NULL; diff --git a/ext/filter/sanitizing_filters.c b/ext/filter/sanitizing_filters.c index d295b94ca2..50341f1325 100644 --- a/ext/filter/sanitizing_filters.c +++ b/ext/filter/sanitizing_filters.c @@ -27,7 +27,7 @@ typedef unsigned long filter_map[256]; /* }}} */ /* {{{ HELPER FUNCTIONS */ -static void php_filter_encode_html(zval *value, char* chars, int encode_nul) +static void php_filter_encode_html(zval *value, const char* chars, int encode_nul) { register int x, y; smart_str str = {0}; @@ -79,7 +79,7 @@ static void php_filter_encode_html_high_low(zval *value, long flags) Z_STRLEN_P(value) = str.len; } -static unsigned char hexchars[] = "0123456789ABCDEF"; +static const unsigned char hexchars[] = "0123456789ABCDEF"; #define LOWALPHA "abcdefghijklmnopqrstuvwxyz" #define HIALPHA "ABCDEFGHIJKLMNOPQRSTUVWXYZ" @@ -87,7 +87,7 @@ static unsigned char hexchars[] = "0123456789ABCDEF"; #define DEFAULT_URL_ENCODE LOWALPHA HIALPHA DIGIT "-._" -static void php_filter_encode_url(zval *value, char* chars, int high, int low, int encode_nul) +static void php_filter_encode_url(zval *value, const char* chars, int high, int low, int encode_nul) { register int x, y; unsigned char *str; @@ -145,11 +145,11 @@ static void filter_map_init(filter_map *map) memset(map, 0, sizeof(filter_map)); } -static void filter_map_update(filter_map *map, int flag, unsigned char *allowed_list) +static void filter_map_update(filter_map *map, int flag, const unsigned char *allowed_list) { int l, i; - l = strlen((char*)allowed_list); + l = strlen((const char*)allowed_list); for (i = 0; i < l; ++i) { (*map)[allowed_list[i]] = flag; } @@ -255,7 +255,7 @@ void php_filter_unsafe_raw(PHP_INPUT_FILTER_PARAM_DECL) void php_filter_email(PHP_INPUT_FILTER_PARAM_DECL) { /* Check section 6 of rfc 822 http://www.faqs.org/rfcs/rfc822.html */ - unsigned char allowed_list[] = LOWALPHA HIALPHA DIGIT "!#$%&'*+-/=?^_`{|}~@.[]"; + const unsigned char allowed_list[] = LOWALPHA HIALPHA DIGIT "!#$%&'*+-/=?^_`{|}~@.[]"; filter_map map; filter_map_init(&map); @@ -269,7 +269,7 @@ void php_filter_url(PHP_INPUT_FILTER_PARAM_DECL) { /* Strip all chars not part of section 5 of * http://www.faqs.org/rfcs/rfc1738.html */ - unsigned char allowed_list[] = LOWALPHA HIALPHA DIGIT SAFE EXTRA NATIONAL PUNCTUATION RESERVED; + const unsigned char allowed_list[] = LOWALPHA HIALPHA DIGIT SAFE EXTRA NATIONAL PUNCTUATION RESERVED; filter_map map; filter_map_init(&map); @@ -282,7 +282,7 @@ void php_filter_url(PHP_INPUT_FILTER_PARAM_DECL) void php_filter_number_int(PHP_INPUT_FILTER_PARAM_DECL) { /* strip everything [^0-9+-] */ - unsigned char allowed_list[] = "+-" DIGIT; + const unsigned char allowed_list[] = "+-" DIGIT; filter_map map; filter_map_init(&map); @@ -295,7 +295,7 @@ void php_filter_number_int(PHP_INPUT_FILTER_PARAM_DECL) void php_filter_number_float(PHP_INPUT_FILTER_PARAM_DECL) { /* strip everything [^0-9+-] */ - unsigned char allowed_list[] = "+-" DIGIT; + const unsigned char allowed_list[] = "+-" DIGIT; filter_map map; filter_map_init(&map);