handle bit fields in packed structures.

This commit is contained in:
christos 2009-10-02 21:49:30 +00:00
parent 932cd15f91
commit 17b31cc3a2
1 changed files with 17 additions and 10 deletions

View File

@ -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 @@ 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;