Skip to content

Commit c174bf3

Browse files
jhitonycoz
authored andcommitted
Quad_t and Uquad_t cannot unpack as NVs.
If IVSIZE >= 8, a Quad_t is always >= IV_MIN, and <= IV_MAX, and an Uquad_t is always (>= 0 aka UV_MIN and) <= UV_MAX; they cannot escape their quadness and be NVs. (This logic may fail if Quad_t is not 8 bytes, but then other things would no doubt fail.) Also tighten the logic by adding HAS_QUAD, also for the pack case. Fix for Coverity perl5 CID 28942.
1 parent 00b25ef commit c174bf3

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

pp_pack.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,14 +1632,13 @@ S_unpack_rec(pTHX_ tempsym_t* symptr, const char *s, const char *strbeg, const c
16321632
PUSHs(newSVpvn_flags(aptr, len, SVs_TEMP));
16331633
}
16341634
break;
1635-
#if IVSIZE >= 8
1635+
#if defined(HAS_QUAD) && IVSIZE >= 8
16361636
case 'q':
16371637
while (len-- > 0) {
16381638
Quad_t aquad;
16391639
SHIFT_VAR(utf8, s, strend, aquad, datumtype, needs_swap);
16401640
if (!checksum)
1641-
mPUSHs(aquad >= IV_MIN && aquad <= IV_MAX ?
1642-
newSViv((IV)aquad) : newSVnv((NV)aquad));
1641+
mPUSHs(newSViv((IV)aquad));
16431642
else if (checksum > bits_in_uv)
16441643
cdouble += (NV)aquad;
16451644
else
@@ -1651,8 +1650,7 @@ S_unpack_rec(pTHX_ tempsym_t* symptr, const char *s, const char *strbeg, const c
16511650
Uquad_t auquad;
16521651
SHIFT_VAR(utf8, s, strend, auquad, datumtype, needs_swap);
16531652
if (!checksum)
1654-
mPUSHs(auquad <= UV_MAX ?
1655-
newSVuv((UV)auquad) : newSVnv((NV)auquad));
1653+
mPUSHs(newSVuv((UV)auquad));
16561654
else if (checksum > bits_in_uv)
16571655
cdouble += (NV)auquad;
16581656
else
@@ -2982,7 +2980,7 @@ S_pack_rec(pTHX_ SV *cat, tempsym_t* symptr, SV **beglist, SV **endlist )
29822980
PUSH32(utf8, cur, &ai32, needs_swap);
29832981
}
29842982
break;
2985-
#if IVSIZE >= 8
2983+
#if defined(HAS_QUAD) && IVSIZE >= 8
29862984
case 'Q':
29872985
while (len-- > 0) {
29882986
Uquad_t auquad;

0 commit comments

Comments
 (0)