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 handle bit fields in packed structures.



details:   https://anonhg.NetBSD.org/src/rev/c54aa3a7d6f0
branches:  trunk
changeset: 747823:c54aa3a7d6f0
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Oct 02 21:49:30 2009 +0000

description:
handle bit fields in packed structures.

diffstat:

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

diffs (53 lines):

diff -r 99333523fccc -r c54aa3a7d6f0 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Fri Oct 02 21:47:35 2009 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Fri Oct 02 21:49:30 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.50 2009/10/02 21:04:03 christos Exp $ */
+/* $NetBSD: decl.c,v 1.51 2009/10/02 21:49:30 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.50 2009/10/02 21:04:03 christos Exp $");
+__RCSID("$NetBSD: decl.c,v 1.51 2009/10/02 21:49:30 christos Exp $");
 #endif
 
 #include <sys/param.h>
@@ -495,19 +495,26 @@
 
        switch (tp->t_tspec) {
        case STRUCT:
-               sp = tp->t_str;
-               sp->size = 0;
-               for (mem = sp->memb; mem != NULL; mem = mem->s_nxt) {
-                       size_t x = (size_t)tsize(mem->s_type);
-                       sp->size += x;
-               }
-               break;
        case UNION:
                sp = tp->t_str;
                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;
+                               if (mem == NULL)
+                                       break;
+                       }
                        size_t x = (size_t)tsize(mem->s_type);
-                       if (x > sp->size)
+                       if (tp->t_tspec == STRUCT)
+                               sp->size += x;
+                       else if (x > sp->size)
                                sp->size = x;
                }
                break;



Home | Main Index | Thread Index | Old Index