Mercurial > vim
changeset 13493:96de13023cad v8.0.1620
patch 8.0.1620: reading spell file has no good EOF detection
commit https://github.com/vim/vim/commit/e26e0d2b83c2875b9829b884c2ababf8ca771f7e
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Mar 20 12:34:04 2018 +0100
patch 8.0.1620: reading spell file has no good EOF detection
Problem: Reading spell file has no good EOF detection.
Solution: Check for EOF at every character read for a length field.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 20 Mar 2018 12:45:05 +0100 |
parents | b774e8e6ea1d |
children | 3f7f1579151c |
files | src/misc2.c src/version.c |
diffstat | 2 files changed, 38 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/misc2.c +++ b/src/misc2.c @@ -6148,59 +6148,83 @@ filewritable(char_u *fname) #if defined(FEAT_SPELL) || defined(FEAT_PERSISTENT_UNDO) || defined(PROTO) /* * Read 2 bytes from "fd" and turn them into an int, MSB first. + * Returns -1 when encountering EOF. */ int get2c(FILE *fd) { - int n; + int c, n; n = getc(fd); - n = (n << 8) + getc(fd); - return n; + if (n == EOF) return -1; + c = getc(fd); + if (c == EOF) return -1; + return (n << 8) + c; } /* * Read 3 bytes from "fd" and turn them into an int, MSB first. + * Returns -1 when encountering EOF. */ int get3c(FILE *fd) { - int n; + int c, n; n = getc(fd); - n = (n << 8) + getc(fd); - n = (n << 8) + getc(fd); - return n; + if (n == EOF) return -1; + c = getc(fd); + if (c == EOF) return -1; + n = (n << 8) + c; + c = getc(fd); + if (c == EOF) return -1; + return (n << 8) + c; } /* * Read 4 bytes from "fd" and turn them into an int, MSB first. + * Returns -1 when encountering EOF. */ int get4c(FILE *fd) { + int c; /* Use unsigned rather than int otherwise result is undefined * when left-shift sets the MSB. */ unsigned n; - n = (unsigned)getc(fd); - n = (n << 8) + (unsigned)getc(fd); - n = (n << 8) + (unsigned)getc(fd); - n = (n << 8) + (unsigned)getc(fd); + c = getc(fd); + if (c == EOF) return -1; + n = (unsigned)c; + c = getc(fd); + if (c == EOF) return -1; + n = (n << 8) + (unsigned)c; + c = getc(fd); + if (c == EOF) return -1; + n = (n << 8) + (unsigned)c; + c = getc(fd); + if (c == EOF) return -1; + n = (n << 8) + (unsigned)c; return (int)n; } /* * Read 8 bytes from "fd" and turn them into a time_T, MSB first. + * Returns -1 when encountering EOF. */ time_T get8ctime(FILE *fd) { + int c; time_T n = 0; int i; for (i = 0; i < 8; ++i) - n = (n << 8) + getc(fd); + { + c = getc(fd); + if (c == EOF) return -1; + n = (n << 8) + c; + } return n; }