From 9cbe880bef86d6a2a18d2671579498840ffb8162 Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Tue, 7 Jun 2005 12:08:58 +0000 Subject: [PATCH] The FBM compile code is mutable, because it's permissible to FBM compile a read-only value. p4raw-id: //depot/perl@24725 --- util.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/util.c b/util.c index cb3774e..13379d5 100644 --- a/util.c +++ b/util.c @@ -366,7 +366,7 @@ Analyses the string in order to make fast searches on it using fbm_instr() void Perl_fbm_compile(pTHX_ SV *sv, U32 flags) { - register U8 *s; + const register U8 *s; register U8 *table; register U32 i; STRLEN len; @@ -379,20 +379,20 @@ Perl_fbm_compile(pTHX_ SV *sv, U32 flags) if (mg && mg->mg_len >= 0) mg->mg_len++; } - s = (U8*)SvPV_force(sv, len); + s = (U8*)SvPV_force_mutable(sv, len); SvUPGRADE(sv, SVt_PVBM); if (len == 0) /* TAIL might be on a zero-length string. */ return; if (len > 2) { U8 mlen; - unsigned char *sb; + const unsigned char *sb; if (len > 255) mlen = 255; else mlen = (U8)len; Sv_Grow(sv, len + 256 + FBM_TABLE_OFFSET); - table = (unsigned char*)(SvPVX(sv) + len + FBM_TABLE_OFFSET); + table = (unsigned char*)(SvPVX_mutable(sv) + len + FBM_TABLE_OFFSET); s = table - 1 - FBM_TABLE_OFFSET; /* last char */ memset((void*)table, mlen, 256); table[-1] = (U8)flags; @@ -407,7 +407,7 @@ Perl_fbm_compile(pTHX_ SV *sv, U32 flags) sv_magic(sv, Nullsv, PERL_MAGIC_bm, Nullch, 0); /* deep magic */ SvVALID_on(sv); - s = (unsigned char*)(SvPVX(sv)); /* deeper magic */ + s = (const unsigned char*)(SvPVX_const(sv)); /* deeper magic */ for (i = 0; i < len; i++) { if (PL_freq[s[i]] < frequency) { rarest = i; @@ -443,7 +443,8 @@ Perl_fbm_instr(pTHX_ unsigned char *big, register unsigned char *bigend, SV *lit { register unsigned char *s; STRLEN l; - register unsigned char *little = (unsigned char *)SvPV(littlestr,l); + register const unsigned char *little + = (const unsigned char *)SvPV_const(littlestr,l); register STRLEN littlelen = l; register const I32 multiline = flags & FBMrf_MULTILINE; @@ -574,7 +575,7 @@ Perl_fbm_instr(pTHX_ unsigned char *big, register unsigned char *bigend, SV *lit { /* Do actual FBM. */ register const unsigned char *table = little + littlelen + FBM_TABLE_OFFSET; - register unsigned char *oldlittle; + const register unsigned char *oldlittle; if (littlelen > (STRLEN)(bigend - big)) return Nullch; -- 2.7.4