X-Git-Url: https://ncurses.scripts.mit.edu/?a=blobdiff_plain;f=progs%2Finfocmp.c;h=817845502db2b7e72024eb37c06849cc4ea58a2c;hb=122d3739b3c11c83decc625d53f26fff6e825710;hp=c1b95088b113e23c0cbb990032a719a35aa9194c;hpb=d761c922d94448b16b71061ee5efeb346b744f13;p=ncurses.git diff --git a/progs/infocmp.c b/progs/infocmp.c index c1b95088..81784550 100644 --- a/progs/infocmp.c +++ b/progs/infocmp.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2020-2021,2022 Thomas E. Dickey * + * Copyright 2020-2022,2023 Thomas E. Dickey * * Copyright 1998-2016,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -43,7 +43,7 @@ #include -MODULE_ID("$Id: infocmp.c,v 1.155 2022/09/03 23:28:48 tom Exp $") +MODULE_ID("$Id: infocmp.c,v 1.158 2023/11/11 18:25:52 tom Exp $") #define MAX_STRING 1024 /* maximum formatted string */ @@ -158,7 +158,7 @@ no_numeric(int value) } static bool -no_string(char *value) +no_string(const char *const value) { bool result = (value == ABSENT_STRING); if (!strcmp(s_absent, s_cancel)) @@ -209,15 +209,18 @@ use_predicate(unsigned type, PredIdx idx) * unlike numbers and strings, whose cancelled/absent state is * recorded in the terminfo database. */ - for (ep = &entries[1]; ep < entries + termcount; ep++) - if (ep->tterm.Booleans[idx] == TRUE) { - is_set = entries[0].tterm.Booleans[idx]; - break; + if (idx < NUM_BOOLEANS(&(entries[0].tterm))) { + for (ep = &entries[1]; ep < entries + termcount; ep++) { + if (idx < NUM_BOOLEANS(&(ep->tterm)) + && ep->tterm.Booleans[idx] == TRUE) { + is_set = entries[0].tterm.Booleans[idx]; + break; + } } - if (is_set != entries[0].tterm.Booleans[idx]) - return (!is_set); - else - return (FAIL); + if (is_set != entries[0].tterm.Booleans[idx]) + return (!is_set); + } + return (FAIL); } case NUMBER: @@ -229,16 +232,18 @@ use_predicate(unsigned type, PredIdx idx) * capability gets the first non-default value found * in the sequence of use entries'. */ - for (ep = &entries[1]; ep < entries + termcount; ep++) - if (VALID_NUMERIC(ep->tterm.Numbers[idx])) { - value = ep->tterm.Numbers[idx]; - break; - } + if (idx < NUM_NUMBERS(&(entries[0].tterm))) { + for (ep = &entries[1]; ep < entries + termcount; ep++) + if (idx < NUM_NUMBERS(&(ep->tterm)) + && VALID_NUMERIC(ep->tterm.Numbers[idx])) { + value = ep->tterm.Numbers[idx]; + break; + } - if (value != entries[0].tterm.Numbers[idx]) - return (value != ABSENT_NUMERIC); - else - return (FAIL); + if (value != entries[0].tterm.Numbers[idx]) + return (value != ABSENT_NUMERIC); + } + return (FAIL); } case STRING: @@ -252,18 +257,20 @@ use_predicate(unsigned type, PredIdx idx) * capability gets the first non-default value found * in the sequence of use entries'. */ - for (ep = &entries[1]; ep < entries + termcount; ep++) - if (ep->tterm.Strings[idx]) { - usestr = ep->tterm.Strings[idx]; - break; - } + if (idx < NUM_STRINGS(&(entries[0].tterm))) { + for (ep = &entries[1]; ep < entries + termcount; ep++) + if (idx < NUM_STRINGS(&(ep->tterm)) + && ep->tterm.Strings[idx]) { + usestr = ep->tterm.Strings[idx]; + break; + } - if (usestr == ABSENT_STRING && termstr == ABSENT_STRING) - return (FAIL); - else if (!usestr || !termstr || capcmp(idx, usestr, termstr)) - return (TRUE); - else - return (FAIL); + if (usestr == ABSENT_STRING && termstr == ABSENT_STRING) + return (FAIL); + else if (!usestr || !termstr || capcmp(idx, usestr, termstr)) + return (TRUE); + } + return (FAIL); } } @@ -905,7 +912,6 @@ analyze_string(const char *name, const char *cap, TERMTYPE2 *tp) sizeof(buf2)); _nc_STRNCPY(buf3, sp + csi, len); buf3[len] = '\0'; - len += (size_t) csi + 1; expansion = lookup_params(std_modes, buf2, buf3); } @@ -926,7 +932,6 @@ analyze_string(const char *name, const char *cap, TERMTYPE2 *tp) sizeof(buf2)); _nc_STRNCPY(buf3, sp + csi + 1, len); buf3[len] = '\0'; - len += (size_t) csi + 2; expansion = lookup_params(private_modes, buf2, buf3); }