diff options
author | dgp@users.sourceforge.net <dgp> | 2011-12-22 18:42:28 (GMT) |
---|---|---|
committer | dgp@users.sourceforge.net <dgp> | 2011-12-22 18:42:28 (GMT) |
commit | 3182e20819a866da2abb1b39639cfe552aca67ce (patch) | |
tree | d38f3dea1080e86f18df725d0d07165fbcd8510c /win/tkWinMenu.c | |
parent | 7a954cff3a1cd4cd5424738f12294bd159d7cdb2 (diff) | |
parent | a0c377d715163a11f283a3a2ef196dad917a7c4f (diff) | |
download | tk-3182e20819a866da2abb1b39639cfe552aca67ce.zip tk-3182e20819a866da2abb1b39639cfe552aca67ce.tar.gz tk-3182e20819a866da2abb1b39639cfe552aca67ce.tar.bz2 |
3235256 - Keep menu entry IDs out of system values. Thanks Colin McDonald.
Diffstat (limited to 'win/tkWinMenu.c')
-rw-r--r-- | win/tkWinMenu.c | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/win/tkWinMenu.c b/win/tkWinMenu.c index 5ad29e1..c25b793 100644 --- a/win/tkWinMenu.c +++ b/win/tkWinMenu.c @@ -217,30 +217,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, (char *) mePtr); *menuIDPtr = curID; tsdPtr->lastCommandID = curID; return TCL_OK; - } - curID++; + } } - return TCL_ERROR; } /* |