diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2002-02-20 16:26:56 +0000 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2002-02-20 16:26:56 +0000 |
commit | 735b914b6122ad8117831a13734ab73e13d1e5bc (patch) | |
tree | 4934005371e59d20000ee84956e0fe7e60f052d7 /pp_pack.c | |
parent | 13089db4da7b2c2e95e9627db24ff15c9fdc44f8 (diff) | |
download | perl-735b914b6122ad8117831a13734ab73e13d1e5bc.tar.gz |
Forgot from #14790.
p4raw-id: //depot/perl@14793
Diffstat (limited to 'pp_pack.c')
-rw-r--r-- | pp_pack.c | 23 |
1 files changed, 21 insertions, 2 deletions
@@ -1720,8 +1720,27 @@ PP(pp_pack) buf[sizeof(buf) - 1] &= 0x7f; /* clear continue bit */ sv_catpvn(cat, in, (buf + sizeof(buf)) - in); } - else - DIE(aTHX_ "Cannot compress non integer"); + else { + char *from, *result, *in; + SV *norm; + STRLEN len; + bool done; + + /* Copy string and check for compliance */ + from = SvPV(fromstr, len); + if ((norm = is_an_int(from, len)) == NULL) + DIE(aTHX_ "can compress only unsigned integer"); + + New('w', result, len, char); + in = result + len; + done = FALSE; + while (!done) + *--in = div128(norm, &done) | 0x80; + result[len - 1] &= 0x7F; /* clear continue bit */ + sv_catpvn(cat, in, (result + len) - in); + Safefree(result); + SvREFCNT_dec(norm); /* free norm */ + } } break; case 'i': |