read-file: reorganize to avoid various issues
authorPádraig Brady <P@draigBrady.com>
Mon, 13 Dec 2010 08:08:23 +0000 (08:08 +0000)
committerPádraig Brady <P@draigBrady.com>
Mon, 13 Dec 2010 22:18:45 +0000 (22:18 +0000)
commit5c84fa529cdf9f76cdc538d9a2113a6bb05afc40
tree1a17199f14e8fbe3859680cbbbb5859828d878b8
parent980f9d2ceb43f9d86ea57db0367e569267c8571b
read-file: reorganize to avoid various issues

* lib/read-file.c (fread_file): Read 1 more byte than is
currently in a regular file, to immediately detect EOF,
and thus avoid any realloc()s.  As well as being slower,
these may fail, thus artificially limiting the supported size.
Allocate up to SIZE_MAX for streams, rather than limiting
to about SIZE_MAX - SIZE_MAX/5.
Don't use the 'size + BUFSIZ + 1' expression, which
could overflow and cause invalid operation.
As a style decision, explicitly check for overflow rather
than using a temporary roll over variable (new_alloc).
ChangeLog
lib/read-file.c