summaryrefslogtreecommitdiff
path: root/usr.bin/indent/lexi.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2005-03-06 14:34:26 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2005-03-06 14:34:26 +0000
commit0e5eff6fee0fe35e3efcbf966ad480aaac42c8fb (patch)
tree224c8e681b7b65e0ed3527143d49f1266a4333b8 /usr.bin/indent/lexi.c
parent20cc763a35c975a364e1c6c94bcab1197cd0c0fb (diff)
Fix realloc bug introduce in rev 1.10 and do some minor cleanup.
OK henning@ and tdeval@
Diffstat (limited to 'usr.bin/indent/lexi.c')
-rw-r--r--usr.bin/indent/lexi.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/usr.bin/indent/lexi.c b/usr.bin/indent/lexi.c
index 6c8595a0849..e513cf4877f 100644
--- a/usr.bin/indent/lexi.c
+++ b/usr.bin/indent/lexi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lexi.c,v 1.11 2004/07/20 03:50:26 deraadt Exp $ */
+/* $OpenBSD: lexi.c,v 1.12 2005/03/06 14:34:25 millert Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -34,7 +34,7 @@
#ifndef lint
/*static char sccsid[] = "@(#)lexi.c 8.1 (Berkeley) 6/6/93";*/
-static char rcsid[] = "$OpenBSD: lexi.c,v 1.11 2004/07/20 03:50:26 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: lexi.c,v 1.12 2005/03/06 14:34:25 millert Exp $";
#endif /* not lint */
/*
@@ -565,14 +565,12 @@ void
addkey(char *key, int val)
{
struct templ *p;
- int i = 0;
+ int i;
- while (i < nspecials) {
+ for (i = 0; i < nspecials; i++) {
p = &specials[i];
if (p->rwd[0] == key[0] && strcmp(p->rwd, key) == 0)
return;
- else
- i++;
}
if (specials == specialsinit) {
@@ -580,14 +578,13 @@ addkey(char *key, int val)
* Whoa. Must reallocate special table.
*/
nspecials = sizeof (specialsinit) / sizeof (specialsinit[0]);
- maxspecials = nspecials;
- maxspecials += maxspecials >> 2;
+ maxspecials = nspecials + (nspecials >> 2);
specials = (struct templ *)malloc(maxspecials * sizeof specials[0]);
if (specials == NULL)
err(1, NULL);
- memmove(specials, specialsinit, sizeof specialsinit);
+ memcpy(specials, specialsinit, sizeof specialsinit);
} else if (nspecials >= maxspecials) {
- int newspecials = maxspecials + maxspecials >> 2;
+ int newspecials = maxspecials + (maxspecials >> 2);
struct templ *specials2;
specials2 = realloc(specials, newspecials * sizeof specials[0]);
@@ -597,7 +594,7 @@ addkey(char *key, int val)
maxspecials = newspecials;
}
- p = &specials[i];
+ p = &specials[nspecials];
p->rwd = key;
p->rwcode = val;
nspecials++;