Skip to content

Commit

Permalink
pp_pack.c: Replace rolled-own with hop()
Browse files Browse the repository at this point in the history
  • Loading branch information
khwilliamson committed Oct 1, 2024
1 parent 045b0df commit 24a0fdd
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions pp_pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -979,16 +979,10 @@ S_unpack_rec(pTHX_ tempsym_t* symptr, const char *s, const char *strbeg, const c
case '@' | TYPE_IS_SHRIEKING:
case '@':
s = strbeg + symptr->strbeg;
if (utf8 && !(datumtype & TYPE_IS_SHRIEKING))
{
while (len > 0) {
if (s >= strend)
Perl_croak(aTHX_ "'@' outside of string in unpack");
s += UTF8SKIP(s);
len--;
}
if (s > strend)
Perl_croak(aTHX_ "'@' outside of string with malformed UTF-8 in unpack");
if (utf8 && !(datumtype & TYPE_IS_SHRIEKING)) {
s = (char *) utf8_hop_forward((U8 *) s, len, (U8 *) strend);
if (s >= strend)
Perl_croak(aTHX_ "'@' outside of string in unpack");
} else {
if (strend-s < len)
Perl_croak(aTHX_ "'@' outside of string in unpack");
Expand Down Expand Up @@ -1018,15 +1012,9 @@ S_unpack_rec(pTHX_ tempsym_t* symptr, const char *s, const char *strbeg, const c
/* FALLTHROUGH */
case 'X':
if (utf8) {
while (len > 0) {
if (s <= strbeg)
Perl_croak(aTHX_ "'X' outside of string in unpack");
while (--s, UTF8_IS_CONTINUATION(*s)) {
if (s <= strbeg)
Perl_croak(aTHX_ "'X' outside of string in unpack");
}
len--;
}
s = (char *) utf8_hop_back((U8 *) s, -len, (U8 *) strbeg);
if (s <= strbeg)
Perl_croak(aTHX_ "'X' outside of string in unpack");
} else {
if (len > s - strbeg)
Perl_croak(aTHX_ "'X' outside of string in unpack" );
Expand Down

0 comments on commit 24a0fdd

Please sign in to comment.