Bug#442854: hex-a-hop: [m68k] FTBFS: packfile.h:57: error: size of array 'static_assert1' is negative
Hi,
the following message didn't reached the list (even after correction
of the wrong email address) so I resend it ...
Please keep 442854@bugs.debian.org in CC:.
----- Forwarded message from Jens Seidel <jensseidel@users.sf.net> -----
From: Jens Seidel <jensseidel@users.sf.net>
Subject: Re: Bug#442854: hex-a-hop: [m68k] FTBFS: packfile.h:57: error: size of array 'static_assert1' is negative
To: Bas Wijnen <wijnen@debian.org>, 442854@bugs.debian.org,
debian-68k@bugs.debian.org
Date: Tue, 18 Sep 2007 11:45:31 +0200
Hi m68k porters!
Could you please help me resolving a problem on the m68k architecture?
I'm the maintainer of hex-a-hop, a funny SDL game, which was mainly
written for i386. During my attempts to make it big endian clean I also
added a static assert test which aim was to check for proper alignment
of a data structure.
I think my test sizeof(Entry)==8 is wrong as it failed on m68k.
Nevertheless I'm nearly sure that this platform doesn't align a char[1]
array on 64 bit boundaries so the code should work :-)
Some parts of the code need to rewritten to properly support all (or at
least more) architectures. But for now I just want to know whether the
current code works.
Can someone please compile and start the attached C program? It just
collects some basic system properties such as sizeof() and tests the
suspicious code fragment. Please send me the output.
You may also directly test hex-a-hop, except the affected test
sizeof(Entry)==8 (I suggest to comment this line out in
debian/patches/endianess.patch) it should compile and run fine (I hope).
On Mon, Sep 17, 2007 at 03:34:25PM +0200, Jens Seidel wrote:
> On Mon, Sep 17, 2007 at 02:46:32PM +0200, Bas Wijnen wrote:
> > Package: hex-a-hop
> > Version: 0.0.20070315-5
> > Severity: Serious
> > Justification: FTBFS
> >
> > The package fails to build on m68k, see
> > http://buildd.debian.org/fetch.cgi?&pkg=hex-a-hop&ver=0.0.20070315-5&arch=m68k&stamp=1189827580&file=log
> >
> > g++ -Wall -W -g -DUSE_GETTEXT -O2 -D_VERSION=\"1.0.0\" -DDATA_DIR=\"/usr/share/games/hex-a-hop\" `sdl-config --cflags` -c -o hex_puzzzle.o hex_puzzzle.cpp
> > packfile.h:57: error: size of array 'static_assert1' is negative
> > http://lists.alioth.debian.org/mailman/listinfo/pkg-games-devel
>
> Oops, I explitely added this test and now I wonder whether I should be
> happy that this error was found or not :-)
>
> I do not have access to a m68k machine. Bas, could you please provide
I mean sizeof(Entry).
>
> The problem is that hex-a-hop reads a char data stream and interprets it as
Not an array but something as a list. At least it does a type conversion
on a char array which is bad style.
> an array of type Entry. I knew that this could cause trouble so I added the
Jens
#include <stdio.h>
#include <stdint.h>
#include <string.h>
typedef struct Entry {
int32_t len;
// could there be an alignment gap here?
char name[1];
} Entry;
int main(void) {
int *int_ptr;
void *void_ptr;
int (*funct_ptr)(void);
printf("sizeof(char): %ld bytes\n", sizeof(char));
printf("sizeof(short): %ld bytes\n", sizeof(short));
printf("sizeof(int): %ld bytes\n", sizeof(int));
printf("sizeof(long): %ld bytes\n", sizeof(long));
printf("sizeof(long long): %ld bytes\n", sizeof(long long));
printf("------------------------------\n");
printf("sizeof(float): %ld bytes\n", sizeof(float));
printf("sizeof(double): %ld bytes\n", sizeof(double));
printf("sizeof(long double): %ld bytes\n", sizeof(long double));
printf("------------------------------\n");
printf("sizeof(*int_ptr): %ld bytes\n", sizeof(int_ptr));
printf("sizeof(*void_ptr): %ld bytes\n", sizeof(void_ptr));
printf("sizeof(*funct_ptr): %ld bytes\n\n", sizeof(funct_ptr));
printf("sizeof(Entry): %ld bytes\n\n", sizeof(Entry));
char tmp[10];
int i;
for (i=0; i<10; ++i)
tmp[i] = i;
Entry *e = (Entry*)(&tmp[0]);
printf("e.len=%d, e.name[0]=%d\n", e->len, e->name[0]);
printf("Expected len (little endian): %d ", 0+1*(1<<8)+2*(1<<16)+3*(1<<24));
printf("(big endian): %d ", 3+2*(1<<8)+1*(1<<16)+0*(1<<24));
printf("name[0]: 4\n\n");
strcpy(e->name, "Hi\n");
for (i=0; i<10; ++i)
printf("%d ", tmp[i]);
printf("\n");
printf("Expected:\n0 1 2 3 72 105 10 0 8 9\n\n");
// Now try the same if *e is differently aligned (could be forbidden?)
Entry *e2 = (Entry*)(&tmp[1]);
printf("e2.len=%d, e2.name[0]=%d\n", e2->len, e2->name[0]);
printf("Expected len (little endian): %d ", 1+2*(1<<8)+3*(1<<16)+72*(1<<24));
printf("(big endian): %d ", 72+3*(1<<8)+2*(1<<16)+1*(1<<24));
printf("name[0]: 105\n\n");
strcpy(e2->name, "Hi\n");
for (i=0; i<10; ++i)
printf("%d ", tmp[i]);
printf("\n");
printf("Expected:\n0 1 2 3 72 72 105 10 0 9\n");
return 0;
}
----- End forwarded message -----
Reply to: