From d286f1a396f1185457280e0840ecc42489ca0cbe Mon Sep 17 00:00:00 2001 From: Mark Nudelman Date: Tue, 14 Nov 2023 16:58:51 -0800 Subject: [PATCH] Fix some compiler warnings from gcc -Wextra. --- ch.c | 4 ++-- charset.c | 4 ++-- cmdbuf.c | 3 ++- command.c | 4 ++-- cvt.c | 1 + decode.c | 8 +++++--- forwback.c | 2 +- ifile.c | 2 +- input.c | 3 ++- lang.h | 3 +++ lessecho.c | 1 + lesskey_parse.c | 8 ++++---- line.c | 4 ++-- main.c | 2 +- optfunc.c | 2 +- opttbl.c | 2 +- pattern.c | 1 + prompt.c | 10 ++-------- screen.c | 3 +-- search.c | 6 +++--- signal.c | 4 ++++ tags.c | 6 +++--- 22 files changed, 45 insertions(+), 38 deletions(-) diff --git a/ch.c b/ch.c index abf25e34..95c5248a 100644 --- a/ch.c +++ b/ch.c @@ -145,7 +145,7 @@ static int ch_addbuf(); */ static POSITION ch_position(BLOCKNUM block, size_t offset) { - return (ch_block * LBUFSIZE) + (POSITION) offset; + return (block * LBUFSIZE) + (POSITION) offset; } /* @@ -663,7 +663,7 @@ public int ch_back_get(void) * Set max amount of buffer space. * bufspace is in units of 1024 bytes. -1 mean no limit. */ -public void ch_setbufspace(size_t bufspace) +public void ch_setbufspace(ssize_t bufspace) { if (bufspace < 0) maxbufs = -1; diff --git a/charset.c b/charset.c index 42d66bcb..b443236f 100644 --- a/charset.c +++ b/charset.c @@ -819,7 +819,7 @@ public LWCHAR step_char(char **pp, signed int dir, constant char *limit) #define DECLARE_RANGE_TABLE_START(name) \ static struct wchar_range name##_array[] = { #define DECLARE_RANGE_TABLE_END(name) \ - }; struct wchar_range_table name##_table = { name##_array, sizeof(name##_array)/sizeof(*name##_array) }; + }; struct wchar_range_table name##_table = { name##_array, countof(name##_array) }; DECLARE_RANGE_TABLE_START(compose) #include "compose.uni" @@ -907,7 +907,7 @@ public lbool is_combining_char(LWCHAR ch1, LWCHAR ch2) { /* The table is small; use linear search. */ int i; - for (i = 0; i < sizeof(comb_table)/sizeof(*comb_table); i++) + for (i = 0; i < countof(comb_table); i++) { if (ch1 == comb_table[i].first && ch2 == comb_table[i].last) diff --git a/cmdbuf.c b/cmdbuf.c index a67689cd..26487692 100644 --- a/cmdbuf.c +++ b/cmdbuf.c @@ -1209,7 +1209,7 @@ public int cmd_char(char c) if (IS_ASCII_OCTET(c)) cmd_mbc_buf_len = 1; #if MSDOS_COMPILER || OS2 - else if (c == (unsigned char) '\340' && IS_ASCII_OCTET(peekcc())) + else if (c == '\340' && IS_ASCII_OCTET(peekcc())) { /* Assume a special key. */ cmd_mbc_buf_len = 1; @@ -1479,6 +1479,7 @@ static void read_cmdhist(void (*action)(void*,struct mlist*,constant char*), voi static void addhist_init(void *uparam, struct mlist *ml, constant char *string) { + (void) uparam; if (ml != NULL) cmd_addhist(ml, string, 0); else if (string != NULL) diff --git a/command.c b/command.c index ee365315..b50bef20 100644 --- a/command.c +++ b/command.c @@ -858,7 +858,7 @@ static void prompt(void) { WCHAR w[MAX_PATH+16]; p = pr_expand("Less?f - %f."); - MultiByteToWideChar(CP_ACP, 0, p, -1, w, sizeof(w)/sizeof(*w)); + MultiByteToWideChar(CP_ACP, 0, p, -1, w, countof(w)); SetConsoleTitleW(w); } #endif @@ -895,7 +895,7 @@ static void prompt(void) #if MSDOS_COMPILER==WIN32C WCHAR w[MAX_PATH*2]; char a[MAX_PATH*2]; - MultiByteToWideChar(less_acp, 0, p, -1, w, sizeof(w)/sizeof(*w)); + MultiByteToWideChar(less_acp, 0, p, -1, w, countof(w)); WideCharToMultiByte(utf_mode ? CP_UTF8 : GetConsoleOutputCP(), 0, w, -1, a, sizeof(a), NULL, NULL); p = a; diff --git a/cvt.c b/cvt.c index b7770f77..80bb553c 100644 --- a/cvt.c +++ b/cvt.c @@ -21,6 +21,7 @@ extern int utf_mode; */ public size_t cvt_length(size_t len, int ops) { + (void) ops; if (utf_mode) /* * Just copying a string in UTF-8 mode can cause it to grow diff --git a/decode.c b/decode.c index 4bc48a53..33488df3 100644 --- a/decode.c +++ b/decode.c @@ -484,6 +484,7 @@ static int mouse_wheel_up(void) */ static int mouse_button_left(int x, int y) { + (void) x; /* * {{ It would be better to return an action and then do this * in commands() but it's nontrivial to pass y to it. }} @@ -501,6 +502,7 @@ static int mouse_button_left(int x, int y) */ static int mouse_button_right(int x, int y) { + (void) x; /* * {{ unlike mouse_button_left, we could return an action, * but keep it near mouse_button_left for readability. }} @@ -856,21 +858,21 @@ static int new_lesskey(unsigned char *buf, size_t len, lbool sysvar) { case CMD_SECTION: n = gint(&p); - if (n < 0 || p+n >= end) + if (p+n >= end) return (-1); add_fcmd_table(p, n); p += n; break; case EDIT_SECTION: n = gint(&p); - if (n < 0 || p+n >= end) + if (p+n >= end) return (-1); add_ecmd_table(p, n); p += n; break; case VAR_SECTION: n = gint(&p); - if (n < 0 || p+n >= end) + if (p+n >= end) return (-1); add_var_table((sysvar) ? &list_sysvar_tables : &list_var_tables, p, n); diff --git a/forwback.c b/forwback.c index b88357d7..1739cef6 100644 --- a/forwback.c +++ b/forwback.c @@ -401,7 +401,7 @@ public void back(int n, POSITION pos, int force, int only_last) do_repaint = (n > get_back_scroll() || (only_last && n > sc_height-1) || header_lines > 0); #if HILITE_SEARCH if (pos != NULL_POSITION && (hilite_search == OPT_ONPLUS || is_filtering() || status_col)) { - prep_hilite((pos < 3*size_linebuf) ? 0 : pos - (POSITION) (3*size_linebuf), pos, -1); + prep_hilite((pos < (POSITION) (3*size_linebuf)) ? 0 : pos - (POSITION) (3*size_linebuf), pos, -1); } #endif while (--n >= 0) diff --git a/ifile.c b/ifile.c index 5927a8ef..c112c520 100644 --- a/ifile.c +++ b/ifile.c @@ -48,7 +48,7 @@ struct ifile { * Anchor for linked list. */ static struct ifile anchor = { &anchor, &anchor, NULL, NULL, NULL, 0, 0, '\0', - { NULL_POSITION, 0 } }; + { NULL_POSITION, 0 }, NULL, NULL }; static int ifiles = 0; static void incr_index(struct ifile *p, int incr) diff --git a/input.c b/input.c index 2d6b0207..728f921c 100644 --- a/input.c +++ b/input.c @@ -356,7 +356,8 @@ public POSITION back_line(POSITION curr_pos) } #if HILITE_SEARCH if (hilite_search == OPT_ONPLUS || is_filtering() || status_col) - prep_hilite((curr_pos < 3*size_linebuf) ? 0 : curr_pos - (POSITION) (3*size_linebuf), curr_pos, -1); + prep_hilite((curr_pos < (POSITION) (3*size_linebuf)) ? 0 : + curr_pos - (POSITION) (3*size_linebuf), curr_pos, -1); #endif if (ch_seek(curr_pos-1)) { diff --git a/lang.h b/lang.h index 576e5765..226b61cf 100644 --- a/lang.h +++ b/lang.h @@ -28,7 +28,10 @@ #define public /* PUBLIC FUNCTION */ +#undef ptr_diff #define ptr_diff(p1,p2) ((size_t) ((p1)-(p2))) +#undef countof +#define countof(a) ((int)(sizeof(a)/sizeof(*a))) #define size_t_null ((size_t)-1) diff --git a/lessecho.c b/lessecho.c index ee3449e6..e6a58206 100644 --- a/lessecho.c +++ b/lessecho.c @@ -245,6 +245,7 @@ int main(int argc, char *argv[]) return (0); } pr_error("Invalid option after --"); + return (0); default: pr_error("Invalid option letter"); } diff --git a/lesskey_parse.c b/lesskey_parse.c index a6aaa0ba..6f01c347 100644 --- a/lesskey_parse.c +++ b/lesskey_parse.c @@ -382,7 +382,7 @@ static int match_version(char op, int ver) * If the version matches, return the part of the line that should be executed. * Otherwise, return NULL. */ -static char * version_line(char *s, struct lesskey_tables *tables) +static char * version_line(char *s) { char op; int ver; @@ -445,7 +445,7 @@ static char * control_line(char *s, struct lesskey_tables *tables) } if (PREFIX(s, "#version")) { - return (version_line(s, tables)); + return (version_line(s)); } return (s); } @@ -655,7 +655,7 @@ int parse_lesskey(constant char *ainfile, struct lesskey_tables *tables) */ int parse_lesskey_content(constant char *content, struct lesskey_tables *tables) { - int cx = 0; + size_t cx = 0; init_tables(tables); errors = 0; @@ -667,7 +667,7 @@ int parse_lesskey_content(constant char *content, struct lesskey_tables *tables) { /* Extract a line from the content buffer and parse it. */ char line[1024]; - int lx = 0; + size_t lx = 0; while (content[cx] != '\0' && content[cx] != '\n' && content[cx] != ';') { if (lx >= sizeof(line)-1) break; diff --git a/line.c b/line.c index 7957e7ec..75d6be68 100644 --- a/line.c +++ b/line.c @@ -632,7 +632,7 @@ public int ansi_step(struct ansi_state *pansi, LWCHAR ch) if (pansi->hindex >= 0) { static char hlink_prefix[] = ESCS "]8;"; - if (ch == hlink_prefix[pansi->hindex] || + if (ch == (LWCHAR) hlink_prefix[pansi->hindex] || (pansi->hindex == 0 && IS_CSI_START(ch))) { pansi->hindex++; @@ -1556,7 +1556,7 @@ public int rrshift(void) static int lookup_color_index(int attr) { int cx; - for (cx = 0; cx < sizeof(color_map)/sizeof(*color_map); cx++) + for (cx = 0; cx < countof(color_map); cx++) if (color_map[cx].attr == attr) return cx; return -1; diff --git a/main.c b/main.c index 1c78b46d..1356e4d7 100644 --- a/main.c +++ b/main.c @@ -181,7 +181,7 @@ static int security_feature(constant char *name, size_t len) int i; int match = -1; - for (i = 0; i < sizeof(features)/sizeof(*features); i++) + for (i = 0; i < countof(features); i++) { if (strncmp(features[i].name, name, len) == 0) { diff --git a/optfunc.c b/optfunc.c index eb9f77cd..bec11fbf 100644 --- a/optfunc.c +++ b/optfunc.c @@ -475,7 +475,7 @@ public void opt_b(int type, constant char *s) /* * Set the new number of buffers. */ - ch_setbufspace((size_t) bufspace); + ch_setbufspace((ssize_t) bufspace); break; case QUERY: break; diff --git a/opttbl.c b/opttbl.c index c4d33ae9..56c8ecd0 100644 --- a/opttbl.c +++ b/opttbl.c @@ -854,7 +854,7 @@ public struct loption * findopt_name(constant char **p_optname, constant char ** maxoname = oname; maxlen = len; ambig = FALSE; - exact = (len == (int)strlen(oname->oname)); + exact = (len == strlen(oname->oname)); } if (!(o->otype & TRIPLE)) break; diff --git a/pattern.c b/pattern.c index e4f9e5e3..93d7a740 100644 --- a/pattern.c +++ b/pattern.c @@ -264,6 +264,7 @@ static int match(constant char *pattern, size_t pattern_len, constant char *buf, constant char *pattern_end = pattern + pattern_len; constant char *buf_end = buf + buf_len; + (void) nsubs; for ( ; buf < buf_end; buf++) { for (pp = pattern, lp = buf; ; pp++, lp++) diff --git a/prompt.c b/prompt.c index 660aa884..66a9b872 100644 --- a/prompt.c +++ b/prompt.c @@ -226,7 +226,7 @@ static lbool cond(char c, int where) * Here we decode that letter and take the appropriate action, * usually by appending something to the message being built. */ -static void protochar(char c, int where, int iseditproto) +static void protochar(char c, int where) { POSITION pos; POSITION len; @@ -501,13 +501,7 @@ public constant char * pr_expand(constant char *proto) { where = 0; p = wherechar(p, &where); - protochar(c, where, -#if EDITOR - (proto == editproto)); -#else - 0); -#endif - + protochar(c, where); } break; } diff --git a/screen.c b/screen.c index 74e23cb6..b62e58e7 100644 --- a/screen.c +++ b/screen.c @@ -3094,8 +3094,7 @@ public void WIN32textout(constant char *text, int len) * wide and use WriteConsoleW. */ WCHAR wtext[1024]; - len = MultiByteToWideChar(CP_UTF8, 0, text, len, wtext, - sizeof(wtext)/sizeof(*wtext)); + len = MultiByteToWideChar(CP_UTF8, 0, text, len, wtext, countof(wtext)); WriteConsoleW(con_out, wtext, len, &written, NULL); } else WriteConsole(con_out, text, len, &written, NULL); diff --git a/search.c b/search.c index b01c6932..4dd157a9 100644 --- a/search.c +++ b/search.c @@ -962,7 +962,7 @@ static void create_hilites(POSITION linepos, constant char *line, constant char * the current pattern. * sp,ep delimit the first match already found. */ -static void hilite_line(POSITION linepos, constant char *line, size_t line_len, int *chpos, constant char **sp, constant char **ep, int nsp, int cvt_ops) +static void hilite_line(POSITION linepos, constant char *line, size_t line_len, int *chpos, constant char **sp, constant char **ep, int nsp) { constant char *searchp; constant char *line_end = line + line_len; @@ -1378,7 +1378,7 @@ static int search_range(POSITION pos, POSITION endpos, int search_type, int matc * Just add the matches in this line to the * hilite list and keep searching. */ - hilite_line(linepos + skip_bytes, cline, line_len, chpos, sp, ep, NSP, cvt_ops); + hilite_line(linepos + skip_bytes, cline, line_len, chpos, sp, ep, NSP); #endif } else if (--matches <= 0) { @@ -1394,7 +1394,7 @@ static int search_range(POSITION pos, POSITION endpos, int search_type, int matc * the matches in this one line. */ clr_hilite(); - hilite_line(linepos + skip_bytes, cline, line_len, chpos, sp, ep, NSP, cvt_ops); + hilite_line(linepos + skip_bytes, cline, line_len, chpos, sp, ep, NSP); } #endif if (chop_line()) diff --git a/signal.c b/signal.c index f711068c..60684803 100644 --- a/signal.c +++ b/signal.c @@ -40,6 +40,7 @@ extern long jump_sline_fraction; /* ARGSUSED*/ static RETSIGTYPE u_interrupt(int type) { + (void) type; bell(); #if OS2 LSIGNAL(SIGINT, SIG_ACK); @@ -70,6 +71,7 @@ static RETSIGTYPE u_interrupt(int type) /* ARGSUSED*/ static RETSIGTYPE stop(int type) { + (void) type; LSIGNAL(SIGTSTP, stop); sigs |= S_STOP; if (reading) @@ -93,6 +95,7 @@ static RETSIGTYPE stop(int type) /* ARGSUSED*/ public RETSIGTYPE winch(int type) { + (void) type; LSIGNAL(SIG_LESSWINDOW, winch); sigs |= S_WINCH; if (reading) @@ -127,6 +130,7 @@ static BOOL WINAPI wbreak_handler(DWORD dwCtrlType) static RETSIGTYPE terminate(int type) { + (void) type; quit(15); } diff --git a/tags.c b/tags.c index 383f12e1..b868b9c6 100644 --- a/tags.c +++ b/tags.c @@ -111,7 +111,7 @@ public void cleantags(void) /* * Create a new tag entry. */ -static struct tag * maketagent(constant char *name, constant char *file, LINENUM linenum, constant char *pattern, lbool endline) +static struct tag * maketagent(constant char *file, LINENUM linenum, constant char *pattern, lbool endline) { struct tag *tp; @@ -353,7 +353,7 @@ static enum tag_result findctag(constant char *tag) q--; *q = '\0'; } - tp = maketagent(tag, tagfile, taglinenum, tagpattern, tagendline); + tp = maketagent(tagfile, taglinenum, tagpattern, tagendline); TAG_INS(tp); total++; } @@ -583,7 +583,7 @@ static enum tag_result findgtag(constant char *tag, int type) } /* Make new entry and add to list. */ - tp = maketagent(name, file, (LINENUM) atoi(line), NULL, FALSE); + tp = maketagent(file, (LINENUM) atoi(line), NULL, FALSE); TAG_INS(tp); total++; }