about summary refs log tree commit diff
path: root/src/stdio/fputs.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2014-09-04 22:21:17 -0400
committerRich Felker <dalias@aerifal.cx>2015-03-30 01:15:44 -0400
commitf071365e66174937ffcb68c103e68573ce7dfd13 (patch)
tree25c8d41e51e721c69f51167af1a30930da7b5f63 /src/stdio/fputs.c
parent6d14779eabec925c3977584d5dfd52778047b856 (diff)
downloadmusl-f071365e66174937ffcb68c103e68573ce7dfd13.tar.gz
musl-f071365e66174937ffcb68c103e68573ce7dfd13.tar.xz
musl-f071365e66174937ffcb68c103e68573ce7dfd13.zip
fix multiple stdio functions' behavior on zero-length operations
previously, fgets, fputs, fread, and fwrite completely omitted locking
and access to the FILE object when their arguments yielded a zero
length read or write operation independent of the FILE state. this
optimization was invalid; it wrongly skipped marking the stream as
byte-oriented (a C conformance bug) and exposed observably missing
synchronization (a POSIX conformance bug) where one of these functions
could wrongly complete despite another thread provably holding the
lock.

(cherry picked from commit 6e2bb7acf42589fb7130b039d0623e2ca42503dd)
Diffstat (limited to 'src/stdio/fputs.c')
-rw-r--r--src/stdio/fputs.c4
1 files changed, 1 insertions, 3 deletions
diff --git a/src/stdio/fputs.c b/src/stdio/fputs.c
index 1112b192..4737f448 100644
--- a/src/stdio/fputs.c
+++ b/src/stdio/fputs.c
@@ -3,9 +3,7 @@
 
 int fputs(const char *restrict s, FILE *restrict f)
 {
-	size_t l = strlen(s);
-	if (!l) return 0;
-	return (int)fwrite(s, l, 1, f) - 1;
+	return (int)fwrite(s, strlen(s), 1, f) - 1;
 }
 
 weak_alias(fputs, fputs_unlocked);