mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 14:38:32 +00:00
if_cscope: Fix conversion warnings when char defaults to unsigned
../src/nvim/if_cscope.c: In function 'cs_read_prompt': ../src/nvim/if_cscope.c:1771:47: warning: comparison is always true due to limited range of data type [-Wtype-limits] while ((ch = (char)getc(csinfo[i].fr_fp)) != EOF && ch != CSCOPE_PROMPT[0]) ^~ ../src/nvim/if_cscope.c:1804:14: warning: comparison is always false due to limited range of data type [-Wtype-limits] if (ch == EOF) { ^~ ../src/nvim/if_cscope.c:1816:14: warning: negative integer implicitly converted to unsigned type [-Wsign-conversion] ch = EOF; ^~~ ../src/nvim/if_cscope.c:1821:12: warning: comparison is always false due to limited range of data type [-Wtype-limits] if (ch == EOF) ^~ Since EOF is -1, it will be converted to a large unsigned value to compare with unsigned char and never match. Use an int to store the return from getc so we can safely compare it and, once known to be valid, cast it to char when storing it into buf. Signed-off-by: James McCoy <jamessan@jamessan.com>
This commit is contained in:
@@ -1761,7 +1761,7 @@ static void cs_print_tags_priv(char **matches, char **cntxts,
|
||||
*/
|
||||
static int cs_read_prompt(size_t i)
|
||||
{
|
||||
char ch;
|
||||
int ch;
|
||||
char *buf = NULL; /* buffer for possible error message from cscope */
|
||||
size_t bufpos = 0;
|
||||
char *cs_emsg = _("E609: Cscope error: %s");
|
||||
@@ -1774,7 +1774,7 @@ static int cs_read_prompt(size_t i)
|
||||
size_t maxlen = IOSIZE - cs_emsg_len;
|
||||
|
||||
for (;; ) {
|
||||
while ((ch = (char)getc(csinfo[i].fr_fp)) != EOF && ch != CSCOPE_PROMPT[0])
|
||||
while ((ch = getc(csinfo[i].fr_fp)) != EOF && ch != CSCOPE_PROMPT[0])
|
||||
/* if there is room and char is printable */
|
||||
if (bufpos < maxlen - 1 && vim_isprintc(ch)) {
|
||||
// lazy buffer allocation
|
||||
@@ -1783,7 +1783,7 @@ static int cs_read_prompt(size_t i)
|
||||
}
|
||||
{
|
||||
/* append character to the message */
|
||||
buf[bufpos++] = ch;
|
||||
buf[bufpos++] = (char)ch;
|
||||
buf[bufpos] = NUL;
|
||||
if (bufpos >= epromptlen
|
||||
&& strcmp(&buf[bufpos - epromptlen], eprompt) == 0) {
|
||||
|
Reference in New Issue
Block a user