swig/swig-2.0.4-fix-overflow-error-64bitint.patch
Ismail Dönmez e65876f8c1 Accepting request 108217 from home:k0da:ppc
- The perl 5.12 packages are compiled with -Duse64bitint, which 
  means that IVs are 64-bits even on 32-bit architectures. When 
  converting IVs, SWIG assumes that an IV is the same size as a 
  long, which causes OverflowErrors with  unsigned longs when 
  the value is greater than 2^31.

OBS-URL: https://build.opensuse.org/request/show/108217
OBS-URL: https://build.opensuse.org/package/show/devel:tools:building/swig?expand=0&rev=31
2012-03-06 20:46:07 +00:00

81 lines
2.2 KiB
Diff

Description: Fix overflow errors with 64-bit IVs
The perl 5.12 packages are compiled with -Duse64bitint, which means that IVs
are 64-bits even on 32-bit architectures. When converting IVs, SWIG assumes
that an IV is the same size as a long, which causes OverflowErrors with
unsigned longs when the value is greater than 2^31.
.
This patch should remove those assumptions by using the "IV" type defined by
the perl headers, and explicitly checking the values are within the correct
range for the type being converted.
Author: Chris Butler <chrisb@debian.org>
Bug-Debian: http://bugs.debian.org/579540
Forwarded: no
--- a/Lib/perl5/perlprimtypes.swg
+++ b/Lib/perl5/perlprimtypes.swg
@@ -56,8 +56,13 @@
SWIG_AsVal_dec(long)(SV *obj, long* val)
{
if (SvIOK(obj)) {
- if (val) *val = SvIV(obj);
- return SWIG_OK;
+ IV v = SvIV(obj);
+ if (v >= LONG_MIN && v <= LONG_MAX) {
+ if (val) *val = v;
+ return SWIG_OK;
+ } else {
+ return SWIG_OverflowError;
+ }
} else {
int dispatch = 0;
const char *nptr = SvPV_nolen(obj);
@@ -108,11 +113,16 @@
SWIG_AsVal_dec(unsigned long)(SV *obj, unsigned long *val)
{
if (SvUOK(obj)) {
- if (val) *val = SvUV(obj);
- return SWIG_OK;
+ UV v = SvUV(obj);
+ if (v >= 0 && v <= ULONG_MAX) {
+ if (val) *val = v;
+ return SWIG_OK;
+ } else {
+ return SWIG_OverflowError;
+ }
} else if (SvIOK(obj)) {
- long v = SvIV(obj);
- if (v >= 0) {
+ IV v = SvIV(obj);
+ if (v >= 0 && v <= ULONG_MAX) {
if (val) *val = v;
return SWIG_OK;
} else {
@@ -179,8 +189,13 @@
SWIG_AsVal_dec(long long)(SV *obj, long long *val)
{
if (SvIOK(obj)) {
- if (val) *val = SvIV(obj);
- return SWIG_OK;
+ IV v = SvIV(obj);
+ if (v >= LLONG_MIN && v <= LLONG_MAX) {
+ if (val) *val = v;
+ return SWIG_OK;
+ } else {
+ return SWIG_OverflowError;
+ }
} else {
int dispatch = 0;
const char *nptr = SvPV_nolen(obj);
@@ -246,8 +261,8 @@
if (val) *val = SvUV(obj);
return SWIG_OK;
} else if (SvIOK(obj)) {
- long v = SvIV(obj);
- if (v >= 0) {
+ IV v = SvIV(obj);
+ if (v >= 0 && v <= ULLONG_MAX) {
if (val) *val = v;
return SWIG_OK;
} else {