Skip to content
Tcl Source Code Artifact [aab1b8dcdb]
Login

Artifact [aab1b8dcdb]

Artifact aab1b8dcdbc6d7fe56df128a6f51234999296105:

Attachment "tcl-abs.patch" to ticket [1241572fff] added by rmax on 2005-12-10 01:13:03.
--- generic/tclExecute.c
+++ generic/tclExecute.c
@@ -5074,8 +5074,11 @@
     if (valuePtr->typePtr == &tclIntType) {
 	i = valuePtr->internalRep.longValue;
 	if (i < 0) {
-	    iResult = -i;
-	    if (iResult < 0) {
+	    /* The casting hell below is needed to prevent GCC 4.1.0
+	     * and newer from optimizing away the MIN_INT special case
+	     * as dead code, which is allowed, according to the C
+	     * standard.  See bug #1241572. */
+	    if ((unsigned long)(((signed long)iResult)-1) > 0) {
 #ifdef TCL_WIDE_INT_IS_LONG
 		Tcl_SetObjResult(interp, Tcl_NewStringObj(
 			"integer value too large to represent", -1));
@@ -5094,6 +5097,7 @@
 #endif
 
 	    }
+	    iResult = -i;
 	} else {
 	    iResult = i;
 	}