summaryrefslogtreecommitdiff
path: root/sv.c
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2000-11-30 20:41:39 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2000-11-30 20:41:39 +0000
commitfa301091a913890fbb1fa04962693e6daf2a2229 (patch)
treeea0a5fe585484b2c30b35fba4d8f6a4d7099406c /sv.c
parent4659c93fd71d46dcfe5376e8f72bace4634ccd6c (diff)
downloadperl-fa301091a913890fbb1fa04962693e6daf2a2229.tar.gz
Fix for 20001128.006, be more careful in Perl_sv_utf8_downgrade().
Why the different platforms behave so differently (core dump vs no core dump) on this bug is a but of a mystery, but if I had to guess I would mumble something like 'alignment'. p4raw-id: //depot/perl@7936
Diffstat (limited to 'sv.c')
-rw-r--r--sv.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/sv.c b/sv.c
index d7b4c8b4a1..01076cbe02 100644
--- a/sv.c
+++ b/sv.c
@@ -2447,22 +2447,26 @@ bool
Perl_sv_utf8_downgrade(pTHX_ register SV* sv, bool fail_ok)
{
if (SvPOK(sv) && SvUTF8(sv)) {
- char *c = SvPVX(sv);
- STRLEN len = SvCUR(sv) + 1; /* include trailing NUL */
- if (!utf8_to_bytes((U8*)c, &len)) {
- if (fail_ok)
- return FALSE;
- else {
- if (PL_op)
- Perl_croak(aTHX_ "Wide character in %s",
- PL_op_desc[PL_op->op_type]);
- else
- Perl_croak(aTHX_ "Wide character");
+ if (SvCUR(sv)) {
+ char *c = SvPVX(sv);
+ STRLEN len = SvCUR(sv);
+
+ if (!utf8_to_bytes((U8*)c, &len)) {
+ if (fail_ok)
+ return FALSE;
+ else {
+ if (PL_op)
+ Perl_croak(aTHX_ "Wide character in %s",
+ PL_op_desc[PL_op->op_type]);
+ else
+ Perl_croak(aTHX_ "Wide character");
+ }
}
+ SvCUR(sv) = len;
}
- SvCUR(sv) = len - 1;
SvUTF8_off(sv);
}
+
return TRUE;
}