}
STATIC U8 *
-doencodes(U8 *h, const char *s, I32 len)
+doencodes(U8 *h, const U8 *s, I32 len)
{
*h++ = PL_uuemap[len];
while (len > 2) {
len -= 3;
}
if (len > 0) {
- const char r = (len > 1 ? s[1] : '\0');
+ const U8 r = (len > 1 ? s[1] : '\0');
*h++ = PL_uuemap[(077 & (s[0] >> 2))];
*h++ = PL_uuemap[(077 & (((s[0] << 4) & 060) | ((r >> 4) & 017)))];
*h++ = PL_uuemap[(077 & ((r << 2) & 074))];
return SvGROW(sv, len+extend+1);
}
-static void
+static SV *
S_sv_check_infnan(pTHX_ SV *sv, I32 datumtype)
{
SvGETMAGIC(sv);
+ if (UNLIKELY(SvAMAGIC(sv)))
+ sv = sv_2num(sv);
if (UNLIKELY(isinfnansv(sv))) {
const I32 c = TYPE_NO_MODIFIERS(datumtype);
const NV nv = SvNV_nomg(sv);
else
Perl_croak(aTHX_ "Cannot pack %"NVgf" with '%c'", nv, (int) c);
}
+ return sv;
}
-#define SvIV_no_inf(sv,d) (S_sv_check_infnan(aTHX_ sv,d), SvIV_nomg(sv))
-#define SvUV_no_inf(sv,d) (S_sv_check_infnan(aTHX_ sv,d), SvUV_nomg(sv))
+#define SvIV_no_inf(sv,d) \
+ ((sv) = S_sv_check_infnan(aTHX_ sv,d), SvIV_nomg(sv))
+#define SvUV_no_inf(sv,d) \
+ ((sv) = S_sv_check_infnan(aTHX_ sv,d), SvUV_nomg(sv))
STATIC
SV **
afloat = -FLT_MAX;
else afloat = (float)anv;
# else
- afloat = (float)anv;
+ /* a simple cast to float is undefined if outside
+ * the range of values that can be represented */
+ afloat = (float)(anv > FLT_MAX ? NV_INF :
+ anv < -FLT_MAX ? -NV_INF : anv);
# endif
PUSH_VAR(utf8, cur, afloat, needs_swap);
}
"aptr=%p, aend=%p, buffer=%p, todo=%ld",
aptr, aend, buffer, (long) todo);
}
- end = doencodes(hunk, buffer, todo);
+ end = doencodes(hunk, (const U8 *)buffer, todo);
} else {
- end = doencodes(hunk, aptr, todo);
+ end = doencodes(hunk, (const U8 *)aptr, todo);
aptr += todo;
}
PUSH_BYTES(utf8, cur, hunk, end-hunk, 0);