X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=progs%2Finfocmp.c;h=506a374e40177d96c18e6582f495050282845de8;hp=d57fa857f9879998dd5f49025ee7b97a00c7b04d;hb=64f44b13d30e0a7bc2921a9d43755423f81564fd;hpb=ceaf3464e98d7984ed377f023abf63d69b7b8045 diff --git a/progs/infocmp.c b/progs/infocmp.c index d57fa857..506a374e 100644 --- a/progs/infocmp.c +++ b/progs/infocmp.c @@ -42,7 +42,7 @@ #include -MODULE_ID("$Id: infocmp.c,v 1.118 2012/05/26 21:11:32 tom Exp $") +MODULE_ID("$Id: infocmp.c,v 1.123 2012/11/17 23:15:10 tom Exp $") #define L_CURL "{" #define R_CURL "}" @@ -87,20 +87,45 @@ static int compare; static bool ignorepads; /* ignore pad prefixes when diffing */ #if NO_LEAKS + +typedef struct { + ENTRY *head; + ENTRY *tail; +} ENTERED; + +static ENTERED *entered; + #undef ExitProgram static void ExitProgram(int code) GCC_NORETURN; /* prototype is to get gcc to accept the noreturn attribute */ static void ExitProgram(int code) { - while (termcount-- > 0) - _nc_free_termtype(&entries[termcount].tterm); + int n; + + for (n = 0; n < termcount; ++n) { + ENTRY *new_head = _nc_head; + ENTRY *new_tail = _nc_tail; + _nc_head = entered[n].head; + _nc_tail = entered[n].tail; + _nc_free_entries(entered[n].head); + _nc_head = new_head; + _nc_tail = new_tail; + } _nc_leaks_dump_entry(); free(entries); + free(entered); _nc_free_tic(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 */ @@ -579,6 +604,7 @@ compare_predicate(PredType type, PredIdx idx, const char *name) case C_NAND: if (!e1->nuses) { + found = TRUE; for_each_entry() { e2 = &entries[extra++]; if (e2->nuses != e1->nuses) { @@ -959,6 +985,10 @@ file_comparison(int argc, char *argv[]) if (freopen(argv[n], "r", stdin) == 0) _nc_err_abort("Can't open %s", argv[n]); +#if NO_LEAKS + entered[n].head = _nc_head; + entered[n].tail = _nc_tail; +#endif _nc_head = _nc_tail = 0; /* parse entries out of the source file */ @@ -1190,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); @@ -1469,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; @@ -1651,9 +1686,16 @@ 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 + if ((entered = typeCalloc(ENTERED, maxterms)) == 0) + failed("entered"); +#endif if (tfile == 0 || tname == 0