diff options
author | Rich Felker <dalias@aerifal.cx> | 2016-02-10 19:44:19 -0500 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2016-02-10 19:44:19 -0500 |
commit | 500c6886c654fd45e4926990fee2c61d816be197 (patch) | |
tree | 8a46228b4a5880e3f1c57499ef92d123d51dbe07 /src | |
parent | 416d1c7a711807384cc21a18163475cf757bbcb5 (diff) | |
download | musl-500c6886c654fd45e4926990fee2c61d816be197.tar.gz musl-500c6886c654fd45e4926990fee2c61d816be197.tar.bz2 musl-500c6886c654fd45e4926990fee2c61d816be197.tar.xz musl-500c6886c654fd45e4926990fee2c61d816be197.zip |
fix return value for fread/fwrite when size argument is 0
when the size argument was zero but nmemb was nonzero, these functions
were returning nmemb, despite no data having been written.
conceptually this is not wrong, but the standard requires a return
value of zero in this case.
Diffstat (limited to 'src')
-rw-r--r-- | src/stdio/fread.c | 1 | ||||
-rw-r--r-- | src/stdio/fwrite.c | 1 |
2 files changed, 2 insertions, 0 deletions
diff --git a/src/stdio/fread.c b/src/stdio/fread.c index 33a65f58..aef75f73 100644 --- a/src/stdio/fread.c +++ b/src/stdio/fread.c @@ -7,6 +7,7 @@ size_t fread(void *restrict destv, size_t size, size_t nmemb, FILE *restrict f) { unsigned char *dest = destv; size_t len = size*nmemb, l = len, k; + if (!size) nmemb = 0; FLOCK(f); diff --git a/src/stdio/fwrite.c b/src/stdio/fwrite.c index fa30c0d3..7a567b2c 100644 --- a/src/stdio/fwrite.c +++ b/src/stdio/fwrite.c @@ -28,6 +28,7 @@ size_t __fwritex(const unsigned char *restrict s, size_t l, FILE *restrict f) size_t fwrite(const void *restrict src, size_t size, size_t nmemb, FILE *restrict f) { size_t k, l = size*nmemb; + if (!size) nmemb = 0; FLOCK(f); k = __fwritex(src, l, f); FUNLOCK(f); |