Skip to content

Commit

Permalink
Fix some compiler warnings from gcc -Wextra.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Nov 15, 2023
1 parent 9c34d87 commit d286f1a
Show file tree
Hide file tree
Showing 22 changed files with 45 additions and 38 deletions.
4 changes: 2 additions & 2 deletions ch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/*
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion cmdbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions command.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions cvt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. }}
Expand All @@ -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. }}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion forwback.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ifile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
3 changes: 3 additions & 0 deletions lang.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions lessecho.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
8 changes: 4 additions & 4 deletions lesskey_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions line.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion optfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion opttbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions pattern.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down
10 changes: 2 additions & 8 deletions prompt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 1 addition & 2 deletions screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions search.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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())
Expand Down
4 changes: 4 additions & 0 deletions signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -127,6 +130,7 @@ static BOOL WINAPI wbreak_handler(DWORD dwCtrlType)

static RETSIGTYPE terminate(int type)
{
(void) type;
quit(15);
}

Expand Down
6 changes: 3 additions & 3 deletions tags.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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++;
}
Expand Down Expand Up @@ -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++;
}
Expand Down

0 comments on commit d286f1a

Please sign in to comment.