Skip to content

Commit 4a2ae84

Browse files
committed
Add "const". Move constant strings to read-only memory.
1 parent fd0b399 commit 4a2ae84

File tree

14 files changed

+19
-19
lines changed

14 files changed

+19
-19
lines changed

Zend/zend_strtod.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1563,7 +1563,7 @@ hexdig_init(void) /* Use of hexdig_init omitted 20121220 to avoid a */
15631563
htinit(hexdig, USC "ABCDEF", 0x10 + 10);
15641564
}
15651565
#else
1566-
static unsigned char hexdig[256] = {
1566+
static const unsigned char hexdig[256] = {
15671567
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
15681568
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
15691569
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

ext/calendar/calendar.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ enum { CAL_MONTH_GREGORIAN_SHORT, CAL_MONTH_GREGORIAN_LONG,
101101

102102
/* For heb_number_to_chars escape sequences of אבגדהוזחטיכלמנסעפצקרשת
103103
ISO-8859-8 Hebrew alphabet */
104-
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";
104+
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";
105105

106106
#define CAL_JEWISH_ADD_ALAFIM_GERESH 0x2
107107
#define CAL_JEWISH_ADD_ALAFIM 0x4

ext/iconv/iconv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ static php_iconv_err_t _php_iconv_mime_encode(smart_str *pretval, const char *fn
11821182
smart_str_appendc(pretval, *(char *)p);
11831183
char_cnt--;
11841184
} else {
1185-
static char qp_digits[] = "0123456789ABCDEF";
1185+
static const char qp_digits[] = "0123456789ABCDEF";
11861186
smart_str_appendc(pretval, '=');
11871187
smart_str_appendc(pretval, qp_digits[(*p >> 4) & 0x0f]);
11881188
smart_str_appendc(pretval, qp_digits[(*p & 0x0f)]);

ext/session/session.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ static int php_session_decode(zend_string *data) /* {{{ */
260260
* into URLs.
261261
*/
262262

263-
static char hexconvtab[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,-";
263+
static const char hexconvtab[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,-";
264264

265265
static void bin_to_readable(unsigned char *in, size_t inlen, char *out, size_t outlen, char nbits) /* {{{ */
266266
{
@@ -1102,12 +1102,12 @@ typedef struct {
11021102
#define ADD_HEADER(a) sapi_add_header(a, strlen(a), 1);
11031103
#define MAX_STR 512
11041104

1105-
static char *month_names[] = {
1105+
static const char *month_names[] = {
11061106
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
11071107
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
11081108
};
11091109

1110-
static char *week_days[] = {
1110+
static const char *week_days[] = {
11111111
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"
11121112
};
11131113

ext/soap/php_encoding.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ static xmlNodePtr to_xml_base64(encodeTypePtr type, zval *data, int style, xmlNo
940940

941941
static xmlNodePtr to_xml_hexbin(encodeTypePtr type, zval *data, int style, xmlNodePtr parent)
942942
{
943-
static char hexconvtab[] = "0123456789ABCDEF";
943+
static const char hexconvtab[] = "0123456789ABCDEF";
944944
xmlNodePtr ret, text;
945945
unsigned char *str;
946946
zval tmp;

ext/standard/crypt_blowfish.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,10 @@ static BF_ctx BF_init_state = {
356356
}
357357
};
358358

359-
static unsigned char BF_itoa64[64 + 1] =
359+
static const unsigned char BF_itoa64[64 + 1] =
360360
"./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
361361

362-
static unsigned char BF_atoi64[0x60] = {
362+
static const unsigned char BF_atoi64[0x60] = {
363363
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 1,
364364
54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 64, 64, 64, 64, 64,
365365
64, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,

ext/standard/filters.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ typedef struct _php_conv_base64_encode {
208208
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);
209209
static void php_conv_base64_encode_dtor(php_conv_base64_encode *inst);
210210

211-
static unsigned char b64_tbl_enc[256] = {
211+
static const unsigned char b64_tbl_enc[256] = {
212212
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
213213
'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
214214
'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
656656
unsigned int lb_cnt;
657657
unsigned int trail_ws;
658658
int opts;
659-
static char qp_digits[] = "0123456789ABCDEF";
659+
static const char qp_digits[] = "0123456789ABCDEF";
660660

661661
line_ccnt = inst->line_ccnt;
662662
opts = inst->opts;

ext/standard/math.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ PHPAPI void _php_math_basetozval(zend_string *str, int base, zval *ret)
797797
*/
798798
PHPAPI zend_string * _php_math_longtobase(zend_long arg, int base)
799799
{
800-
static char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
800+
static const char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
801801
char buf[(sizeof(zend_ulong) << 3) + 1];
802802
char *ptr, *end;
803803
zend_ulong value;
@@ -828,7 +828,7 @@ PHPAPI zend_string * _php_math_longtobase(zend_long arg, int base)
828828
*/
829829
PHPAPI zend_string * _php_math_zvaltobase(zval *arg, int base)
830830
{
831-
static char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
831+
static const char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
832832

833833
if ((Z_TYPE_P(arg) != IS_LONG && Z_TYPE_P(arg) != IS_DOUBLE) || base < 2 || base > 36) {
834834
return ZSTR_EMPTY_ALLOC();

ext/standard/php_crypt_r.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void _crypt_extended_init_r(void)
8383
#define MD5_MAGIC "$1$"
8484
#define MD5_MAGIC_LEN 3
8585

86-
static unsigned char itoa64[] = /* 0 ... 63 => ascii - 64 */
86+
static const unsigned char itoa64[] = /* 0 ... 63 => ascii - 64 */
8787
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
8888

8989
/* Convert a 16/32 bit integer to Base64 string representation */

ext/standard/soundex.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ PHP_FUNCTION(soundex)
2828
size_t i, _small, str_len, code, last;
2929
char soundex[4 + 1];
3030

31-
static char soundex_table[26] =
31+
static const char soundex_table[26] =
3232
{0, /* A */
3333
'1', /* B */
3434
'2', /* C */

ext/standard/string.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void register_string_constants(INIT_FUNC_ARGS)
8888
int php_tag_find(char *tag, size_t len, const char *set);
8989

9090
/* this is read-only, so it's ok */
91-
ZEND_SET_ALIGNED(16, static char hexconvtab[]) = "0123456789abcdef";
91+
ZEND_SET_ALIGNED(16, static const char hexconvtab[]) = "0123456789abcdef";
9292

9393
/* localeconv mutex */
9494
#ifdef ZTS

ext/standard/url.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ static int php_htoi(char *s)
442442
For added safety, we only leave -_. unencoded.
443443
*/
444444

445-
static unsigned char hexchars[] = "0123456789ABCDEF";
445+
static const unsigned char hexchars[] = "0123456789ABCDEF";
446446

447447
static zend_always_inline zend_string *php_url_encode_impl(const char *s, size_t len, zend_bool raw) /* {{{ */ {
448448
register unsigned char c;

main/strlcat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
*/
4949

5050
#if defined(LIBC_SCCS) && !defined(lint)
51-
static char *rcsid = "$OpenBSD: strlcat.c,v 1.17 2016/10/14 18:19:04 dtucker Exp $";
51+
static const char *rcsid = "$OpenBSD: strlcat.c,v 1.17 2016/10/14 18:19:04 dtucker Exp $";
5252
#endif /* LIBC_SCCS and not lint */
5353

5454
#include <sys/types.h>

main/strlcpy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
*/
4949

5050
#if defined(LIBC_SCCS) && !defined(lint)
51-
static char *rcsid = "$OpenBSD: strlcpy.c,v 1.15 2016/10/16 17:37:39 dtucker Exp $";
51+
static const char *rcsid = "$OpenBSD: strlcpy.c,v 1.15 2016/10/16 17:37:39 dtucker Exp $";
5252
#endif /* LIBC_SCCS and not lint */
5353

5454
#include <sys/types.h>

0 commit comments

Comments
 (0)