diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-02-22 17:34:33 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-02-22 17:34:33 -0300 |
commit | 8c1a9899d4460aa19780919f4245c08d7ebba0e9 (patch) | |
tree | 685817907f64133330011eb7db845830c9327a3e /tree.c | |
parent | 05caf09a36cadaab401bc9a24e29e2cd6e4126d4 (diff) | |
download | lua-8c1a9899d4460aa19780919f4245c08d7ebba0e9.tar.gz lua-8c1a9899d4460aa19780919f4245c08d7ebba0e9.tar.bz2 lua-8c1a9899d4460aa19780919f4245c08d7ebba0e9.zip |
functions "luaI_free" and "luaI_realloc" (or macro "growvector") may be
called with NULL.
Diffstat (limited to 'tree.c')
-rw-r--r-- | tree.c | 28 |
1 files changed, 13 insertions, 15 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_tree="$Id: tree.c,v 1.17 1996/02/14 13:35:51 roberto Exp roberto $"; | 6 | char *rcs_tree="$Id: tree.c,v 1.18 1996/02/14 19:11:09 roberto Exp roberto $"; |
7 | 7 | ||
8 | 8 | ||
9 | #include <string.h> | 9 | #include <string.h> |
@@ -55,20 +55,18 @@ static void grow (stringtable *tb) | |||
55 | int i; | 55 | int i; |
56 | for (i=0; i<newsize; i++) | 56 | for (i=0; i<newsize; i++) |
57 | newhash[i] = NULL; | 57 | newhash[i] = NULL; |
58 | if (tb->size > 0) | 58 | /* rehash */ |
59 | { /* rehash */ | 59 | tb->nuse = 0; |
60 | tb->nuse = 0; | 60 | for (i=0; i<tb->size; i++) |
61 | for (i=0; i<tb->size; i++) | 61 | if (tb->hash[i] != NULL && tb->hash[i] != &EMPTY) |
62 | if (tb->hash[i] != NULL && tb->hash[i] != &EMPTY) | 62 | { |
63 | { | 63 | int h = tb->hash[i]->hash%newsize; |
64 | int h = tb->hash[i]->hash%newsize; | 64 | while (newhash[h]) |
65 | while (newhash[h]) | 65 | h = (h+1)%newsize; |
66 | h = (h+1)%newsize; | 66 | newhash[h] = tb->hash[i]; |
67 | newhash[h] = tb->hash[i]; | 67 | tb->nuse++; |
68 | tb->nuse++; | 68 | } |
69 | } | 69 | luaI_free(tb->hash); |
70 | luaI_free(tb->hash); | ||
71 | } | ||
72 | tb->size = newsize; | 70 | tb->size = newsize; |
73 | tb->hash = newhash; | 71 | tb->hash = newhash; |
74 | } | 72 | } |