mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Pascal Cuoq <cuoq@trust-in-soft.com>
To: "musl@lists.openwall.com" <musl@lists.openwall.com>
Subject: patch: sequence points in memset
Date: Mon, 10 Jul 2017 14:39:07 +0000	[thread overview]
Message-ID: <CF3F2019-214F-487B-A7DC-7E88B0F2D4A1@trust-in-soft.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 435 bytes --]

Following a recent discussion of statements shaped like x = x = c;, the attached patch introduces additional sequence points in musl's implementation of memset, because no realistic target platform benefits from the lack of sequence points in the current version, and if a hypothetical target (VLIW maybe?) was designed to benefit from the lack of sequence point, the lack of sequence point might just as well cause harm.

Pascal


[-- Attachment #2: memset_sp.patch --]
[-- Type: application/octet-stream, Size: 632 bytes --]

diff --git a/src/string/memset.c b/src/string/memset.c
index f438b07..5613a14 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,

             reply	other threads:[~2017-07-10 14:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-10 14:39 Pascal Cuoq [this message]
2017-07-10 15:10 ` Alexander Monakov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CF3F2019-214F-487B-A7DC-7E88B0F2D4A1@trust-in-soft.com \
    --to=cuoq@trust-in-soft.com \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).