X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Fmake_hash.c;h=31f21005f4187c639084c3edc4e65e1cb66581bf;hp=e050fe10d9460950b39f0b12c59e83ecd21dbca6;hb=7087871f804c061d339994964269f3c20e88f547;hpb=44a4147009bf2978d342175fb52b7f0999e11b5f diff --git a/ncurses/tinfo/make_hash.c b/ncurses/tinfo/make_hash.c index e050fe10..31f21005 100644 --- a/ncurses/tinfo/make_hash.c +++ b/ncurses/tinfo/make_hash.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2010,2011 Free Software Foundation, Inc. * + * Copyright (c) 1998-2012,2013 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 * @@ -39,13 +39,12 @@ #include -#include #include #include #include -MODULE_ID("$Id: make_hash.c,v 1.4 2011/10/08 21:11:54 tom Exp $") +MODULE_ID("$Id: make_hash.c,v 1.12 2013/02/16 21:27:50 tom Exp $") /* * _nc_make_hash_table() @@ -60,6 +59,23 @@ MODULE_ID("$Id: make_hash.c,v 1.4 2011/10/08 21:11:54 tom Exp $") #define MODULE_ID(id) /*nothing */ #include +static void +failed(const char *s) +{ + perror(s); + exit(EXIT_FAILURE); +} + +static char * +strmalloc(char *s) +{ + char *result = malloc(strlen(s) + 1); + if (result == 0) + failed("strmalloc"); + strcpy(result, s); + return result; +} + /* * int hash_function(string) * @@ -120,6 +136,18 @@ _nc_make_hash_table(struct name_table_entry *table, #define MAX_COLUMNS BUFSIZ /* this _has_ to be worst-case */ +static int +count_columns(char **list) +{ + int result = 0; + if (list != 0) { + while (*list++) { + ++result; + } + } + return result; +} + static char ** parse_columns(char *buffer) { @@ -127,7 +155,7 @@ parse_columns(char *buffer) int col = 0; - if (list == 0 && (list = typeCalloc(char *, MAX_COLUMNS)) == 0) + if (list == 0 && (list = typeCalloc(char *, (MAX_COLUMNS + 1))) == 0) return (0); if (*buffer != '#') { @@ -202,8 +230,15 @@ main(int argc, char **argv) list = parse_columns(buffer); if (list == 0) /* blank or comment */ continue; + if (column > count_columns(list)) { + fprintf(stderr, "expected %d columns, have %d:\n%s\n", + column, + count_columns(list), + buffer); + exit(EXIT_FAILURE); + } name_table[n].nte_link = -1; /* end-of-hash */ - name_table[n].nte_name = strdup(list[column]); + name_table[n].nte_name = strmalloc(list[column]); if (!strcmp(list[2], "bool")) { name_table[n].nte_type = BOOLEAN; name_table[n].nte_index = BoolCount++; @@ -257,13 +292,12 @@ main(int argc, char **argv) printf("static struct name_table_entry *_nc_%s_table = 0;\n\n", root_name); } else { - printf("static struct name_table_entry %s _nc_%s_table[] =\n", - bigstring ? "" : "const", + printf("static struct name_table_entry const _nc_%s_table[] =\n", root_name); printf("{\n"); for (n = 0; n < CAPTABSIZE; n++) { - sprintf(buffer, "\"%s\"", - name_table[n].nte_name); + _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer)) "\"%s\"", + name_table[n].nte_name); printf("\t{ %15s,\t%10s,\t%3d, %3d }%c\n", buffer, typenames[name_table[n].nte_type],