Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 compute anonymous bitfield sizes properly.



details:   https://anonhg.NetBSD.org/src/rev/a333358ee0a1
branches:  trunk
changeset: 347387:a333358ee0a1
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Aug 23 16:42:55 2016 +0000

description:
compute anonymous bitfield sizes properly.

diffstat:

 usr.bin/xlint/lint1/decl.c |  29 +++++++++++++++++++----------
 1 files changed, 19 insertions(+), 10 deletions(-)

diffs (64 lines):

diff -r e90c7f91886e -r a333358ee0a1 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Tue Aug 23 16:03:45 2016 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Tue Aug 23 16:42:55 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.64 2016/08/19 11:51:27 christos Exp $ */
+/* $NetBSD: decl.c,v 1.65 2016/08/23 16:42:55 christos Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.64 2016/08/19 11:51:27 christos Exp $");
+__RCSID("$NetBSD: decl.c,v 1.65 2016/08/23 16:42:55 christos Exp $");
 #endif
 
 #include <sys/param.h>
@@ -486,6 +486,17 @@
        }
 }
 
+static size_t
+bitfieldsize(sym_t **mem)
+{
+       size_t len = (*mem)->s_type->t_flen;
+       while (*mem && (*mem)->s_type->t_isfield) {
+               len += (*mem)->s_type->t_flen;
+               *mem = (*mem)->s_nxt;
+       }
+       return ((len + INT_SIZE - 1) / INT_SIZE) * INT_SIZE;
+}
+
 static void
 setpackedsize(type_t *tp)
 {
@@ -500,14 +511,7 @@
                sp->size = 0;
                for (mem = sp->memb; mem != NULL; mem = mem->s_nxt) {
                        if (mem->s_type->t_isfield) {
-                               size_t len = mem->s_type->t_flen;
-                               while (mem && mem->s_type->t_isfield) {
-                                       len += mem->s_type->t_flen;
-                                       mem = mem->s_nxt;
-                               }
-                               len = ((len + INT_SIZE - 1) /
-                                   INT_SIZE) * INT_SIZE;
-                               sp->size += len;
+                               sp->size += bitfieldsize(&mem);
                                if (mem == NULL)
                                        break;
                        }
@@ -1783,6 +1787,11 @@
                        /* bind anonymous members to the structure */
                        if (mem->s_styp == NULL) {
                                mem->s_styp = sp;
+                               if (mem->s_type->t_isfield) {
+                                       sp->size += bitfieldsize(&mem);
+                                       if (mem == NULL)
+                                               break;
+                               }
                                sp->size += tsize(mem->s_type);
                        }
                        if (mem->s_name != unnamed)



Home | Main Index | Thread Index | Old Index