summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-11-18 11:48:44 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-11-18 11:48:44 -0200
commit62e1a4c84d9075e27e5bcde20151f8545f9ab731 (patch)
treefc43e108a65ba1b88688e473e0374617b5222fb6
parent81411e8913a5aabd0c58926c7a399e1a6de4fe90 (diff)
downloadlua-62e1a4c84d9075e27e5bcde20151f8545f9ab731.tar.gz
lua-62e1a4c84d9075e27e5bcde20151f8545f9ab731.tar.bz2
lua-62e1a4c84d9075e27e5bcde20151f8545f9ab731.zip
BUG: problems with negative indexes
-rw-r--r--hash.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/hash.c b/hash.c
index 07b427bc..90d81293 100644
--- a/hash.c
+++ b/hash.c
@@ -3,7 +3,7 @@
3** hash manager for lua 3** hash manager for lua
4*/ 4*/
5 5
6char *rcs_hash="$Id: hash.c,v 2.30 1996/05/06 14:30:27 roberto Exp roberto $"; 6char *rcs_hash="$Id: hash.c,v 2.31 1996/07/12 20:00:26 roberto Exp roberto $";
7 7
8 8
9#include "mem.h" 9#include "mem.h"
@@ -48,24 +48,26 @@ int luaI_redimension (int nhash)
48 48
49static int hashindex (Hash *t, Object *ref) /* hash function */ 49static int hashindex (Hash *t, Object *ref) /* hash function */
50{ 50{
51 switch (tag(ref)) 51 long int h;
52 { 52 switch (tag(ref)) {
53 case LUA_T_NIL: 53 case LUA_T_NIL:
54 lua_error ("unexpected type to index table"); 54 lua_error ("unexpected type to index table");
55 return -1; /* UNREACHEABLE */ 55 h = 0; /* UNREACHEABLE */
56 case LUA_T_NUMBER: 56 case LUA_T_NUMBER:
57 return (((int)nvalue(ref))%nhash(t)); 57 h = (long int)nvalue(ref); break;
58 case LUA_T_STRING: 58 case LUA_T_STRING:
59 return (int)((tsvalue(ref)->hash)%nhash(t)); /* make it a valid index */ 59 h = tsvalue(ref)->hash; break;
60 case LUA_T_FUNCTION: 60 case LUA_T_FUNCTION:
61 return (((IntPoint)ref->value.tf)%nhash(t)); 61 h = (IntPoint)ref->value.tf; break;
62 case LUA_T_CFUNCTION: 62 case LUA_T_CFUNCTION:
63 return (((IntPoint)fvalue(ref))%nhash(t)); 63 h = (IntPoint)fvalue(ref); break;
64 case LUA_T_ARRAY: 64 case LUA_T_ARRAY:
65 return (((IntPoint)avalue(ref))%nhash(t)); 65 h = (IntPoint)avalue(ref); break;
66 default: /* user data */ 66 default: /* user data */
67 return (((IntPoint)uvalue(ref))%nhash(t)); 67 h = (IntPoint)uvalue(ref); break;
68 } 68 }
69 if (h < 0) h = -h;
70 return h%nhash(t); /* make it a valid index */
69} 71}
70 72
71int lua_equalObj (Object *t1, Object *t2) 73int lua_equalObj (Object *t1, Object *t2)