X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Fmake_hash.c;h=c8bf911f826089da93f4da1e5e164fa6d0f1b439;hp=31f21005f4187c639084c3edc4e65e1cb66581bf;hb=bfe3845eb1a2ff02a740e917b537e939ec4e44cb;hpb=f486c68b1efe3bab5739c3f464fde6685a52bee5 diff --git a/ncurses/tinfo/make_hash.c b/ncurses/tinfo/make_hash.c index 31f21005..c8bf911f 100644 --- a/ncurses/tinfo/make_hash.c +++ b/ncurses/tinfo/make_hash.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2012,2013 Free Software Foundation, Inc. * + * Copyright (c) 1998-2017,2018 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -34,7 +34,6 @@ /* * make_hash.c --- build-time program for constructing comp_captab.c - * */ #include @@ -44,7 +43,7 @@ #include -MODULE_ID("$Id: make_hash.c,v 1.12 2013/02/16 21:27:50 tom Exp $") +MODULE_ID("$Id: make_hash.c,v 1.17 2018/05/12 15:58:31 tom Exp $") /* * _nc_make_hash_table() @@ -69,10 +68,11 @@ failed(const char *s) static char * strmalloc(char *s) { - char *result = malloc(strlen(s) + 1); + size_t need = strlen(s) + 1; + char *result = malloc(need); if (result == 0) - failed("strmalloc"); - strcpy(result, s); + failed("strmalloc"); + _nc_STRCPY(result, s, need); return result; } @@ -155,10 +155,12 @@ parse_columns(char *buffer) int col = 0; - if (list == 0 && (list = typeCalloc(char *, (MAX_COLUMNS + 1))) == 0) - return (0); - if (*buffer != '#') { + if (list == 0) { + list = typeCalloc(char *, (MAX_COLUMNS + 1)); + if (list == 0) + return (0); + } while (*buffer != '\0') { char *s; for (s = buffer; (*s != '\0') && !isspace(UChar(*s)); s++) @@ -224,13 +226,16 @@ main(int argc, char **argv) * Read the table into our arrays. */ for (n = 0; (n < CAPTABSIZE) && fgets(buffer, BUFSIZ, stdin);) { - char **list, *nlp = strchr(buffer, '\n'); + char **list; + char *nlp = strchr(buffer, '\n'); if (nlp) *nlp = '\0'; + else + buffer[sizeof(buffer) - 2] = '\0'; list = parse_columns(buffer); if (list == 0) /* blank or comment */ continue; - if (column > count_columns(list)) { + if (column < 0 || column > count_columns(list)) { fprintf(stderr, "expected %d columns, have %d:\n%s\n", column, count_columns(list), @@ -325,5 +330,11 @@ main(int argc, char **argv) printf("#endif\n\n"); free(hash_table); +#if NO_LEAKS + for (n = 0; (n < CAPTABSIZE); ++n) { + free((void *) name_table[n].nte_name); + } + free(name_table); +#endif return EXIT_SUCCESS; }