Skip to content

Commit

Permalink
Fix some char type confusion.
Browse files Browse the repository at this point in the history
Chars returned from get_cc* are single byte chars, not LWCHARs.
  • Loading branch information
gwsw committed Nov 14, 2023
1 parent 8992745 commit 2a79e5c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 33 deletions.
4 changes: 2 additions & 2 deletions cmdbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ public void cmd_accept(void)
* CC_OK Line edit function done.
* CC_QUIT The char requests the current command to be aborted.
*/
static int cmd_edit(int c)
static int cmd_edit(char c)
{
int action;
int flags;
Expand Down Expand Up @@ -1185,7 +1185,7 @@ static int cmd_complete(int action)
* CC_QUIT The char requests the command to be aborted.
* CC_ERROR The char could not be accepted due to an error.
*/
public int cmd_char(int c)
public int cmd_char(char c)
{
int action;
size_t len;
Expand Down
44 changes: 22 additions & 22 deletions command.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static char pipec;
/* Stack of ungotten chars (via ungetcc) */
struct ungot {
struct ungot *ug_next;
LWCHAR ug_char;
char ug_char;
};
static struct ungot* ungot = NULL;

Expand Down Expand Up @@ -326,23 +326,23 @@ static void exec_mca(void)
/*
* Is a character an erase or kill char?
*/
static int is_erase_char(LWCHAR c)
static int is_erase_char(char c)
{
return (c == erase_char || c == erase2_char || c == kill_char);
}

/*
* Is a character a carriage return or newline?
*/
static int is_newline_char(LWCHAR c)
static int is_newline_char(char c)
{
return (c == '\n' || c == '\r');
}

/*
* Handle the first char of an option (after the initial dash).
*/
static int mca_opt_first_char(LWCHAR c)
static int mca_opt_first_char(char c)
{
int no_prompt = (optflag & OPT_NO_PROMPT);
int flag = (optflag & ~OPT_NO_PROMPT);
Expand Down Expand Up @@ -393,7 +393,7 @@ static int mca_opt_first_char(LWCHAR c)
* If so, display the complete name and stop
* accepting chars until user hits RETURN.
*/
static int mca_opt_nonfirst_char(LWCHAR c)
static int mca_opt_nonfirst_char(char c)
{
constant char *p;
constant char *oname;
Expand Down Expand Up @@ -447,7 +447,7 @@ static int mca_opt_nonfirst_char(LWCHAR c)
/*
* Handle a char of an option toggle command.
*/
static int mca_opt_char(LWCHAR c)
static int mca_opt_char(char c)
{
PARG parg;

Expand Down Expand Up @@ -525,7 +525,7 @@ public int norm_search_type(int st)
/*
* Handle a char of a search command.
*/
static int mca_search_char(LWCHAR c)
static int mca_search_char(char c)
{
int flag = 0;

Expand Down Expand Up @@ -594,7 +594,7 @@ static int mca_search_char(LWCHAR c)
/*
* Handle a character of a multi-character command.
*/
static int mca_char(LWCHAR c)
static int mca_char(char c)
{
int ret;

Expand Down Expand Up @@ -940,10 +940,10 @@ static LWCHAR getcc_end_command(void)
/*
* Get a command character from the ungotten stack.
*/
static LWCHAR get_ungot(void)
static char get_ungot(void)
{
struct ungot *ug = ungot;
LWCHAR c = ug->ug_char;
char c = ug->ug_char;
ungot = ug->ug_next;
free(ug);
return c;
Expand All @@ -964,9 +964,9 @@ public void getcc_clear(void)
* but may come from ungotten characters
* (characters previously given to ungetcc or ungetsc).
*/
static LWCHAR getccu(void)
static char getccu(void)
{
LWCHAR c = 0;
char c = 0;
while (c == 0)
{
if (ungot == NULL)
Expand All @@ -990,10 +990,10 @@ static LWCHAR getccu(void)
* Get a command character, but if we receive the orig sequence,
* convert it to the repl sequence.
*/
static LWCHAR getcc_repl(char constant *orig, char constant *repl, LWCHAR (*gr_getc)(void), void (*gr_ungetc)(LWCHAR))
static char getcc_repl(char constant *orig, char constant *repl, char (*gr_getc)(void), void (*gr_ungetc)(char))
{
LWCHAR c;
LWCHAR keys[16];
char c;
char keys[16];
int ki = 0;

c = (*gr_getc)();
Expand Down Expand Up @@ -1039,7 +1039,7 @@ public LWCHAR getcc(void)
* "Unget" a command character.
* The next getcc() will return this character.
*/
public void ungetcc(LWCHAR c)
public void ungetcc(char c)
{
struct ungot *ug = (struct ungot *) ecalloc(1, sizeof(struct ungot));

Expand All @@ -1052,7 +1052,7 @@ public void ungetcc(LWCHAR c)
* "Unget" a command character.
* If any other chars are already ungotten, put this one after those.
*/
public void ungetcc_back(LWCHAR c)
public void ungetcc_back(char c)
{
struct ungot *ug = (struct ungot *) ecalloc(1, sizeof(struct ungot));
ug->ug_char = c;
Expand Down Expand Up @@ -1081,9 +1081,9 @@ public void ungetsc(constant char *s)
/*
* Peek the next command character, without consuming it.
*/
public LWCHAR peekcc(void)
public char peekcc(void)
{
LWCHAR c = getcc();
char c = getcc();
ungetcc(c);
return c;
}
Expand Down Expand Up @@ -1230,7 +1230,7 @@ static int forw_loop(int until_hilite)
*/
public void commands(void)
{
LWCHAR c;
char c;
int action;
constant char *cbuf;
constant char *msg;
Expand Down Expand Up @@ -1347,7 +1347,7 @@ public void commands(void)
* want erase_char/kill_char to be treated
* as line editing characters.
*/
char tbuf[2] = { (char) c, '\0' }; /*{{char-issue}}*/
constant char tbuf[2] = { c, '\0' };
action = fcmd_decode(tbuf, &extra);
}
/*
Expand Down Expand Up @@ -2026,7 +2026,7 @@ public void commands(void)
c = '.';
if (badmark(c))
break;
pipec = (char) c;
pipec = c;
start_mca(A_PIPE, "!", ml_shell, 0);
c = getcc();
goto again;
Expand Down
2 changes: 1 addition & 1 deletion decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ static void add_content_table(int (*call_lesskey)(constant char *, lbool), const
/*
* See if a char is a special line-editing command.
*/
public int editchar(int c, int flags)
public int editchar(char c, int flags)
{
int action;
int nch;
Expand Down
2 changes: 1 addition & 1 deletion less.h
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ typedef enum {
#define ESC CONTROL('[')
#define ESCS "\33"
#define CSI ((unsigned char)'\233')
#define CHAR_END_COMMAND 0x40000000
#define CHAR_END_COMMAND ((char)0377) /*{{ Is this safe? }}*/

#if _OSK_MWC32
#define LSIGNAL(sig,func) os9_signal(sig,func)
Expand Down
14 changes: 7 additions & 7 deletions mark.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static void mark_get_ifile(struct mark *m)
/*
* Return the user mark struct identified by a character.
*/
static struct mark * getumark(LWCHAR c)
static struct mark * getumark(char c)
{
PARG parg;
if (c >= 'a' && c <= 'z')
Expand All @@ -125,7 +125,7 @@ static struct mark * getumark(LWCHAR c)
* The mark struct may either be in the mark table (user mark)
* or may be constructed on the fly for certain characters like ^, $.
*/
static struct mark * getmark(LWCHAR c)
static struct mark * getmark(char c)
{
struct mark *m;
static struct mark sm;
Expand Down Expand Up @@ -185,15 +185,15 @@ static struct mark * getmark(LWCHAR c)
/*
* Is a mark letter invalid?
*/
public int badmark(LWCHAR c)
public int badmark(char c)
{
return (getmark(c) == NULL);
}

/*
* Set a user-defined mark.
*/
public void setmark(LWCHAR c, int where)
public void setmark(char c, int where)
{
struct mark *m;
struct scrpos scrpos;
Expand All @@ -214,7 +214,7 @@ public void setmark(LWCHAR c, int where)
/*
* Clear a user-defined mark.
*/
public void clrmark(LWCHAR c)
public void clrmark(char c)
{
struct mark *m;

Expand Down Expand Up @@ -249,7 +249,7 @@ public void lastmark(void)
/*
* Go to a mark.
*/
public void gomark(LWCHAR c)
public void gomark(char c)
{
struct mark *m;
struct scrpos scrpos;
Expand Down Expand Up @@ -290,7 +290,7 @@ public void gomark(LWCHAR c)
* is associated with, but this doesn't matter much,
* because it's always the first non-blank line on the screen.
*/
public POSITION markpos(LWCHAR c)
public POSITION markpos(char c)
{
struct mark *m;

Expand Down

1 comment on commit 2a79e5c

@avih
Copy link
Contributor

@avih avih commented on 2a79e5c Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit resulted in this warning in clang 17:

cmdbuf.c:1212:15: warning: result of comparison of constant 224 with expression of type 'char' is always false [-Wtautological-constant-out-of-range-compare]
 1212 |                         else if (c == (unsigned char) '\340' && IS_ASCII_OCTET(peekcc()))
      |                                  ~ ^  ~~~~~~~~~~~~~~~~~~~~~~

I'm guessing because char is signed, and both sides are converted to unsiged int for the comparison, and there's no char value which can result in 224 after such conversion?

(casting c to unsigned char should fix it)

Please sign in to comment.