X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Fmake_hash.c;h=37ac7651424c779a8bd0586ca3aa25c02e488ce6;hp=38980d2492edc8c5d0bac14f1455dcfabf79ab04;hb=6a530b46563470c2ca73579d1994a0c8e275dd98;hpb=1c551ea75ea57f9186fbe8d79674ac85baa4d358 diff --git a/ncurses/tinfo/make_hash.c b/ncurses/tinfo/make_hash.c index 38980d24..37ac7651 100644 --- a/ncurses/tinfo/make_hash.c +++ b/ncurses/tinfo/make_hash.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2011,2012 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 * @@ -44,7 +44,7 @@ #include -MODULE_ID("$Id: make_hash.c,v 1.10 2012/12/16 00:40:14 tom Exp $") +MODULE_ID("$Id: make_hash.c,v 1.13 2013/09/28 20:55:47 tom Exp $") /* * _nc_make_hash_table() @@ -59,6 +59,24 @@ MODULE_ID("$Id: make_hash.c,v 1.10 2012/12/16 00:40:14 tom Exp $") #define MODULE_ID(id) /*nothing */ #include +static void +failed(const char *s) +{ + perror(s); + exit(EXIT_FAILURE); +} + +static char * +strmalloc(char *s) +{ + size_t need = strlen(s) + 1; + char *result = malloc(need); + if (result == 0) + failed("strmalloc"); + _nc_STRCPY(result, s, need); + return result; +} + /* * int hash_function(string) * @@ -138,7 +156,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 != '#') { @@ -221,7 +239,7 @@ main(int argc, char **argv) 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++;