mirror of
https://github.com/fluencelabs/musl
synced 2025-04-24 23:02:14 +00:00
fix undefined behavior in memset due to missing sequence points
patch by Pascal Cuoq.
This commit is contained in:
parent
c7f56b4d2f
commit
9d4c902c42
@ -11,12 +11,16 @@ void *memset(void *dest, int c, size_t n)
|
|||||||
* offsets are well-defined and in the dest region. */
|
* offsets are well-defined and in the dest region. */
|
||||||
|
|
||||||
if (!n) return dest;
|
if (!n) return dest;
|
||||||
s[0] = s[n-1] = c;
|
s[0] = c;
|
||||||
|
s[n-1] = c;
|
||||||
if (n <= 2) return dest;
|
if (n <= 2) return dest;
|
||||||
s[1] = s[n-2] = c;
|
s[1] = c;
|
||||||
s[2] = s[n-3] = c;
|
s[2] = c;
|
||||||
|
s[n-2] = c;
|
||||||
|
s[n-3] = c;
|
||||||
if (n <= 6) return dest;
|
if (n <= 6) return dest;
|
||||||
s[3] = s[n-4] = c;
|
s[3] = c;
|
||||||
|
s[n-4] = c;
|
||||||
if (n <= 8) return dest;
|
if (n <= 8) return dest;
|
||||||
|
|
||||||
/* Advance pointer to align it at a 4-byte boundary,
|
/* Advance pointer to align it at a 4-byte boundary,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user