diff options
author | James McCoy <jamessan@jamessan.com> | 2016-10-09 20:56:51 -0400 |
---|---|---|
committer | James McCoy <jamessan@jamessan.com> | 2016-10-09 21:13:08 -0400 |
commit | 8fd12805d7cc6d043adfe325a274c2ac7580e0c6 (patch) | |
tree | d8d0ef9b39f545a27b198a2616f706001850ed72 /src | |
parent | 4192c411a84098fe64e5022cfed9b4549f9a8c87 (diff) | |
download | rneovim-8fd12805d7cc6d043adfe325a274c2ac7580e0c6.tar.gz rneovim-8fd12805d7cc6d043adfe325a274c2ac7580e0c6.tar.bz2 rneovim-8fd12805d7cc6d043adfe325a274c2ac7580e0c6.zip |
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/if_cscope.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c index 3ed85677fc..f89dd2d473 100644 --- a/src/nvim/if_cscope.c +++ b/src/nvim/if_cscope.c @@ -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) { |