> Synopsis: A struct containing just a single char apparently gets corrupted when passed as variable argument.
>Environment:
        System      : OpenBSD 7.3
Details : OpenBSD 7.3 (GENERIC.MP) #1178: Sat Mar 25 12:08:33 MDT 2023

dera...@powerpc64.openbsd.org:/usr/src/sys/arch/powerpc64/compile/GENERIC.MP

        Architecture: OpenBSD.powerpc64
        Machine     : powerpc64
>Description:
When running the regression test suite from the Small Device C Compiler, I found that a test (passing a tiny struct as a variable argument) fails on my OpenBSD 7.3 powerpc64 system. I do not know if other versions of OpenBSD or other architectures are affected.
>How-To-Repeat:
Compile the below C source via "cc test.c", invoke via "./a.out", see assertion fail ('assertion "x.c == 10" failed: file "test.c", line 31, function "f"').

// Test for OpenBSD issue based on a test in the SDCC regression test suite.

#include <assert.h>
#include <stdarg.h>

struct tiny
{
  char c;
};

void f (int n, ...);

void m (void)
{
  struct tiny x[3];
  x[0].c = 10;
  x[1].c = 11;
  x[2].c = 12;

  f (3, x[0], x[1], x[2], (long) 123);
}

void f (int n, ...)
{
        assert (n == 3);
        struct tiny x;
        
        va_list args;
        va_start(args, n);
        x = va_arg (args, struct tiny);
        assert (x.c == 10);
        x = va_arg (args, struct tiny);
        assert (x.c == 11);
        x = va_arg (args, struct tiny);
        assert (x.c == 12);

        assert (va_arg (args, long) == 123);

        va_end (args);
}

int main (void)
{
  m ();
  return (0);
}

Reply via email to