mirror of
https://github.com/neovim/neovim.git
synced 2025-09-12 06:18:16 +00:00
Enable and fix misc2.c -Wconversion warnings #907
This commit is contained in:

committed by
Justin M. Keyes

parent
fa1d9301f7
commit
d61829dd06
@@ -44,7 +44,7 @@ set(CONV_SRCS
|
|||||||
log.c
|
log.c
|
||||||
map.c
|
map.c
|
||||||
memory.c
|
memory.c
|
||||||
map.c
|
misc2.c
|
||||||
os/env.c
|
os/env.c
|
||||||
os/event.c
|
os/event.c
|
||||||
os/job.c
|
os/job.c
|
||||||
|
@@ -488,28 +488,20 @@ time_t get8ctime(FILE *fd)
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/// Reads a string of length "cnt" from "fd" into allocated memory.
|
||||||
* Read a string of length "cnt" from "fd" into allocated memory.
|
/// @return pointer to the string or NULL when unable to read that many bytes.
|
||||||
* Returns NULL when unable to read that many bytes.
|
char *read_string(FILE *fd, size_t cnt)
|
||||||
*/
|
|
||||||
char_u *read_string(FILE *fd, int cnt)
|
|
||||||
{
|
{
|
||||||
int i;
|
uint8_t *str = xmallocz(cnt);
|
||||||
int c;
|
for (size_t i = 0; i < cnt; i++) {
|
||||||
|
int c = getc(fd);
|
||||||
char_u *str = xmallocz(cnt);
|
|
||||||
/* Read the string. Quit when running into the EOF. */
|
|
||||||
for (i = 0; i < cnt; ++i) {
|
|
||||||
c = getc(fd);
|
|
||||||
if (c == EOF) {
|
if (c == EOF) {
|
||||||
free(str);
|
free(str);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
str[i] = c;
|
str[i] = (uint8_t)c;
|
||||||
}
|
}
|
||||||
str[i] = NUL;
|
return (char *)str;
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -3,7 +3,10 @@
|
|||||||
|
|
||||||
#include "nvim/os/shell.h"
|
#include "nvim/os/shell.h"
|
||||||
|
|
||||||
|
#define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
# include "misc2.h.generated.h"
|
# include "misc2.h.generated.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // NVIM_MISC2_H
|
#endif // NVIM_MISC2_H
|
||||||
|
@@ -2600,7 +2600,7 @@ spell_load_file (
|
|||||||
res = 0;
|
res = 0;
|
||||||
switch (n) {
|
switch (n) {
|
||||||
case SN_INFO:
|
case SN_INFO:
|
||||||
lp->sl_info = read_string(fd, len); // <infotext>
|
lp->sl_info = READ_STRING(fd, len); // <infotext>
|
||||||
if (lp->sl_info == NULL)
|
if (lp->sl_info == NULL)
|
||||||
goto endFAIL;
|
goto endFAIL;
|
||||||
break;
|
break;
|
||||||
@@ -2614,7 +2614,7 @@ spell_load_file (
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SN_MIDWORD:
|
case SN_MIDWORD:
|
||||||
lp->sl_midword = read_string(fd, len); // <midword>
|
lp->sl_midword = READ_STRING(fd, len); // <midword>
|
||||||
if (lp->sl_midword == NULL)
|
if (lp->sl_midword == NULL)
|
||||||
goto endFAIL;
|
goto endFAIL;
|
||||||
break;
|
break;
|
||||||
@@ -2640,7 +2640,7 @@ spell_load_file (
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SN_MAP:
|
case SN_MAP:
|
||||||
p = read_string(fd, len); // <mapstr>
|
p = READ_STRING(fd, len); // <mapstr>
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
goto endFAIL;
|
goto endFAIL;
|
||||||
set_map_str(lp, p);
|
set_map_str(lp, p);
|
||||||
@@ -2668,7 +2668,7 @@ spell_load_file (
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SN_SYLLABLE:
|
case SN_SYLLABLE:
|
||||||
lp->sl_syllable = read_string(fd, len); // <syllable>
|
lp->sl_syllable = READ_STRING(fd, len); // <syllable>
|
||||||
if (lp->sl_syllable == NULL)
|
if (lp->sl_syllable == NULL)
|
||||||
goto endFAIL;
|
goto endFAIL;
|
||||||
if (init_syl_tab(lp) == FAIL)
|
if (init_syl_tab(lp) == FAIL)
|
||||||
@@ -2764,7 +2764,7 @@ static char_u *read_cnt_string(FILE *fd, int cnt_bytes, int *cntp)
|
|||||||
if (cnt == 0)
|
if (cnt == 0)
|
||||||
return NULL; // nothing to read, return NULL
|
return NULL; // nothing to read, return NULL
|
||||||
|
|
||||||
str = read_string(fd, cnt);
|
str = READ_STRING(fd, cnt);
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
*cntp = SP_OTHERERROR;
|
*cntp = SP_OTHERERROR;
|
||||||
return str;
|
return str;
|
||||||
|
@@ -916,7 +916,7 @@ static u_entry_T *unserialize_uep(FILE *fp, int *error, char_u *file_name)
|
|||||||
for (i = 0; i < uep->ue_size; ++i) {
|
for (i = 0; i < uep->ue_size; ++i) {
|
||||||
line_len = get4c(fp);
|
line_len = get4c(fp);
|
||||||
if (line_len >= 0)
|
if (line_len >= 0)
|
||||||
line = read_string(fp, line_len);
|
line = READ_STRING(fp, line_len);
|
||||||
else {
|
else {
|
||||||
line = NULL;
|
line = NULL;
|
||||||
corruption_error("line length", file_name);
|
corruption_error("line length", file_name);
|
||||||
@@ -1316,7 +1316,7 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name)
|
|||||||
if (str_len < 0)
|
if (str_len < 0)
|
||||||
goto error;
|
goto error;
|
||||||
if (str_len > 0)
|
if (str_len > 0)
|
||||||
line_ptr = read_string(fp, str_len);
|
line_ptr = READ_STRING(fp, str_len);
|
||||||
line_lnum = (linenr_T)get4c(fp);
|
line_lnum = (linenr_T)get4c(fp);
|
||||||
line_colnr = (colnr_T)get4c(fp);
|
line_colnr = (colnr_T)get4c(fp);
|
||||||
if (line_lnum < 0 || line_colnr < 0) {
|
if (line_lnum < 0 || line_colnr < 0) {
|
||||||
|
Reference in New Issue
Block a user