diff --git a/ch.c b/ch.c index 5b31204f..fbca8c4a 100644 --- a/ch.c +++ b/ch.c @@ -122,7 +122,8 @@ struct filestate { thisfile->hashtbl[h].hnext = (bn); static struct filestate *thisfile; -static int ch_ungotchar = -1; +static unsigned char ch_ungotchar; +static lbool ch_have_ungotchar = FALSE; static int maxbufs = -1; extern int autobuf; @@ -260,11 +261,11 @@ static int ch_get(void) * If we read less than a full block, that's ok. * We use partial block and pick up the rest next time. */ - if (ch_ungotchar != -1) + if (ch_have_ungotchar) { bp->data[bp->datasize] = ch_ungotchar; n = 1; - ch_ungotchar = -1; + ch_have_ungotchar = FALSE; } else if (ch_flags & CH_HELPFILE) { bp->data[bp->datasize] = helpdata[ch_fpos]; @@ -372,9 +373,15 @@ static int ch_get(void) */ public void ch_ungetchar(int c) { - if (c != -1 && ch_ungotchar != -1) - error("ch_ungetchar overrun", NULL_PARG); - ch_ungotchar = c; + if (c < 0) + ch_have_ungotchar = FALSE; + else + { + if (ch_have_ungotchar) + error("ch_ungetchar overrun", NULL_PARG); + ch_ungotchar = (unsigned char) c; + ch_have_ungotchar = TRUE; + } } #if LOGFILE diff --git a/charset.c b/charset.c index 902e6c3b..136cfd31 100644 --- a/charset.c +++ b/charset.c @@ -521,9 +521,10 @@ public int binary_char(LWCHAR c) /* * Is a given character a "control" character? */ -public int control_char(LWCHAR c) +public lbool control_char(LWCHAR c) { - c &= 0377; + if (!is_ascii_char(c)) + return FALSE; return (chardef[c] & IS_CONTROL_CHAR); } @@ -536,7 +537,7 @@ public constant char * prchar(LWCHAR c) /* {{ This buffer can be overrun if LESSBINFMT is a long string. }} */ static char buf[MAX_PRCHAR_LEN+1]; - c &= 0377; + c &= 0377; /*{{type-issue}}*/ if ((c < 128 || !utf_mode) && !control_char(c)) SNPRINTF1(buf, sizeof(buf), "%c", (int) c); else if (c == ESC) @@ -637,8 +638,7 @@ public lbool is_utf8_well_formed(constant char *ss, int slen) return (FALSE); } else { - unsigned char mask; - mask = (~((1 << (8-len)) - 1)) & 0xFF; + unsigned char mask = (~((((unsigned char)1) << (8-len)) - 1)) & 0xFF; if (s[0] == mask && (s[1] & mask) == 0x80) return (FALSE); } diff --git a/cmdbuf.c b/cmdbuf.c index c7b8719c..9c80e3d6 100644 --- a/cmdbuf.c +++ b/cmdbuf.c @@ -31,7 +31,8 @@ static int prompt_col; /* Column of cursor just after prompt */ static char *cp; /* Pointer into cmdbuf */ static int cmd_offset; /* Index into cmdbuf of first displayed char */ static int literal; /* Next input char should not be interpreted */ -public ssize_t updown_match = -1; /* Prefix length in up/down movement */ +public size_t updown_match; /* Prefix length in up/down movement */ +public lbool have_updown_match = FALSE; #if TAB_COMPLETE_FILENAME static int cmd_complete(int action); @@ -124,7 +125,7 @@ public void cmd_reset(void) cmd_offset = 0; literal = 0; cmd_mbc_buf_len = 0; - updown_match = -1; + have_updown_match = FALSE; } /* @@ -134,7 +135,7 @@ public void clear_cmd(void) { cmd_col = prompt_col = 0; cmd_mbc_buf_len = 0; - updown_match = -1; + have_updown_match = FALSE; } /* @@ -193,7 +194,7 @@ static constant char * cmd_step_common(char *p, LWCHAR ch, size_t len, int *pwid if (len == 1) { - pr = prchar((int) ch); + pr = prchar(ch); width = (int) strlen(pr); } else { @@ -460,7 +461,7 @@ static int cmd_ichar(constant char *cs, size_t clen) /* * Reprint the tail of the line from the inserted char. */ - updown_match = -1; + have_updown_match = FALSE; cmd_repaint(cp); cmd_right(); return (CC_OK); @@ -503,7 +504,7 @@ static int cmd_erase(void) /* * Repaint the buffer after the erased char. */ - updown_match = -1; + have_updown_match = FALSE; cmd_repaint(cp); /* @@ -596,7 +597,7 @@ static int cmd_kill(void) cmd_offset = 0; cmd_home(); *cp = '\0'; - updown_match = -1; + have_updown_match = FALSE; cmd_repaint(cp); /* @@ -643,8 +644,11 @@ static int cmd_updown(int action) return (CC_OK); } - if (updown_match < 0) + if (!have_updown_match) + { updown_match = ptr_diff(cp, cmdbuf); + have_updown_match = TRUE; + } /* * Find the next history entry which matches. diff --git a/command.c b/command.c index f7e72f84..67c6d2d5 100644 --- a/command.c +++ b/command.c @@ -920,8 +920,9 @@ public void dispversion(void) /* * Return a character to complete a partial command, if possible. */ -static LWCHAR getcc_end_command(void) +static char getcc_end_command(void) { + int ch; switch (mca) { case A_DIGIT: @@ -934,7 +935,11 @@ static LWCHAR getcc_end_command(void) return ('\n'); default: /* Some other incomplete command. Let user complete it. */ - return ((ungot == NULL) ? getchr() : 0); + if (ungot != NULL) + return ('\0'); + ch = getchr(); + if (ch < 0) ch = '\0'; + return (char) ch; } } @@ -969,7 +974,7 @@ public void getcc_clear(void) */ static char getccu(void) { - char c = 0; + int c = 0; while (c == 0) { if (ungot == NULL) @@ -977,6 +982,7 @@ static char getccu(void) /* Normal case: no ungotten chars. * Get char from the user. */ c = getchr(); + if (c < 0) return ('\0'); } else { /* Ungotten chars available: @@ -998,7 +1004,7 @@ static char getcc_repl(char constant *orig, char constant *repl, char (*gr_getc) { char c; char keys[16]; - int ki = 0; + size_t ki = 0; c = (*gr_getc)(); if (orig == NULL || orig[0] == '\0') @@ -1033,7 +1039,7 @@ static char getcc_repl(char constant *orig, char constant *repl, char (*gr_getc) /* * Get command character. */ -public LWCHAR getcc(void) +public char getcc(void) { /* Replace kent (keypad Enter) with a newline. */ return getcc_repl(kent, "\n", getccu, ungetcc); diff --git a/cvt.c b/cvt.c index 04ed303e..0f3a87b1 100644 --- a/cvt.c +++ b/cvt.c @@ -82,7 +82,7 @@ public void cvt_text(char *odst, constant char *osrc, int *chpos, size_t *lenp, { if (ansi_step(pansi, ch) != ANSI_MID) break; - ch = *src++; + ch = (LWCHAR) *src++; /* {{ would step_char work? }} */ } ansi_done(pansi); } else diff --git a/decode.c b/decode.c index cadb0410..e5206b1f 100644 --- a/decode.c +++ b/decode.c @@ -281,7 +281,7 @@ static void expand_special_keys(unsigned char *table, size_t len) if (repl == NULL || strlen(repl) > klen) repl = "\377"; while (*repl != '\0') - *to++ = *repl++; + *to++ = (unsigned char) *repl++; /*{{type-issue}}*/ } *to++ = '\0'; /* diff --git a/evar.c b/evar.c index 33560998..27461163 100644 --- a/evar.c +++ b/evar.c @@ -144,14 +144,14 @@ static size_t add_evar(struct xbuffer *xbuf, mutable char *buf, size_t len, size { constant char *repl = find_replace(replaces, evar, &v); if (repl == NULL) - xbuf_add_byte(xbuf, evar[v++]); + xbuf_add_char(xbuf, evar[v++]); else { size_t r; for (r = 0; repl[r] != '\0'; r++) { if (repl[r] == '\\') ++r; - xbuf_add_byte(xbuf, repl[r]); + xbuf_add_char(xbuf, repl[r]); } } } @@ -186,7 +186,7 @@ public void expand_evars(mutable char *buf, size_t len, struct xbuffer *xbuf) i = add_evar(xbuf, buf, len, e, evar, term); } else { - xbuf_add_byte(xbuf, buf[i++]); + xbuf_add_char(xbuf, buf[i++]); } } } diff --git a/filename.c b/filename.c index 0e5763d9..5b0517f7 100644 --- a/filename.c +++ b/filename.c @@ -514,7 +514,7 @@ static char * readfd(FILE *fd) int ch; if ((ch = getc(fd)) == '\n' || ch == EOF) break; - xbuf_add_char(&xbuf, ch); + xbuf_add_char(&xbuf, (char) ch); } xbuf_add_char(&xbuf, '\0'); return (char *) xbuf.data; diff --git a/input.c b/input.c index d99996de..1ac4a722 100644 --- a/input.c +++ b/input.c @@ -151,7 +151,7 @@ public POSITION forw_line_seg(POSITION curr_pos, lbool skipeol, lbool rscroll, l null_line(); return (NULL_POSITION); } - backchars = pappend(c, new_pos); + backchars = pappend((char) c, new_pos); new_pos++; if (backchars > 0) { @@ -161,7 +161,7 @@ public POSITION forw_line_seg(POSITION curr_pos, lbool skipeol, lbool rscroll, l do { new_pos++; - c = ch_forw_get(); + c = ch_forw_get(); /* {{ what if c == EOI? }} */ } while (c == ' ' || c == '\t'); backchars = 1; } @@ -214,7 +214,7 @@ public POSITION forw_line_seg(POSITION curr_pos, lbool skipeol, lbool rscroll, l /* * Append the char to the line and get the next char. */ - backchars = pappend(c, ch_tell()-1); + backchars = pappend((char) c, ch_tell()-1); if (backchars > 0) { /* @@ -250,10 +250,10 @@ public POSITION forw_line_seg(POSITION curr_pos, lbool skipeol, lbool rscroll, l do { new_pos = ch_tell(); - c = ch_forw_get(); + c = ch_forw_get(); /* {{ what if c == EOI? }} */ } while (c == ' ' || c == '\t'); if (c == '\r') - c = ch_forw_get(); + c = ch_forw_get(); /* {{ what if c == EOI? }} */ if (c == '\n') new_pos = ch_tell(); } else if (wrap_pos == NULL_POSITION) @@ -373,6 +373,7 @@ public POSITION back_line(POSITION curr_pos) */ (void) ch_forw_get(); /* Skip the newline */ c = ch_forw_get(); /* First char of "current" line */ + /* {{ what if c == EOI? }} */ (void) ch_back_get(); /* Restore our position */ (void) ch_back_get(); @@ -467,7 +468,7 @@ public POSITION back_line(POSITION curr_pos) edisp_pos = new_pos; break; } - backchars = pappend(c, ch_tell()-1); + backchars = pappend((char) c, ch_tell()-1); if (backchars > 0) { /* @@ -494,14 +495,14 @@ public POSITION back_line(POSITION curr_pos) { for (;;) { - c = ch_forw_get(); + c = ch_forw_get(); /* {{ what if c == EOI? }} */ if (c == ' ' || c == '\t') new_pos++; else { if (c == '\r') { - c = ch_forw_get(); + c = ch_forw_get(); /* {{ what if c == EOI? }} */ if (c == '\n') new_pos++; } diff --git a/less.h b/less.h index f3e3b050..6afa97e9 100644 --- a/less.h +++ b/less.h @@ -77,8 +77,8 @@ * These substitutes for C23 stdckdint macros do not set *R on overflow, * and they assume A and B are nonnegative. That is good enough for us. */ -#define ckd_add(r, a, b) help_ckd_add(r, a, b, sizeof *(r), signed_expr(*(r))) -#define ckd_mul(r, a, b) help_ckd_mul(r, a, b, sizeof *(r), signed_expr(*(r))) +#define ckd_add(r, a, b) help_ckd_add(r, (uintmax)(a), (uintmax)(b), sizeof *(r), signed_expr(*(r))) +#define ckd_mul(r, a, b) help_ckd_mul(r, (uintmax)(a), (uintmax)(b), sizeof *(r), signed_expr(*(r))) /* True if the integer expression E, after promotion, is signed. */ #define signed_expr(e) ((TRUE ? 0 : e) - 1 < 0) #endif @@ -144,15 +144,15 @@ void free(); #define TO_LOWER(c) towlower(c) #else #if HAVE_UPPER_LOWER -#define IS_UPPER(c) isupper((unsigned char) (c)) -#define IS_LOWER(c) islower((unsigned char) (c)) -#define TO_UPPER(c) toupper((unsigned char) (c)) -#define TO_LOWER(c) tolower((unsigned char) (c)) +#define IS_UPPER(c) (is_ascii_char(c) && isupper((unsigned char) (c))) +#define IS_LOWER(c) (is_ascii_char(c) && islower((unsigned char) (c))) +#define TO_UPPER(c) (is_ascii_char(c) ? toupper((unsigned char) (c)) : (c)) +#define TO_LOWER(c) (is_ascii_char(c) ? tolower((unsigned char) (c)) : (c)) #else -#define IS_UPPER(c) ASCII_IS_UPPER(c) -#define IS_LOWER(c) ASCII_IS_LOWER(c) -#define TO_UPPER(c) ASCII_TO_UPPER(c) -#define TO_LOWER(c) ASCII_TO_LOWER(c) +#define IS_UPPER(c) (is_ascii_char(c) && ASCII_IS_UPPER(c)) +#define IS_LOWER(c) (is_ascii_char(c) && ASCII_IS_LOWER(c)) +#define TO_UPPER(c) (is_ascii_char(c) ? ASCII_TO_UPPER(c) : (c)) +#define TO_LOWER(c) (is_ascii_char(c) ? ASCII_TO_LOWER(c) : (c)) #endif #endif diff --git a/line.c b/line.c index 3f887b77..12bb381e 100644 --- a/line.c +++ b/line.c @@ -200,7 +200,7 @@ static int expand_linebuf(void) /* * Is a character ASCII? */ -public int is_ascii_char(LWCHAR ch) +public lbool is_ascii_char(LWCHAR ch) { return (ch <= 0x7F); } @@ -381,13 +381,13 @@ public void plinestart(POSITION pos) * Return the width of the line prefix (status column and line number). * {{ Actual line number can be wider than linenum_width. }} */ -public size_t line_pfx_width(void) +public int line_pfx_width(void) { - size_t width = 0; + int width = 0; if (status_col) - width += (size_t) status_col_width; /*{{type-issue}}*/ + width += status_col_width; if (linenums == OPT_ONPLUS) - width += (size_t) linenum_width + 1; /*{{type-issue}}*/ + width += linenum_width + 1; return width; } diff --git a/lsystem.c b/lsystem.c index 72c86c1c..721f6c11 100644 --- a/lsystem.c +++ b/lsystem.c @@ -247,7 +247,7 @@ public void lsystem(constant char *cmd, constant char *donemsg) * If the mark is on the current screen, or if the mark is ".", * the whole current screen is piped. */ -public int pipe_mark(int c, constant char *cmd) +public int pipe_mark(char c, constant char *cmd) { POSITION mpos, tpos, bpos; diff --git a/mark.c b/mark.c index f257af93..6a10c630 100644 --- a/mark.c +++ b/mark.c @@ -311,7 +311,7 @@ public POSITION markpos(char c) */ public char posmark(POSITION pos) { - int i; + unsigned char i; /* Only user marks */ for (i = 0; i < NUMARKS; i++) diff --git a/option.c b/option.c index 83e4b8a3..52d015db 100644 --- a/option.c +++ b/option.c @@ -48,7 +48,7 @@ static constant char * opt_desc(struct loption *o) * Return a string suitable for printing as the "name" of an option. * For example, if the option letter is 'x', just return "-x". */ -public constant char * propt(int c) +public constant char * propt(char c) { static char buf[MAX_PRCHAR_LEN+2]; diff --git a/search.c b/search.c index 2a433c9d..5c94d654 100644 --- a/search.c +++ b/search.c @@ -138,9 +138,9 @@ static lbool is_ucase(constant char *str) { ch = step_charc(&str, +1, str_end); if (IS_UPPER(ch)) - return (1); + return (TRUE); } - return (0); + return (FALSE); } /*