[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

Perl_newSVpvf("%lld") is broken



The %lld format overflows with a 2**31 long long with 32 bit integers.  Likely
something inside Perl_sv_vcatpvfn is using an integer for the %d and only
later does it notice the %lld.  That or it's assuming integers are 64 bit
which I've seen in other quad-related code (POPq, for example).

The vcatpvfn() code terrifies me, anyone want to investigate?

	SV *tsv;
	long long bignumber = 0x7FFFFFFFLL;
	tsv = Perl_newSVpvf(aTHX_ "%lld", bignumber);
	sv_dump(tsv);

SV = PV(0x1801c40) at 0x1803de0
  REFCNT = 1
  FLAGS = (POK,pPOK)
  PV = 0x11018c0 "2147483647"\0
  CUR = 10
  LEN = 16

-----------------------------------------------------------

	SV *tsv;
	long long bignumber = 0x80000000LL;
	tsv = Perl_newSVpvf(aTHX_ "%lld", bignumber);
	sv_dump(tsv);

SV = PV(0x1801c40) at 0x1803de0
  REFCNT = 1
  FLAGS = (POK,pPOK)
  PV = 0x11018c0 "-2147483648"\0
  CUR = 11
  LEN = 16

------------------------------------------------------------

	SV *tsv;
	long long bignumber = 0x7FFFFFFFFLL;
	tsv = Perl_newSVpvf(aTHX_ "%lld", bignumber);
	sv_dump(tsv);

SV = PV(0x1801c40) at 0x1803de0
  REFCNT = 1
  FLAGS = (POK,pPOK)
  PV = 0x11018c0 "-1"\0
  CUR = 2
  LEN = 16



-- 
I have a date with some giant cartoon robots and booze.


Follow-Ups from:
Michael G Schwern <schwern@pobox.com>

[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]