diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2001-09-03 19:50:57 +0000 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2001-09-03 19:50:57 +0000 |
commit | 85c16d835facb3e1567f0ad453769c0d9a8da60b (patch) | |
tree | 18e98ac37b49f61765b436c2fb4fcc0f200c99a7 /pp.c | |
parent | 0686c0b8fd853975c64d3472ef479435ba920e0a (diff) | |
download | perl-85c16d835facb3e1567f0ad453769c0d9a8da60b.tar.gz |
Make crypt() do something more sane for Unicode
(take crypt() of the low eight bits of the characters,
instead of taking crypt() of the UTF-8 of the scalar);
add a test for crypt().
p4raw-id: //depot/perl@11852
Diffstat (limited to 'pp.c')
-rw-r--r-- | pp.c | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -3095,12 +3095,28 @@ PP(pp_crypt) dSP; dTARGET; dPOPTOPssrl; STRLEN n_a; #ifdef HAS_CRYPT - char *tmps = SvPV(left, n_a); + STRLEN len; + char *tmps = SvPV(left, len); + char *t = 0; + if (DO_UTF8(left)) { + /* If Unicode take the crypt() of the low 8 bits + * of the characters of the string. */ + char *s = tmps; + char *send = tmps + len; + STRLEN i = 0; + Newz(688, t, len, char); + while (s < send) { + t[i++] = utf8_to_uvchr((U8*)s, 0) & 0xFF; + s += UTF8SKIP(s); + } + tmps = t; + } #ifdef FCRYPT sv_setpv(TARG, fcrypt(tmps, SvPV(right, n_a))); #else sv_setpv(TARG, PerlProc_crypt(tmps, SvPV(right, n_a))); #endif + Safefree(t); #else DIE(aTHX_ "The crypt() function is unimplemented due to excessive paranoia."); |