diff options
author | jan.nijtmans <jan.nijtmans@noemail.net> | 2013-01-24 08:05:42 (GMT) |
---|---|---|
committer | jan.nijtmans <jan.nijtmans@noemail.net> | 2013-01-24 08:05:42 (GMT) |
commit | 197dfc4e7015fc276ee5939307d4da92d023217b (patch) | |
tree | a3927441e7a87f5d5666c7ca17310ef57ba21d28 /generic/tclIndexObj.c | |
parent | 24554fa7ece1e66d0bd4dcc3576ebf6a54845ea1 (diff) | |
parent | 5372488c56ff04f566580257aa963e7cabdede41 (diff) | |
download | tcl-197dfc4e7015fc276ee5939307d4da92d023217b.zip tcl-197dfc4e7015fc276ee5939307d4da92d023217b.tar.gz tcl-197dfc4e7015fc276ee5939307d4da92d023217b.tar.bz2 |
Simplify STRING_AT macro.
Protect Tcl_GetIndexFromObjStruct from invalid "offset" values, like 0 or -1. Undocumented, because I don't want to promote people start using that.
FossilOrigin-Name: 8d90ad34d174691263098bd82e0879e39714a0b6
Diffstat (limited to 'generic/tclIndexObj.c')
-rw-r--r-- | generic/tclIndexObj.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/generic/tclIndexObj.c b/generic/tclIndexObj.c index 944fb8e..8ec1b68 100644 --- a/generic/tclIndexObj.c +++ b/generic/tclIndexObj.c @@ -53,12 +53,12 @@ typedef struct { * The following macros greatly simplify moving through a table... */ -#define STRING_AT(table, offset, index) \ - (*((const char *const *)(((char *)(table)) + ((offset) * (index))))) +#define STRING_AT(table, offset) \ + (*((const char *const *)(((char *)(table)) + (offset)))) #define NEXT_ENTRY(table, offset) \ - (&(STRING_AT(table, offset, 1))) + (&(STRING_AT(table, offset))) #define EXPAND_OF(indexRep) \ - STRING_AT((indexRep)->tablePtr, (indexRep)->offset, (indexRep)->index) + STRING_AT((indexRep)->tablePtr, (indexRep)->offset*(indexRep)->index) /* *---------------------------------------------------------------------- @@ -138,7 +138,7 @@ Tcl_GetIndexFromObj( * proper match, then TCL_ERROR is returned and an error message is left * in interp's result (unless interp is NULL). The msg argument is used * in the error message; for example, if msg has the value "option" then - * the error message will say something flag 'bad option "foo": must be + * the error message will say something like 'bad option "foo": must be * ...' * * Side effects: @@ -170,6 +170,10 @@ Tcl_GetIndexFromObjStruct( Tcl_Obj *resultPtr; IndexRep *indexRep; + /* Protect against invalid values, like -1 or 0. */ + if (offset < (int)sizeof(char *)) { + offset = (int)sizeof(char *); + } /* * See if there is a valid cached result from a previous lookup. */ |