diff options
| author | Paul Eggert | 2020-08-11 02:16:54 -0700 |
|---|---|---|
| committer | Paul Eggert | 2020-08-11 02:27:44 -0700 |
| commit | 9e4e4775364490d31406f247237934dd7f203808 (patch) | |
| tree | e2fa77fb19ac3c6fa1f75f23adfb4b6519d27ee5 /src | |
| parent | eeaef1aec6d881f206a37c6e476fd94a5c289fc3 (diff) | |
| download | emacs-9e4e4775364490d31406f247237934dd7f203808.tar.gz emacs-9e4e4775364490d31406f247237934dd7f203808.zip | |
In pdumper, simplify INT_MAX computation
* src/pdumper.c (dump_read_all): Avoid unnecessary cast.
Also, round down to page size, as sysdep.c does.
Also, don’t assume INT_MAX <= UINT_MAX (!).
Diffstat (limited to 'src')
| -rw-r--r-- | src/pdumper.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/pdumper.c b/src/pdumper.c index 6d303af77d0..fcad5242dfe 100644 --- a/src/pdumper.c +++ b/src/pdumper.c | |||
| @@ -5065,14 +5065,13 @@ dump_read_all (int fd, void *buf, size_t bytes_to_read) | |||
| 5065 | { | 5065 | { |
| 5066 | /* We don't want to use emacs_read, since that relies on the lisp | 5066 | /* We don't want to use emacs_read, since that relies on the lisp |
| 5067 | world, and we're not in the lisp world yet. */ | 5067 | world, and we're not in the lisp world yet. */ |
| 5068 | eassert (bytes_to_read <= SSIZE_MAX); | ||
| 5069 | size_t bytes_read = 0; | 5068 | size_t bytes_read = 0; |
| 5070 | while (bytes_read < bytes_to_read) | 5069 | while (bytes_read < bytes_to_read) |
| 5071 | { | 5070 | { |
| 5072 | /* Some platforms accept only int-sized values to read. */ | 5071 | /* Some platforms accept only int-sized values to read. |
| 5073 | unsigned chunk_to_read = INT_MAX; | 5072 | Round this down to a page size (see MAX_RW_COUNT in sysdep.c). */ |
| 5074 | if (bytes_to_read - bytes_read < chunk_to_read) | 5073 | int max_rw_count = INT_MAX >> 18 << 18; |
| 5075 | chunk_to_read = (unsigned) (bytes_to_read - bytes_read); | 5074 | size_t chunk_to_read = min (bytes_to_read - bytes_read, max_rw_count); |
| 5076 | ssize_t chunk = read (fd, (char *) buf + bytes_read, chunk_to_read); | 5075 | ssize_t chunk = read (fd, (char *) buf + bytes_read, chunk_to_read); |
| 5077 | if (chunk < 0) | 5076 | if (chunk < 0) |
| 5078 | return chunk; | 5077 | return chunk; |