summaryrefslogtreecommitdiffstats
path: root/generic/tclObj.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2005-04-20 16:06:16 (GMT)
committerdgp <dgp@users.sourceforge.net>2005-04-20 16:06:16 (GMT)
commit7661d10d9c8f7d52761d3481a52e770ba3f8b3fe (patch)
tree21bdd0348d778f9641ea900faf308406f81541c3 /generic/tclObj.c
parent83b7caad0f7cbf70e83ec99688ef29b77d0f762d (diff)
downloadtcl-7661d10d9c8f7d52761d3481a52e770ba3f8b3fe.zip
tcl-7661d10d9c8f7d52761d3481a52e770ba3f8b3fe.tar.gz
tcl-7661d10d9c8f7d52761d3481a52e770ba3f8b3fe.tar.bz2
* generic/tclGet.c (Tcl_GetInt): Corrected error that did not
* generic/tclObj.c (Tcl_GetIntFromObj): permit 0x80000000 to be recognized as an integer on TCL_WIDE_INT_IS_LONG systems [Bug 1090869].
Diffstat (limited to 'generic/tclObj.c')
-rw-r--r--generic/tclObj.c53
1 files changed, 17 insertions, 36 deletions
diff --git a/generic/tclObj.c b/generic/tclObj.c
index 9c34908..3cf3760 100644
--- a/generic/tclObj.c
+++ b/generic/tclObj.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclObj.c,v 1.42.2.9 2004/10/27 15:39:36 kennykb Exp $
+ * RCS: @(#) $Id: tclObj.c,v 1.42.2.10 2005/04/20 16:06:17 dgp Exp $
*/
#include "tclInt.h"
@@ -1745,8 +1745,8 @@ Tcl_GetIntFromObj(interp, objPtr, intPtr)
register Tcl_Obj *objPtr; /* The object from which to get a int. */
register int *intPtr; /* Place to store resulting int. */
{
- register long l = 0;
int result;
+ Tcl_WideInt w = 0;
/*
* If the object isn't already an integer of any width, try to
@@ -1764,45 +1764,26 @@ Tcl_GetIntFromObj(interp, objPtr, intPtr)
* Object should now be either int or wide. Get its value.
*/
- if (objPtr->typePtr == &tclIntType) {
- l = objPtr->internalRep.longValue;
- } else if (objPtr->typePtr == &tclWideIntType) {
#ifndef TCL_WIDE_INT_IS_LONG
- /*
- * If the object is already a wide integer, don't convert it.
- * This code allows for any integer in the range -ULONG_MAX to
- * ULONG_MAX to be converted to a long, ignoring overflow.
- * The rule preserves existing semantics for conversion of
- * integers on input, but avoids inadvertent demotion of
- * wide integers to 32-bit ones in the internal rep.
- */
-
- Tcl_WideInt w = objPtr->internalRep.wideValue;
- if (w >= -(Tcl_WideInt)(ULONG_MAX) && w <= (Tcl_WideInt)(ULONG_MAX)) {
- l = Tcl_WideAsLong(w);
- } else {
- goto tooBig;
- }
-#else
- l = objPtr->internalRep.longValue;
+ if (objPtr->typePtr == &tclWideIntType) {
+ w = objPtr->internalRep.wideValue;
+ } else
#endif
- } else {
- Tcl_Panic( "string->integer conversion failed to convert the obj." );
+ {
+ w = Tcl_LongAsWide(objPtr->internalRep.longValue);
}
- if (((long)((int)l)) == l) {
- *intPtr = (int)l;
- return TCL_OK;
- }
-#ifndef TCL_WIDE_INT_IS_LONG
- tooBig:
-#endif
- if (interp != NULL) {
- Tcl_ResetResult(interp);
- Tcl_AppendToObj(Tcl_GetObjResult(interp),
- "integer value too large to represent as non-long integer", -1);
+ if ((LLONG_MAX > UINT_MAX)
+ && ((w > UINT_MAX) || (w < -(Tcl_WideInt)UINT_MAX))) {
+ if (interp != NULL) {
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(
+ "integer value too large to represent as non-long integer",
+ -1));
+ }
+ return TCL_ERROR;
}
- return TCL_ERROR;
+ *intPtr = (int)w;
+ return TCL_OK;
}
/*