SourceForge.net | 10 Aug 2007 01:28
Picon
Favicon

[ swig-Bugs-1650229 ] problem with 64bit variable parsing

Bugs item #1650229, was opened at 2007-02-01 16:48
Message generated for change (Comment added) made by pdokj
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=101645&aid=1650229&group_id=1645

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: tcl
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: spraju (spraju)
Assigned to: Nobody/Anonymous (nobody)
Summary: problem with 64bit variable parsing

Initial Comment:
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

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

Comment By: Kjell Wooding (pdokj)
Date: 2007-08-09 17:28

Message:
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.

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

Comment By: spraju (spraju)
Date: 2007-02-02 14:41

Message:
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

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

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=101645&aid=1650229&group_id=1645

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/

Gmane