summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2011-12-22 18:43:12 (GMT)
committerdgp <dgp@users.sourceforge.net>2011-12-22 18:43:12 (GMT)
commit312e43120625077580d3ac4702bfa73fee6fb953 (patch)
tree2220cbb84982d3486eadd5565d038f6ea96c0113
parentaade3501c09273bd682cd0c3cd0955a2df0e02ba (diff)
parentb2c383f4b4e1df4ee9393ca65a9ba551753739a7 (diff)
downloadtk-312e43120625077580d3ac4702bfa73fee6fb953.zip
tk-312e43120625077580d3ac4702bfa73fee6fb953.tar.gz
tk-312e43120625077580d3ac4702bfa73fee6fb953.tar.bz2
3235256 - Keep menu entry IDs out of system values. Thanks Colin McDonald.
-rw-r--r--win/tkWinMenu.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/win/tkWinMenu.c b/win/tkWinMenu.c
index 79642f5..b1bf7f8 100644
--- a/win/tkWinMenu.c
+++ b/win/tkWinMenu.c
@@ -213,30 +213,36 @@ GetNewID(
TkMenuEntry *mePtr, /* The menu we are working with. */
WORD *menuIDPtr) /* The resulting id. */
{
- ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
+ ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
- WORD curID = tsdPtr->lastCommandID + 1;
-
- /*
- * The following code relies on WORD wrapping when the highest value is
- * incremented.
- */
+ WORD curID = tsdPtr->lastCommandID;
- while (curID != tsdPtr->lastCommandID) {
+ while (1) {
Tcl_HashEntry *commandEntryPtr;
- int newEntry;
+ int new;
- commandEntryPtr = Tcl_CreateHashEntry(&tsdPtr->commandTable,
- ((char *) NULL) + curID, &newEntry);
- if (newEntry == 1) {
+ /*
+ * Try the next ID number, taking care to wrap rather than stray
+ * into the system menu IDs. [Bug 3235256]
+ */
+ if (++curID >= 0xF000) {
+ curID = 1;
+ }
+
+ /* Return error when we've checked all IDs without success. */
+ if (curID == tsdPtr->lastCommandID) {
+ return TCL_ERROR;
+ }
+
+ commandEntryPtr = Tcl_CreateHashEntry(&tsdPtr->commandTable,
+ (char *) curID, &new);
+ if (new) {
Tcl_SetHashValue(commandEntryPtr, mePtr);
*menuIDPtr = curID;
tsdPtr->lastCommandID = curID;
return TCL_OK;
- }
- curID++;
+ }
}
- return TCL_ERROR;
}
/*