]> granicus.if.org Git - php/commitdiff
Add "const". Move constant strings to read-only memory.
authorDmitry Stogov <dmitry@zend.com>
Mon, 7 Sep 2020 18:35:48 +0000 (21:35 +0300)
committerDmitry Stogov <dmitry@zend.com>
Mon, 7 Sep 2020 18:35:48 +0000 (21:35 +0300)
14 files changed:
Zend/zend_strtod.c
ext/calendar/calendar.c
ext/iconv/iconv.c
ext/session/session.c
ext/soap/php_encoding.c
ext/standard/crypt_blowfish.c
ext/standard/filters.c
ext/standard/math.c
ext/standard/php_crypt_r.c
ext/standard/soundex.c
ext/standard/string.c
ext/standard/url.c
main/strlcat.c
main/strlcpy.c

index 2228e2262cf1f0f37ea25b82504323a9abcd9f37..e88fbd001fef6422e522fb7167f5d6b79641fbf1 100644 (file)
@@ -1563,7 +1563,7 @@ hexdig_init(void) /* Use of hexdig_init omitted 20121220 to avoid a */
        htinit(hexdig, USC "ABCDEF", 0x10 + 10);
        }
 #else
-static unsigned char hexdig[256] = {
+static const unsigned char hexdig[256] = {
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
index 4de31ccf7792ada8c1179f7d89ea1cbdc09ec100..5dd4f1ef49eb57cf3241860ccc3e617dc0057269 100644 (file)
@@ -101,7 +101,7 @@ enum { CAL_MONTH_GREGORIAN_SHORT, CAL_MONTH_GREGORIAN_LONG,
 
 /* For heb_number_to_chars escape sequences of אבגדהוזחטיכלמנסעפצקרשת
    ISO-8859-8 Hebrew alphabet */
-static char alef_bet[25] = "0\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEB\xEC\xEE\xF0\xF1\xF2\xF4\xF6\xF7\xF8\xF9\xFA";
+static const char alef_bet[25] = "0\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEB\xEC\xEE\xF0\xF1\xF2\xF4\xF6\xF7\xF8\xF9\xFA";
 
 #define CAL_JEWISH_ADD_ALAFIM_GERESH 0x2
 #define CAL_JEWISH_ADD_ALAFIM 0x4
index 92adc97b123b4a0b367d5f565be838d42368a26b..89ae1b43a4a77d0b865f4252e12fe68d93fb4b5a 100644 (file)
@@ -1182,7 +1182,7 @@ static php_iconv_err_t _php_iconv_mime_encode(smart_str *pretval, const char *fn
                                                smart_str_appendc(pretval, *(char *)p);
                                                char_cnt--;
                                        } else {
-                                               static char qp_digits[] = "0123456789ABCDEF";
+                                               static const char qp_digits[] = "0123456789ABCDEF";
                                                smart_str_appendc(pretval, '=');
                                                smart_str_appendc(pretval, qp_digits[(*p >> 4) & 0x0f]);
                                                smart_str_appendc(pretval, qp_digits[(*p & 0x0f)]);
index 658b7daf9b46b483d00b06e3a4c09cba6f9e6389..9336c05be816c67160575ab601cf3007f688582b 100644 (file)
@@ -260,7 +260,7 @@ static int php_session_decode(zend_string *data) /* {{{ */
  * into URLs.
  */
 
-static char hexconvtab[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,-";
+static const char hexconvtab[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,-";
 
 static void bin_to_readable(unsigned char *in, size_t inlen, char *out, size_t outlen, char nbits) /* {{{ */
 {
@@ -1102,12 +1102,12 @@ typedef struct {
 #define ADD_HEADER(a) sapi_add_header(a, strlen(a), 1);
 #define MAX_STR 512
 
-static char *month_names[] = {
+static const char *month_names[] = {
        "Jan", "Feb", "Mar", "Apr", "May", "Jun",
        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
 };
 
-static char *week_days[] = {
+static const char *week_days[] = {
        "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"
 };
 
index affc771b0b07dc91067fe476e75603723b37fddb..b3dd853298fbf38bf5e1a13c79279c22f00e9b2a 100644 (file)
@@ -940,7 +940,7 @@ static xmlNodePtr to_xml_base64(encodeTypePtr type, zval *data, int style, xmlNo
 
 static xmlNodePtr to_xml_hexbin(encodeTypePtr type, zval *data, int style, xmlNodePtr parent)
 {
-       static char hexconvtab[] = "0123456789ABCDEF";
+       static const char hexconvtab[] = "0123456789ABCDEF";
        xmlNodePtr ret, text;
        unsigned char *str;
        zval tmp;
index 1f20debf288eb2fa960a3e544c9347caa49c1c90..3806a290aee407420ac7f216009f9f7333b66042 100644 (file)
@@ -356,10 +356,10 @@ static BF_ctx BF_init_state = {
        }
 };
 
-static unsigned char BF_itoa64[64 + 1] =
+static const unsigned char BF_itoa64[64 + 1] =
        "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
 
-static unsigned char BF_atoi64[0x60] = {
+static const unsigned char BF_atoi64[0x60] = {
        64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 1,
        54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 64, 64, 64, 64, 64,
        64, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
index 2d5d0dd150432d63ebff07083e7a9648bcec6d07..d5e65644439067b9172cb830f20bf0eff94561e0 100644 (file)
@@ -208,7 +208,7 @@ typedef struct _php_conv_base64_encode {
 static php_conv_err_t php_conv_base64_encode_convert(php_conv_base64_encode *inst, const char **in_p, size_t *in_left, char **out_p, size_t *out_left);
 static void php_conv_base64_encode_dtor(php_conv_base64_encode *inst);
 
-static unsigned char b64_tbl_enc[256] = {
+static const unsigned char b64_tbl_enc[256] = {
        'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
        'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
        'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
@@ -656,7 +656,7 @@ static php_conv_err_t php_conv_qprint_encode_convert(php_conv_qprint_encode *ins
        unsigned int lb_cnt;
        unsigned int trail_ws;
        int opts;
-       static char qp_digits[] = "0123456789ABCDEF";
+       static const char qp_digits[] = "0123456789ABCDEF";
 
        line_ccnt = inst->line_ccnt;
        opts = inst->opts;
index c5e0234fdeefe380542e2c9aa601013cb02e56cb..2aedcc259d2cc8a11b315592f1bc520d714af893 100644 (file)
@@ -797,7 +797,7 @@ PHPAPI void _php_math_basetozval(zend_string *str, int base, zval *ret)
  */
 PHPAPI zend_string * _php_math_longtobase(zend_long arg, int base)
 {
-       static char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
+       static const char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
        char buf[(sizeof(zend_ulong) << 3) + 1];
        char *ptr, *end;
        zend_ulong value;
@@ -828,7 +828,7 @@ PHPAPI zend_string * _php_math_longtobase(zend_long arg, int base)
  */
 PHPAPI zend_string * _php_math_zvaltobase(zval *arg, int base)
 {
-       static char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
+       static const char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
 
        if ((Z_TYPE_P(arg) != IS_LONG && Z_TYPE_P(arg) != IS_DOUBLE) || base < 2 || base > 36) {
                return ZSTR_EMPTY_ALLOC();
index 1e55f5f9b5f79af80d6e0541955848fa13ab203c..f8dffe9cc52e501f494b81c9ba12489f2e7669d5 100644 (file)
@@ -83,7 +83,7 @@ void _crypt_extended_init_r(void)
 #define MD5_MAGIC "$1$"
 #define MD5_MAGIC_LEN 3
 
-static unsigned char itoa64[] =                /* 0 ... 63 => ascii - 64 */
+static const unsigned char itoa64[] =          /* 0 ... 63 => ascii - 64 */
        "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
 
 /* Convert a 16/32 bit integer to Base64 string representation */
index afd16142e30d33008999c52c538a8732484ad78d..5342139f98d0001c1af756ff8f4fff074a364d87 100644 (file)
@@ -28,7 +28,7 @@ PHP_FUNCTION(soundex)
        size_t  i, _small, str_len, code, last;
        char    soundex[4 + 1];
 
-       static char soundex_table[26] =
+       static const char soundex_table[26] =
        {0,                                                     /* A */
         '1',                                           /* B */
         '2',                                           /* C */
index 915b6cff5386b81d4bbed018c76f62f03664e72e..a50ba01fd6fce2fe762e9f86667649b6d69f1458 100644 (file)
@@ -88,7 +88,7 @@ void register_string_constants(INIT_FUNC_ARGS)
 int php_tag_find(char *tag, size_t len, const char *set);
 
 /* this is read-only, so it's ok */
-ZEND_SET_ALIGNED(16, static char hexconvtab[]) = "0123456789abcdef";
+ZEND_SET_ALIGNED(16, static const char hexconvtab[]) = "0123456789abcdef";
 
 /* localeconv mutex */
 #ifdef ZTS
index f710b2fe8a64326d165573fa0a8f1a5b73e786c0..1d4869ecd48e5e8228468ba8880ff11bc3157fe2 100644 (file)
@@ -442,7 +442,7 @@ static int php_htoi(char *s)
    For added safety, we only leave -_. unencoded.
  */
 
-static unsigned char hexchars[] = "0123456789ABCDEF";
+static const unsigned char hexchars[] = "0123456789ABCDEF";
 
 static zend_always_inline zend_string *php_url_encode_impl(const char *s, size_t len, zend_bool raw) /* {{{ */ {
        register unsigned char c;
index 3c18360e962c50ab5ac9a4cddd6578f248e37533..5556bc31ae94bd095e3d4c06e94ddec64e196fd2 100644 (file)
@@ -48,7 +48,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: strlcat.c,v 1.17 2016/10/14 18:19:04 dtucker Exp $";
+static const char *rcsid = "$OpenBSD: strlcat.c,v 1.17 2016/10/14 18:19:04 dtucker Exp $";
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/types.h>
index 55959b2f3a2b32fc0b44b79edb410745a410e765..ef397e267ed70b3158867bb20d8f867500f757b7 100644 (file)
@@ -48,7 +48,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: strlcpy.c,v 1.15 2016/10/16 17:37:39 dtucker Exp $";
+static const char *rcsid = "$OpenBSD: strlcpy.c,v 1.15 2016/10/16 17:37:39 dtucker Exp $";
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/types.h>