X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=progs%2Finfocmp.c;h=506a374e40177d96c18e6582f495050282845de8;hp=748c445585e3d451101e5fa9afb2e3afe8ddf707;hb=64f44b13d30e0a7bc2921a9d43755423f81564fd;hpb=1d7867d33e6954be7c7121b1028ad6768f487752;ds=inline diff --git a/progs/infocmp.c b/progs/infocmp.c index 748c4455..506a374e 100644 --- a/progs/infocmp.c +++ b/progs/infocmp.c @@ -42,7 +42,7 @@ #include -MODULE_ID("$Id: infocmp.c,v 1.120 2012/06/08 23:05:25 tom Exp $") +MODULE_ID("$Id: infocmp.c,v 1.123 2012/11/17 23:15:10 tom Exp $") #define L_CURL "{" #define R_CURL "}" @@ -119,6 +119,13 @@ ExitProgram(int code) } #endif +static void +failed(const char *s) +{ + perror(s); + ExitProgram(EXIT_FAILURE); +} + static char * canonical_name(char *ptr, char *buf) /* extract the terminal type's primary name */ @@ -1213,7 +1220,9 @@ any_initializer(const char *fmt, const char *type) need = (strlen(entries->tterm.term_names) + strlen(type) + strlen(fmt)); - initializer = (char *) malloc(need); + initializer = (char *) malloc(need + 1); + if (initializer == 0) + failed("any_initializer"); } _nc_STRCPY(initializer, entries->tterm.term_names, need); @@ -1492,6 +1501,9 @@ main(int argc, char *argv[]) /* make sure we have enough space to add two terminal entries */ myargv = typeCalloc(char *, (size_t) (argc + 3)); + if (myargv == 0) + failed("myargv"); + memcpy(myargv, argv, (sizeof(char *) * (size_t) argc)); argv = myargv; @@ -1674,11 +1686,15 @@ main(int argc, char *argv[]) } maxterms = (size_t) (argc + 2 - optind); - tfile = typeMalloc(path, maxterms); - tname = typeCalloc(char *, maxterms); - entries = typeCalloc(ENTRY, maxterms); + if ((tfile = typeMalloc(path, maxterms)) == 0) + failed("tfile"); + if ((tname = typeCalloc(char *, maxterms)) == 0) + failed("tname"); + if ((entries = typeCalloc(ENTRY, maxterms)) == 0) + failed("entries"); #if NO_LEAKS - entered = typeCalloc(ENTERED, maxterms); + if ((entered = typeCalloc(ENTERED, maxterms)) == 0) + failed("entered"); #endif if (tfile == 0