public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix BZ#5070
@ 2007-10-03  7:49 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2007-10-03  7:49 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Glibc hackers

Hi!

This patch should IMHO cure the weirdo struct layout problem on arm
while not pessimizing code on sane architectures (on x86_64-linux
the routine with this patch has minor differences in insn scheduling,
but it is the same size and same instructions, just reordered and it is
unclear what is more efficient if not equivalent).
On arm at least with cross compiler distilled testcase also passes
compile time assertion made from the assert and the memset looks good as
well.

2007-10-03  Jakub Jelinek  <jakub@redhat.com>

	[BZ #5070]
	* sysdeps/unix/sysv/linux/check_pf.c (make_request): Remove
	pad array from req, instead use offsetof and sizeof to clear
	padding.

--- libc/sysdeps/unix/sysv/linux/check_pf.c.jj	2007-09-02 19:09:33.000000000 +0200
+++ libc/sysdeps/unix/sysv/linux/check_pf.c	2007-10-03 09:26:18.000000000 +0200
@@ -54,10 +54,6 @@ make_request (int fd, pid_t pid, bool *s
   {
     struct nlmsghdr nlh;
     struct rtgenmsg g;
-    /* struct rtgenmsg consists of a single byte.  This means there
-       are three bytes of padding included in the REQ definition.
-       We make them explicit here.  */
-    char pad[3];
   } req;
   struct sockaddr_nl nladdr;
 
@@ -68,8 +64,11 @@ make_request (int fd, pid_t pid, bool *s
   req.nlh.nlmsg_seq = time (NULL);
   req.g.rtgen_family = AF_UNSPEC;
 
-  assert (sizeof (req) - offsetof (struct req, pad) == 3);
-  memset (req.pad, '\0', sizeof (req.pad));
+  assert (sizeof (req) - offsetof (struct req, g)
+	  - sizeof (req.g.rtgen_family) == 3);
+  memset (&req.g.rtgen_family + 1, '\0',
+	  sizeof (req) - offsetof (struct req, g)
+	  - sizeof (req.g.rtgen_family));
 
   memset (&nladdr, '\0', sizeof (nladdr));
   nladdr.nl_family = AF_NETLINK;

	Jakub

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-10-03  7:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-03  7:49 [PATCH] Fix BZ#5070 Jakub Jelinek

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 read-only IMAP folder(s) and NNTP newsgroup(s).