vim-patch:8.2.1564: a few remaining errors from ubsan

Problem:    A few remaining errors from ubsan.
Solution:   Avoid the warnings. (Dominique Pellé, closes vim/vim#6837)
4ad739fc05
This commit is contained in:
Jan Edmund Lazo
2020-09-02 22:22:15 -04:00
parent b9430fe28e
commit 5fcdb63025
2 changed files with 10 additions and 8 deletions

View File

@@ -984,15 +984,17 @@ nextone:
static char_u *read_cnt_string(FILE *fd, int cnt_bytes, int *cntp)
{
int cnt = 0;
int i;
char_u *str;
// read the length bytes, MSB first
for (i = 0; i < cnt_bytes; ++i)
cnt = (cnt << 8) + getc(fd);
if (cnt < 0) {
*cntp = SP_TRUNCERROR;
return NULL;
for (int i = 0; i < cnt_bytes; i++) {
const int c = getc(fd);
if (c == EOF) {
*cntp = SP_TRUNCERROR;
return NULL;
}
cnt = (cnt << 8) + (unsigned)c;
}
*cntp = cnt;
if (cnt == 0)