#795 problem with 64bit variable parsing

closed-fixed
tcl (60)
5
2007-09-24
2007-02-01
spraju
No

Hi

I am a newbie to swig (only 6 months of experience using). I have this problem with 64bit variables in tcl wrappers.

usage: I use swig1.3.31, on Red hat linux RHEL4, with tcl

problem:
typedef unsigned long long Uint64;
I have a function bla(Uint64 val)
{ ...}

from the tcl environment (tclsh) when i call
"bla 0xdeadbeefff" I get this error

OverflowError in method 'bla', argument 1 of type 'Uint64'

upong further digging, in the following wrapper function generated by swig i found the culprity code

SWIG_AsVal_unsigned_SS_long_SS_long SWIG_TCL_DECL_ARGS_2(Tcl_Obj *obj, unsigned long long *val)
{
...
---------------------
unsigned long long v;
if (*nptr == '-') return SWIG_OverflowError;
v = strtoull(nptr, &endptr,0);
if (errno == ERANGE) {
errno = 0;
return SWIG_OverflowError;
}

---------------------
...
}

In the above code, in if-statement, looking at 'errorno' for overflow is the bug ! The correct check should have been

if ((v == ULLONG_MAX) && (errno == ERANGE)) {

without looking at ULLONG_MAX relying on errorno is no good.

pl see 'man strtoull' for any clarifications.

pl confirm this or provide clarification.

Thanks for your time
spraju

Discussion

  • spraju
    spraju
    2007-02-02

    Logged In: YES
    user_id=1708249
    Originator: YES

    In fact SWIG should get rid of overflow checking, as 0xffffffffffffffff might be a valid input value for an application, in which case, SWIG should not prevent passing that value by flagging overflow error. SWIG should pass the values as is

     
  • Kjell Wooding
    Kjell Wooding
    2007-08-09

    Logged In: YES
    user_id=848092
    Originator: NO

    I also hit this.

    I think some implementations of strtoull can also return EINVAL. Testing against ULLONG_MAX however would seem to be the right thing.

    Also, errno should be cleared before the call to strtoull.

     
  • William Fulton
    William Fulton
    2007-09-24

    Logged In: YES
    user_id=242951
    Originator: NO

    patch 1771313 applied (more or less) for 1.3.32. Please test.

     
  • William Fulton
    William Fulton
    2007-09-24

    • assigned_to: nobody --> wsfulton
    • status: open --> closed-fixed