Test for the size of struct http_parser fails on 32 bit systems where there is padding/alignment for void*

Author: frmichaelCreated Nov 30, 2020Updated Dec 24, 2020

Bonjour,

Porting http-parser to AIX, where there are 32 and 64 bit environments, there is a test on sizeof (struct http_parser) which fails due to 8 byte reservation for void* on both 32 and 64 bit compiles.

A clean option might be to change the void data element of struct http_parser to be a union of uint64 and void.

But this may not work if the 32 bit size of struct http_parser must remain at a total of 28 bytes (and in which case the test is in correct).

However, supposing that this is an error in the test code, I provisionally used the following patch for the 32 bit build

--- ./test.c.ORIG       2020-11-27 22:02:53 +0100
+++ ./test.c    2020-11-27 22:57:18 +0100
@@ -4234,7 +4234,7 @@
   printf("http_parser v%u.%u.%u (0x%06lx)\n", major, minor, patch, version);
 
   printf("sizeof(http_parser) = %u\n", (unsigned int)sizeof(http_parser));
-  assert(sizeof(http_parser) == 4 + 4 + 8 + 2 + 2 + 4 + sizeof(void *));
+  assert(sizeof(http_parser) == 4 + 4 + 8 + 2 + 2 + 4 + 2*sizeof(void *));
 
   //// API
   test_preserve_data();

We would like to ask for your expert advice on how best to resolve this issue.

Thanks.