diff --git a/usr.bin/xlint/lint1/decl.c b/usr.bin/xlint/lint1/decl.c index 08a0d1a2c8ee..25313c0e7297 100644 --- a/usr.bin/xlint/lint1/decl.c +++ b/usr.bin/xlint/lint1/decl.c @@ -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 #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 @@ -495,19 +495,26 @@ setpackedsize(type_t *tp) 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;