Subject: lib/598: stdarg.h for m68k
To: None <gnats-admin@sun-lamp.cs.berkeley.edu>
From: Christian E. Hopps <chopps@NetBSD.ORG>
List: netbsd-bugs
Date: 11/29/1994 14:35:09
>Number: 598
>Category: lib
>Synopsis: stdarg.h incorrectly handles padding.
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: gnats-admin (Library Bug People)
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Nov 29 14:35:04 1994
>Originator: Christian E. Hopps
>Organization:
" "
>Release: 1.0
>Environment:
NetBSD sun-lamp.cs.berkeley.edu 1.0 NetBSD 1.0 (SUN_LAMP) (i386)
NetBSD water.emich.edu 1.0 NetBSD 1.0 (WATER) (m68k/amiga)
>Description:
Stdarg.h mishandles odd aligned structs passed by value.
>How-To-Repeat:
#include <assert.h>
#include <stdio.h>
#include <stdarg.h>
typedef struct {
char c;
} Cstruct;
static int tryit(const char *fmt, ...)
{
int ctr = 0;
va_list ap;
va_start(ap, fmt);
for (; *fmt; ++fmt)
switch (*fmt) {
case 'i':
assert(va_arg(ap, int) == ++ctr);
break;
case 'd':
assert(va_arg(ap, double) == ++ctr);
break;
case 'p':
assert(va_arg(ap, char *)[0] == ++ctr);
break;
case 's':
assert(va_arg(ap, Cstruct).c == ++ctr);
break;
}
va_end(ap);
return (ctr);
}
int main()
{
Cstruct x = {3};
assert(tryit("iisdi", '\1', 2, x, 4.0, 5) == 5);
assert(tryit("") == 0);
assert(tryit("pdp", "\1", 2.0, "\3") == 3);
printf("sizeof(va_list) == %u\n", sizeof(va_list));
puts("SUCCESS testing <stdarg.h>");
return (0);
}
>Fix:
Eventually.
>Audit-Trail:
>Unformatted: