From b21043f8ac1aa2aeaaadae4153f4e059aedaf988 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 15 Apr 2026 10:02:55 +0900 Subject: Constify pack functions --- pack.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/pack.c b/pack.c index 7e17b016c7..94bb510e0d 100644 --- a/pack.c +++ b/pack.c @@ -62,7 +62,7 @@ is_bigendian(void) { static int init = 0; static int endian_value; - char *p; + const char *p; if (init) return endian_value; init = 1; @@ -771,7 +771,7 @@ pack_pack(rb_execution_context_t *ec, VALUE ary, VALUE fmt, VALUE buffer) /* FALL THROUGH */ case 'p': /* pointer to string */ while (len-- > 0) { - char *t = 0; + const char *t = 0; from = NEXTFROM; if (!NIL_P(from)) { STR_FROM(from); @@ -1001,8 +1001,8 @@ static VALUE pack_unpack_internal(VALUE str, VALUE fmt, enum unpack_mode mode, long offset) { #define hexdigits ruby_hexdigits - char *s, *send; - char *p, *pend; + const char *s, *send; + const char *p, *pend; VALUE ary, associates = Qfalse; long len; AVOID_CC_BUG long tmp_len; @@ -1076,7 +1076,7 @@ pack_unpack_internal(VALUE str, VALUE fmt, enum unpack_mode mode, long offset) if (len > send - s) len = send - s; { long end = len; - char *t = s + len - 1; + const char *t = s + len - 1; while (t >= s) { if (*t != ' ' && *t != '\0') break; @@ -1089,7 +1089,7 @@ pack_unpack_internal(VALUE str, VALUE fmt, enum unpack_mode mode, long offset) case 'Z': { - char *t = s; + const char *t = s; if (len > send-s) len = send-s; while (t < s+len && *t) t++; @@ -1523,7 +1523,8 @@ pack_unpack_internal(VALUE str, VALUE fmt, enum unpack_mode mode, long offset) case 'M': { VALUE buf = rb_str_new(0, send - s); - char *ptr = RSTRING_PTR(buf), *ss = s; + char *ptr = RSTRING_PTR(buf); + const char *ss = s; int csum = 0; int c1, c2; @@ -1578,7 +1579,7 @@ pack_unpack_internal(VALUE str, VALUE fmt, enum unpack_mode mode, long offset) case 'P': if (sizeof(char *) <= (size_t)(send - s)) { VALUE tmp = Qnil; - char *t; + const char *t; UNPACK_FETCH(&t, char *); if (t) { @@ -1601,7 +1602,7 @@ pack_unpack_internal(VALUE str, VALUE fmt, enum unpack_mode mode, long offset) break; else { VALUE tmp = Qnil; - char *t; + const char *t; UNPACK_FETCH(&t, char *); if (t) { @@ -1621,7 +1622,7 @@ pack_unpack_internal(VALUE str, VALUE fmt, enum unpack_mode mode, long offset) if (type == 'r') { pack_flags |= INTEGER_PACK_2COMP; } - char *s0 = s; + const char *s0 = s; while (len > 0 && s < send) { if (*s & 0x80) { s++; @@ -1648,7 +1649,7 @@ pack_unpack_internal(VALUE str, VALUE fmt, enum unpack_mode mode, long offset) case 'w': { - char *s0 = s; + const char *s0 = s; while (len > 0 && s < send) { if (*s & 0x80) { s++; -- cgit v1.2.3