diff options
Diffstat (limited to 'usr.bin/indent/lexi.c')
-rw-r--r-- | usr.bin/indent/lexi.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/usr.bin/indent/lexi.c b/usr.bin/indent/lexi.c index fe73fe3f63ce..f48de3215547 100644 --- a/usr.bin/indent/lexi.c +++ b/usr.bin/indent/lexi.c @@ -594,6 +594,7 @@ void add_typename(const char *key) { int comparison; + const char *copy; if (typename_top + 1 >= typename_count) { typenames = realloc((void *)typenames, @@ -602,21 +603,25 @@ add_typename(const char *key) err(1, NULL); } if (typename_top == -1) - typenames[++typename_top] = key; + typenames[++typename_top] = copy = strdup(key); else if ((comparison = strcmp(key, typenames[typename_top])) >= 0) { /* take advantage of sorted input */ - if (comparison != 0) /* remove duplicates */ - typenames[++typename_top] = key; + if (comparison == 0) /* remove duplicates */ + return; + typenames[++typename_top] = copy = strdup(key); } else { int p; - for (p = 0; (comparison = strcmp(key, typenames[p])) >= 0; p++) + for (p = 0; (comparison = strcmp(key, typenames[p])) > 0; p++) /* find place for the new key */; if (comparison == 0) /* remove duplicates */ return; memmove(&typenames[p + 1], &typenames[p], sizeof(typenames[0]) * (++typename_top - p)); - typenames[p] = key; + typenames[p] = copy = strdup(key); } + + if (copy == NULL) + err(1, NULL); } |