Tk Source Code

Artifact [69b79456]
Login

Artifact 69b79456e329cbd3e1eed2f59033d6177a978fa77dfa6abd3116b82b75c0574e:

Attachment "tkmenu.patch" to ticket [b189559e] added by emiliano 2023-10-12 23:52:33. (unpublished)
Index: generic/tkMenu.c
==================================================================
--- generic/tkMenu.c
+++ generic/tkMenu.c
@@ -2152,10 +2152,17 @@
     Tcl_Size *indexPtr)		/* Where to store converted index. */
 {
     int i;
     const char *string;
     Tcl_HashEntry *entryPtr;
+
+    string = Tcl_GetString(objPtr);
+
+    if (string[0] == 0) {
+	*indexPtr = TCL_INDEX_NONE;
+	return TCL_OK;
+    }
 
     if (TkGetIntForIndex(objPtr, menuPtr->numEntries - 1, lastOK, indexPtr) == TCL_OK) {
 	/* TCL_INDEX_NONE is only accepted if it does not result from a negative number */
 	if (*indexPtr != TCL_INDEX_NONE || Tcl_GetString(objPtr)[0] != '-') {
 	    if (*indexPtr >= menuPtr->numEntries) {
@@ -2163,12 +2170,10 @@
 	    }
 	    return TCL_OK;
 	}
     }
 
-    string = Tcl_GetString(objPtr);
-
     if ((string[0] == 'a') && (strcmp(string, "active") == 0)) {
 	*indexPtr = menuPtr->active;
 	goto success;
     }
 
@@ -2175,14 +2180,10 @@
     if ((string[0] == 'l') && (strcmp(string, "last") == 0)) {
 	*indexPtr = menuPtr->numEntries - ((lastOK) ? 0 : 1);
 	goto success;
     }
 
-    if (string[0] == 0) {
-	*indexPtr = TCL_INDEX_NONE;
-	goto success;
-    }
 #if !defined(TK_NO_DEPRECATED) && TK_MAJOR_VERSION < 9
     if ((string[0] == 'n') && (strcmp(string, "none") == 0)) {
 	*indexPtr = TCL_INDEX_NONE;
 	goto success;
     }