Module Name: src Committed By: christos Date: Fri Oct 2 21:49:30 UTC 2009
Modified Files: src/usr.bin/xlint/lint1: decl.c Log Message: handle bit fields in packed structures. To generate a diff of this commit: cvs rdiff -u -r1.50 -r1.51 src/usr.bin/xlint/lint1/decl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/xlint/lint1/decl.c diff -u src/usr.bin/xlint/lint1/decl.c:1.50 src/usr.bin/xlint/lint1/decl.c:1.51 --- src/usr.bin/xlint/lint1/decl.c:1.50 Fri Oct 2 17:04:03 2009 +++ src/usr.bin/xlint/lint1/decl.c Fri Oct 2 17:49:30 2009 @@ -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;