musl - musl - an implementation of the standard library for Linux-based systems

index : musl
musl - an implementation of the standard library for Linux-based systems
summary refs log tree commit diff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2017年08月29日 19:53:50 -0400
committerRich Felker <dalias@aerifal.cx>2017年08月29日 19:53:50 -0400
commit9d4c902c42b3fda368d7ea64bb9575c46228fa7f (patch)
treea19cede317e71619d53be75fcd05baa89fccb077
parentc7f56b4d2f58714b7286ef12fa5410213847f2fe (diff)
downloadmusl-9d4c902c42b3fda368d7ea64bb9575c46228fa7f.tar.gz
fix undefined behavior in memset due to missing sequence points
patch by Pascal Cuoq.
Diffstat
-rw-r--r--src/string/memset.c 12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/string/memset.c b/src/string/memset.c
index f438b073..5613a148 100644
--- a/src/string/memset.c
+++ b/src/string/memset.c
@@ -11,12 +11,16 @@ void *memset(void *dest, int c, size_t n)
* offsets are well-defined and in the dest region. */
if (!n) return dest;
- s[0] = s[n-1] = c;
+ s[0] = c;
+ s[n-1] = c;
if (n <= 2) return dest;
- s[1] = s[n-2] = c;
- s[2] = s[n-3] = c;
+ s[1] = c;
+ s[2] = c;
+ s[n-2] = c;
+ s[n-3] = c;
if (n <= 6) return dest;
- s[3] = s[n-4] = c;
+ s[3] = c;
+ s[n-4] = c;
if (n <= 8) return dest;
/* Advance pointer to align it at a 4-byte boundary,
generated by cgit v1.2.1 (git 2.18.0) at 2025年09月06日 19:07:16 +0000

AltStyle によって変換されたページ (->オリジナル) /