Prechádzať zdrojové kódy

bproto_generator: fix aliasing issues

ambrop7 13 rokov pred
rodič
commit
3291a4713e

+ 31 - 17
bproto_generator/bproto_functions.php

@@ -198,6 +198,7 @@ function generate_header ($name, $directives, $messages) {
 */
 
 #include <stdint.h>
+#include <string.h>
 
 #include <misc/debug.h>
 #include <misc/byteorder.h>
@@ -351,8 +352,10 @@ EOD;
     {$add_count_assert}
     {$add_length_assert}
 
-    ((struct BProto_header_s *)(o->out + o->used))->id = htol16({$entry["id"]});
-    ((struct BProto_header_s *)(o->out + o->used))->type = htol16({$type});
+    struct BProto_header_s header;
+    header.id = htol16({$entry["id"]});
+    header.type = htol16({$type});
+    memcpy(o->out + o->used, &header, sizeof(header));
     o->used += sizeof(struct BProto_header_s);
 
 
@@ -360,14 +363,18 @@ EOD;
             switch ($entry["type"]["type"]) {
                 case "uint":
                     echo <<<EOD
-    ((struct BProto_uint{$entry["type"]["size"]}_s *)(o->out + o->used))->v = htol{$entry["type"]["size"]}(v);
+    struct BProto_uint{$entry["type"]["size"]}_s data;
+    data.v = htol{$entry["type"]["size"]}(v);
+    memcpy(o->out + o->used, &data, sizeof(data));
     o->used += sizeof(struct BProto_uint{$entry["type"]["size"]}_s);
 
 EOD;
                     break;
                 case "data":
                     echo <<<EOD
-    ((struct BProto_data_header_s *)(o->out + o->used))->len = htol32(len);
+    struct BProto_data_header_s data;
+    data.len = htol32(len);
+    memcpy(o->out + o->used, &data, sizeof(data));
     o->used += sizeof(struct BProto_data_header_s);
 
     uint8_t *dest = (o->out + o->used);
@@ -377,7 +384,9 @@ EOD;
                     break;
                 case "constdata":
                     echo <<<EOD
-    ((struct BProto_data_header_s *)(o->out + o->used))->len = htol32({$entry["type"]["size"]});
+    struct BProto_data_header_s data;
+    data.len = htol32({$entry["type"]["size"]});
+    memcpy(o->out + o->used, &data, sizeof(data));
     o->used += sizeof(struct BProto_data_header_s);
 
     uint8_t *dest = (o->out + o->used);
@@ -451,11 +460,12 @@ EOD;
         if (!(left >= sizeof(struct BProto_header_s))) {
             return 0;
         }
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + pos, sizeof(header));
         pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
 
@@ -507,11 +517,12 @@ EOD;
                 if (!(left >= sizeof(struct BProto_data_header_s))) {
                     return 0;
                 }
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + pos, sizeof(val));
                 pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 if (!(left >= payload_len)) {
                     return 0;
                 }
@@ -644,11 +655,12 @@ EOD;
 
     while (left > 0) {
         ASSERT(left >= sizeof(struct BProto_header_s))
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + o->{$entry["name"]}_start + o->{$entry["name"]}_pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + o->{$entry["name"]}_start + o->{$entry["name"]}_pos, sizeof(header));
         o->{$entry["name"]}_pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
 
@@ -662,7 +674,8 @@ EOD;
 EOD;
                 if ($entry["type"]["type"] == "uint" && $entry["type"]["size"] == $bits) {
                     echo <<<EOD
-                struct BProto_uint{$bits}_s *val = (struct BProto_uint{$bits}_s *)(o->buf + o->{$entry["name"]}_start + o->{$entry["name"]}_pos);
+                struct BProto_uint{$bits}_s val;
+                memcpy(&val, o->buf + o->{$entry["name"]}_start + o->{$entry["name"]}_pos, sizeof(val));
 
 EOD;
                 }
@@ -675,7 +688,7 @@ EOD;
                     echo <<<EOD
 
                 if (id == {$entry["id"]}) {
-                    *v = ltoh{$bits}(val->v);
+                    *v = ltoh{$bits}(val.v);
                     return 1;
                 }
 
@@ -693,11 +706,12 @@ EOD;
             case BPROTO_TYPE_CONSTDATA:
             {
                 ASSERT(left >= sizeof(struct BProto_data_header_s))
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + o->{$entry["name"]}_start + o->{$entry["name"]}_pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + o->{$entry["name"]}_start + o->{$entry["name"]}_pos, sizeof(val));
                 o->{$entry["name"]}_pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 ASSERT(left >= payload_len)
 
 EOD;

+ 67 - 39
generated/bproto_addr.h

@@ -4,6 +4,7 @@
 */
 
 #include <stdint.h>
+#include <string.h>
 
 #include <misc/debug.h>
 #include <misc/byteorder.h>
@@ -90,11 +91,15 @@ void addrWriter_Addtype (addrWriter *o, uint8_t v)
     ASSERT(o->type_count == 0)
     
 
-    ((struct BProto_header_s *)(o->out + o->used))->id = htol16(1);
-    ((struct BProto_header_s *)(o->out + o->used))->type = htol16(BPROTO_TYPE_UINT8);
+    struct BProto_header_s header;
+    header.id = htol16(1);
+    header.type = htol16(BPROTO_TYPE_UINT8);
+    memcpy(o->out + o->used, &header, sizeof(header));
     o->used += sizeof(struct BProto_header_s);
 
-    ((struct BProto_uint8_s *)(o->out + o->used))->v = htol8(v);
+    struct BProto_uint8_s data;
+    data.v = htol8(v);
+    memcpy(o->out + o->used, &data, sizeof(data));
     o->used += sizeof(struct BProto_uint8_s);
 
     o->type_count++;
@@ -106,11 +111,15 @@ uint8_t * addrWriter_Addip_port (addrWriter *o)
     ASSERT(o->ip_port_count == 0)
     
 
-    ((struct BProto_header_s *)(o->out + o->used))->id = htol16(2);
-    ((struct BProto_header_s *)(o->out + o->used))->type = htol16(BPROTO_TYPE_CONSTDATA);
+    struct BProto_header_s header;
+    header.id = htol16(2);
+    header.type = htol16(BPROTO_TYPE_CONSTDATA);
+    memcpy(o->out + o->used, &header, sizeof(header));
     o->used += sizeof(struct BProto_header_s);
 
-    ((struct BProto_data_header_s *)(o->out + o->used))->len = htol32(2);
+    struct BProto_data_header_s data;
+    data.len = htol32(2);
+    memcpy(o->out + o->used, &data, sizeof(data));
     o->used += sizeof(struct BProto_data_header_s);
 
     uint8_t *dest = (o->out + o->used);
@@ -127,11 +136,15 @@ uint8_t * addrWriter_Addipv4_addr (addrWriter *o)
     ASSERT(o->ipv4_addr_count == 0)
     
 
-    ((struct BProto_header_s *)(o->out + o->used))->id = htol16(3);
-    ((struct BProto_header_s *)(o->out + o->used))->type = htol16(BPROTO_TYPE_CONSTDATA);
+    struct BProto_header_s header;
+    header.id = htol16(3);
+    header.type = htol16(BPROTO_TYPE_CONSTDATA);
+    memcpy(o->out + o->used, &header, sizeof(header));
     o->used += sizeof(struct BProto_header_s);
 
-    ((struct BProto_data_header_s *)(o->out + o->used))->len = htol32(4);
+    struct BProto_data_header_s data;
+    data.len = htol32(4);
+    memcpy(o->out + o->used, &data, sizeof(data));
     o->used += sizeof(struct BProto_data_header_s);
 
     uint8_t *dest = (o->out + o->used);
@@ -148,11 +161,15 @@ uint8_t * addrWriter_Addipv6_addr (addrWriter *o)
     ASSERT(o->ipv6_addr_count == 0)
     
 
-    ((struct BProto_header_s *)(o->out + o->used))->id = htol16(4);
-    ((struct BProto_header_s *)(o->out + o->used))->type = htol16(BPROTO_TYPE_CONSTDATA);
+    struct BProto_header_s header;
+    header.id = htol16(4);
+    header.type = htol16(BPROTO_TYPE_CONSTDATA);
+    memcpy(o->out + o->used, &header, sizeof(header));
     o->used += sizeof(struct BProto_header_s);
 
-    ((struct BProto_data_header_s *)(o->out + o->used))->len = htol32(16);
+    struct BProto_data_header_s data;
+    data.len = htol32(16);
+    memcpy(o->out + o->used, &data, sizeof(data));
     o->used += sizeof(struct BProto_data_header_s);
 
     uint8_t *dest = (o->out + o->used);
@@ -196,11 +213,12 @@ int addrParser_Init (addrParser *o, uint8_t *buf, int buf_len)
         if (!(left >= sizeof(struct BProto_header_s))) {
             return 0;
         }
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + pos, sizeof(header));
         pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
@@ -264,11 +282,12 @@ int addrParser_Init (addrParser *o, uint8_t *buf, int buf_len)
                 if (!(left >= sizeof(struct BProto_data_header_s))) {
                     return 0;
                 }
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + pos, sizeof(val));
                 pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 if (!(left >= payload_len)) {
                     return 0;
                 }
@@ -362,21 +381,23 @@ int addrParser_Gettype (addrParser *o, uint8_t *v)
 
     while (left > 0) {
         ASSERT(left >= sizeof(struct BProto_header_s))
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + o->type_start + o->type_pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + o->type_start + o->type_pos, sizeof(header));
         o->type_pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
                 ASSERT(left >= sizeof(struct BProto_uint8_s))
-                struct BProto_uint8_s *val = (struct BProto_uint8_s *)(o->buf + o->type_start + o->type_pos);
+                struct BProto_uint8_s val;
+                memcpy(&val, o->buf + o->type_start + o->type_pos, sizeof(val));
                 o->type_pos += sizeof(struct BProto_uint8_s);
                 left -= sizeof(struct BProto_uint8_s);
 
                 if (id == 1) {
-                    *v = ltoh8(val->v);
+                    *v = ltoh8(val.v);
                     return 1;
                 }
             } break;
@@ -399,11 +420,12 @@ int addrParser_Gettype (addrParser *o, uint8_t *v)
             case BPROTO_TYPE_CONSTDATA:
             {
                 ASSERT(left >= sizeof(struct BProto_data_header_s))
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + o->type_start + o->type_pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + o->type_start + o->type_pos, sizeof(val));
                 o->type_pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 ASSERT(left >= payload_len)
                 o->type_pos += payload_len;
                 left -= payload_len;
@@ -435,11 +457,12 @@ int addrParser_Getip_port (addrParser *o, uint8_t **data)
 
     while (left > 0) {
         ASSERT(left >= sizeof(struct BProto_header_s))
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + o->ip_port_start + o->ip_port_pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + o->ip_port_start + o->ip_port_pos, sizeof(header));
         o->ip_port_pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
@@ -466,11 +489,12 @@ int addrParser_Getip_port (addrParser *o, uint8_t **data)
             case BPROTO_TYPE_CONSTDATA:
             {
                 ASSERT(left >= sizeof(struct BProto_data_header_s))
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + o->ip_port_start + o->ip_port_pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + o->ip_port_start + o->ip_port_pos, sizeof(val));
                 o->ip_port_pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 ASSERT(left >= payload_len)
                 uint8_t *payload = o->buf + o->ip_port_start + o->ip_port_pos;
                 o->ip_port_pos += payload_len;
@@ -508,11 +532,12 @@ int addrParser_Getipv4_addr (addrParser *o, uint8_t **data)
 
     while (left > 0) {
         ASSERT(left >= sizeof(struct BProto_header_s))
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + o->ipv4_addr_start + o->ipv4_addr_pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + o->ipv4_addr_start + o->ipv4_addr_pos, sizeof(header));
         o->ipv4_addr_pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
@@ -539,11 +564,12 @@ int addrParser_Getipv4_addr (addrParser *o, uint8_t **data)
             case BPROTO_TYPE_CONSTDATA:
             {
                 ASSERT(left >= sizeof(struct BProto_data_header_s))
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + o->ipv4_addr_start + o->ipv4_addr_pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + o->ipv4_addr_start + o->ipv4_addr_pos, sizeof(val));
                 o->ipv4_addr_pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 ASSERT(left >= payload_len)
                 uint8_t *payload = o->buf + o->ipv4_addr_start + o->ipv4_addr_pos;
                 o->ipv4_addr_pos += payload_len;
@@ -581,11 +607,12 @@ int addrParser_Getipv6_addr (addrParser *o, uint8_t **data)
 
     while (left > 0) {
         ASSERT(left >= sizeof(struct BProto_header_s))
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + o->ipv6_addr_start + o->ipv6_addr_pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + o->ipv6_addr_start + o->ipv6_addr_pos, sizeof(header));
         o->ipv6_addr_pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
@@ -612,11 +639,12 @@ int addrParser_Getipv6_addr (addrParser *o, uint8_t **data)
             case BPROTO_TYPE_CONSTDATA:
             {
                 ASSERT(left >= sizeof(struct BProto_data_header_s))
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + o->ipv6_addr_start + o->ipv6_addr_pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + o->ipv6_addr_start + o->ipv6_addr_pos, sizeof(val));
                 o->ipv6_addr_pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 ASSERT(left >= payload_len)
                 uint8_t *payload = o->buf + o->ipv6_addr_start + o->ipv6_addr_pos;
                 o->ipv6_addr_pos += payload_len;

+ 121 - 71
generated/bproto_bproto_test.h

@@ -4,6 +4,7 @@
 */
 
 #include <stdint.h>
+#include <string.h>
 
 #include <misc/debug.h>
 #include <misc/byteorder.h>
@@ -123,11 +124,15 @@ void msg1Writer_Adda (msg1Writer *o, uint16_t v)
     ASSERT(o->a_count == 0)
     
 
-    ((struct BProto_header_s *)(o->out + o->used))->id = htol16(5);
-    ((struct BProto_header_s *)(o->out + o->used))->type = htol16(BPROTO_TYPE_UINT16);
+    struct BProto_header_s header;
+    header.id = htol16(5);
+    header.type = htol16(BPROTO_TYPE_UINT16);
+    memcpy(o->out + o->used, &header, sizeof(header));
     o->used += sizeof(struct BProto_header_s);
 
-    ((struct BProto_uint16_s *)(o->out + o->used))->v = htol16(v);
+    struct BProto_uint16_s data;
+    data.v = htol16(v);
+    memcpy(o->out + o->used, &data, sizeof(data));
     o->used += sizeof(struct BProto_uint16_s);
 
     o->a_count++;
@@ -139,11 +144,15 @@ void msg1Writer_Addb (msg1Writer *o, uint32_t v)
     ASSERT(o->b_count == 0)
     
 
-    ((struct BProto_header_s *)(o->out + o->used))->id = htol16(6);
-    ((struct BProto_header_s *)(o->out + o->used))->type = htol16(BPROTO_TYPE_UINT32);
+    struct BProto_header_s header;
+    header.id = htol16(6);
+    header.type = htol16(BPROTO_TYPE_UINT32);
+    memcpy(o->out + o->used, &header, sizeof(header));
     o->used += sizeof(struct BProto_header_s);
 
-    ((struct BProto_uint32_s *)(o->out + o->used))->v = htol32(v);
+    struct BProto_uint32_s data;
+    data.v = htol32(v);
+    memcpy(o->out + o->used, &data, sizeof(data));
     o->used += sizeof(struct BProto_uint32_s);
 
     o->b_count++;
@@ -155,11 +164,15 @@ void msg1Writer_Addc (msg1Writer *o, uint64_t v)
     
     
 
-    ((struct BProto_header_s *)(o->out + o->used))->id = htol16(7);
-    ((struct BProto_header_s *)(o->out + o->used))->type = htol16(BPROTO_TYPE_UINT64);
+    struct BProto_header_s header;
+    header.id = htol16(7);
+    header.type = htol16(BPROTO_TYPE_UINT64);
+    memcpy(o->out + o->used, &header, sizeof(header));
     o->used += sizeof(struct BProto_header_s);
 
-    ((struct BProto_uint64_s *)(o->out + o->used))->v = htol64(v);
+    struct BProto_uint64_s data;
+    data.v = htol64(v);
+    memcpy(o->out + o->used, &data, sizeof(data));
     o->used += sizeof(struct BProto_uint64_s);
 
     o->c_count++;
@@ -171,11 +184,15 @@ void msg1Writer_Addd (msg1Writer *o, uint16_t v)
     
     
 
-    ((struct BProto_header_s *)(o->out + o->used))->id = htol16(8);
-    ((struct BProto_header_s *)(o->out + o->used))->type = htol16(BPROTO_TYPE_UINT16);
+    struct BProto_header_s header;
+    header.id = htol16(8);
+    header.type = htol16(BPROTO_TYPE_UINT16);
+    memcpy(o->out + o->used, &header, sizeof(header));
     o->used += sizeof(struct BProto_header_s);
 
-    ((struct BProto_uint16_s *)(o->out + o->used))->v = htol16(v);
+    struct BProto_uint16_s data;
+    data.v = htol16(v);
+    memcpy(o->out + o->used, &data, sizeof(data));
     o->used += sizeof(struct BProto_uint16_s);
 
     o->d_count++;
@@ -187,11 +204,15 @@ void msg1Writer_Adde (msg1Writer *o, uint8_t v)
     ASSERT(o->e_count == 0)
     
 
-    ((struct BProto_header_s *)(o->out + o->used))->id = htol16(9);
-    ((struct BProto_header_s *)(o->out + o->used))->type = htol16(BPROTO_TYPE_UINT8);
+    struct BProto_header_s header;
+    header.id = htol16(9);
+    header.type = htol16(BPROTO_TYPE_UINT8);
+    memcpy(o->out + o->used, &header, sizeof(header));
     o->used += sizeof(struct BProto_header_s);
 
-    ((struct BProto_uint8_s *)(o->out + o->used))->v = htol8(v);
+    struct BProto_uint8_s data;
+    data.v = htol8(v);
+    memcpy(o->out + o->used, &data, sizeof(data));
     o->used += sizeof(struct BProto_uint8_s);
 
     o->e_count++;
@@ -203,11 +224,15 @@ uint8_t * msg1Writer_Addf (msg1Writer *o, int len)
     ASSERT(o->f_count == 0)
     ASSERT(len >= 0 && len <= UINT32_MAX)
 
-    ((struct BProto_header_s *)(o->out + o->used))->id = htol16(10);
-    ((struct BProto_header_s *)(o->out + o->used))->type = htol16(BPROTO_TYPE_DATA);
+    struct BProto_header_s header;
+    header.id = htol16(10);
+    header.type = htol16(BPROTO_TYPE_DATA);
+    memcpy(o->out + o->used, &header, sizeof(header));
     o->used += sizeof(struct BProto_header_s);
 
-    ((struct BProto_data_header_s *)(o->out + o->used))->len = htol32(len);
+    struct BProto_data_header_s data;
+    data.len = htol32(len);
+    memcpy(o->out + o->used, &data, sizeof(data));
     o->used += sizeof(struct BProto_data_header_s);
 
     uint8_t *dest = (o->out + o->used);
@@ -224,11 +249,15 @@ uint8_t * msg1Writer_Addg (msg1Writer *o)
     ASSERT(o->g_count == 0)
     
 
-    ((struct BProto_header_s *)(o->out + o->used))->id = htol16(11);
-    ((struct BProto_header_s *)(o->out + o->used))->type = htol16(BPROTO_TYPE_CONSTDATA);
+    struct BProto_header_s header;
+    header.id = htol16(11);
+    header.type = htol16(BPROTO_TYPE_CONSTDATA);
+    memcpy(o->out + o->used, &header, sizeof(header));
     o->used += sizeof(struct BProto_header_s);
 
-    ((struct BProto_data_header_s *)(o->out + o->used))->len = htol32(4);
+    struct BProto_data_header_s data;
+    data.len = htol32(4);
+    memcpy(o->out + o->used, &data, sizeof(data));
     o->used += sizeof(struct BProto_data_header_s);
 
     uint8_t *dest = (o->out + o->used);
@@ -284,11 +313,12 @@ int msg1Parser_Init (msg1Parser *o, uint8_t *buf, int buf_len)
         if (!(left >= sizeof(struct BProto_header_s))) {
             return 0;
         }
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + pos, sizeof(header));
         pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
@@ -380,11 +410,12 @@ int msg1Parser_Init (msg1Parser *o, uint8_t *buf, int buf_len)
                 if (!(left >= sizeof(struct BProto_data_header_s))) {
                     return 0;
                 }
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + pos, sizeof(val));
                 pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 if (!(left >= payload_len)) {
                     return 0;
                 }
@@ -474,11 +505,12 @@ int msg1Parser_Geta (msg1Parser *o, uint16_t *v)
 
     while (left > 0) {
         ASSERT(left >= sizeof(struct BProto_header_s))
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + o->a_start + o->a_pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + o->a_start + o->a_pos, sizeof(header));
         o->a_pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
@@ -488,12 +520,13 @@ int msg1Parser_Geta (msg1Parser *o, uint16_t *v)
             } break;
             case BPROTO_TYPE_UINT16: {
                 ASSERT(left >= sizeof(struct BProto_uint16_s))
-                struct BProto_uint16_s *val = (struct BProto_uint16_s *)(o->buf + o->a_start + o->a_pos);
+                struct BProto_uint16_s val;
+                memcpy(&val, o->buf + o->a_start + o->a_pos, sizeof(val));
                 o->a_pos += sizeof(struct BProto_uint16_s);
                 left -= sizeof(struct BProto_uint16_s);
 
                 if (id == 5) {
-                    *v = ltoh16(val->v);
+                    *v = ltoh16(val.v);
                     return 1;
                 }
             } break;
@@ -511,11 +544,12 @@ int msg1Parser_Geta (msg1Parser *o, uint16_t *v)
             case BPROTO_TYPE_CONSTDATA:
             {
                 ASSERT(left >= sizeof(struct BProto_data_header_s))
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + o->a_start + o->a_pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + o->a_start + o->a_pos, sizeof(val));
                 o->a_pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 ASSERT(left >= payload_len)
                 o->a_pos += payload_len;
                 left -= payload_len;
@@ -547,11 +581,12 @@ int msg1Parser_Getb (msg1Parser *o, uint32_t *v)
 
     while (left > 0) {
         ASSERT(left >= sizeof(struct BProto_header_s))
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + o->b_start + o->b_pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + o->b_start + o->b_pos, sizeof(header));
         o->b_pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
@@ -566,12 +601,13 @@ int msg1Parser_Getb (msg1Parser *o, uint32_t *v)
             } break;
             case BPROTO_TYPE_UINT32: {
                 ASSERT(left >= sizeof(struct BProto_uint32_s))
-                struct BProto_uint32_s *val = (struct BProto_uint32_s *)(o->buf + o->b_start + o->b_pos);
+                struct BProto_uint32_s val;
+                memcpy(&val, o->buf + o->b_start + o->b_pos, sizeof(val));
                 o->b_pos += sizeof(struct BProto_uint32_s);
                 left -= sizeof(struct BProto_uint32_s);
 
                 if (id == 6) {
-                    *v = ltoh32(val->v);
+                    *v = ltoh32(val.v);
                     return 1;
                 }
             } break;
@@ -584,11 +620,12 @@ int msg1Parser_Getb (msg1Parser *o, uint32_t *v)
             case BPROTO_TYPE_CONSTDATA:
             {
                 ASSERT(left >= sizeof(struct BProto_data_header_s))
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + o->b_start + o->b_pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + o->b_start + o->b_pos, sizeof(val));
                 o->b_pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 ASSERT(left >= payload_len)
                 o->b_pos += payload_len;
                 left -= payload_len;
@@ -620,11 +657,12 @@ int msg1Parser_Getc (msg1Parser *o, uint64_t *v)
 
     while (left > 0) {
         ASSERT(left >= sizeof(struct BProto_header_s))
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + o->c_start + o->c_pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + o->c_start + o->c_pos, sizeof(header));
         o->c_pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
@@ -644,12 +682,13 @@ int msg1Parser_Getc (msg1Parser *o, uint64_t *v)
             } break;
             case BPROTO_TYPE_UINT64: {
                 ASSERT(left >= sizeof(struct BProto_uint64_s))
-                struct BProto_uint64_s *val = (struct BProto_uint64_s *)(o->buf + o->c_start + o->c_pos);
+                struct BProto_uint64_s val;
+                memcpy(&val, o->buf + o->c_start + o->c_pos, sizeof(val));
                 o->c_pos += sizeof(struct BProto_uint64_s);
                 left -= sizeof(struct BProto_uint64_s);
 
                 if (id == 7) {
-                    *v = ltoh64(val->v);
+                    *v = ltoh64(val.v);
                     return 1;
                 }
             } break;
@@ -657,11 +696,12 @@ int msg1Parser_Getc (msg1Parser *o, uint64_t *v)
             case BPROTO_TYPE_CONSTDATA:
             {
                 ASSERT(left >= sizeof(struct BProto_data_header_s))
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + o->c_start + o->c_pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + o->c_start + o->c_pos, sizeof(val));
                 o->c_pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 ASSERT(left >= payload_len)
                 o->c_pos += payload_len;
                 left -= payload_len;
@@ -693,11 +733,12 @@ int msg1Parser_Getd (msg1Parser *o, uint16_t *v)
 
     while (left > 0) {
         ASSERT(left >= sizeof(struct BProto_header_s))
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + o->d_start + o->d_pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + o->d_start + o->d_pos, sizeof(header));
         o->d_pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
@@ -707,12 +748,13 @@ int msg1Parser_Getd (msg1Parser *o, uint16_t *v)
             } break;
             case BPROTO_TYPE_UINT16: {
                 ASSERT(left >= sizeof(struct BProto_uint16_s))
-                struct BProto_uint16_s *val = (struct BProto_uint16_s *)(o->buf + o->d_start + o->d_pos);
+                struct BProto_uint16_s val;
+                memcpy(&val, o->buf + o->d_start + o->d_pos, sizeof(val));
                 o->d_pos += sizeof(struct BProto_uint16_s);
                 left -= sizeof(struct BProto_uint16_s);
 
                 if (id == 8) {
-                    *v = ltoh16(val->v);
+                    *v = ltoh16(val.v);
                     return 1;
                 }
             } break;
@@ -730,11 +772,12 @@ int msg1Parser_Getd (msg1Parser *o, uint16_t *v)
             case BPROTO_TYPE_CONSTDATA:
             {
                 ASSERT(left >= sizeof(struct BProto_data_header_s))
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + o->d_start + o->d_pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + o->d_start + o->d_pos, sizeof(val));
                 o->d_pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 ASSERT(left >= payload_len)
                 o->d_pos += payload_len;
                 left -= payload_len;
@@ -766,21 +809,23 @@ int msg1Parser_Gete (msg1Parser *o, uint8_t *v)
 
     while (left > 0) {
         ASSERT(left >= sizeof(struct BProto_header_s))
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + o->e_start + o->e_pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + o->e_start + o->e_pos, sizeof(header));
         o->e_pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
                 ASSERT(left >= sizeof(struct BProto_uint8_s))
-                struct BProto_uint8_s *val = (struct BProto_uint8_s *)(o->buf + o->e_start + o->e_pos);
+                struct BProto_uint8_s val;
+                memcpy(&val, o->buf + o->e_start + o->e_pos, sizeof(val));
                 o->e_pos += sizeof(struct BProto_uint8_s);
                 left -= sizeof(struct BProto_uint8_s);
 
                 if (id == 9) {
-                    *v = ltoh8(val->v);
+                    *v = ltoh8(val.v);
                     return 1;
                 }
             } break;
@@ -803,11 +848,12 @@ int msg1Parser_Gete (msg1Parser *o, uint8_t *v)
             case BPROTO_TYPE_CONSTDATA:
             {
                 ASSERT(left >= sizeof(struct BProto_data_header_s))
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + o->e_start + o->e_pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + o->e_start + o->e_pos, sizeof(val));
                 o->e_pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 ASSERT(left >= payload_len)
                 o->e_pos += payload_len;
                 left -= payload_len;
@@ -839,11 +885,12 @@ int msg1Parser_Getf (msg1Parser *o, uint8_t **data, int *data_len)
 
     while (left > 0) {
         ASSERT(left >= sizeof(struct BProto_header_s))
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + o->f_start + o->f_pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + o->f_start + o->f_pos, sizeof(header));
         o->f_pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
@@ -870,11 +917,12 @@ int msg1Parser_Getf (msg1Parser *o, uint8_t **data, int *data_len)
             case BPROTO_TYPE_CONSTDATA:
             {
                 ASSERT(left >= sizeof(struct BProto_data_header_s))
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + o->f_start + o->f_pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + o->f_start + o->f_pos, sizeof(val));
                 o->f_pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 ASSERT(left >= payload_len)
                 uint8_t *payload = o->buf + o->f_start + o->f_pos;
                 o->f_pos += payload_len;
@@ -913,11 +961,12 @@ int msg1Parser_Getg (msg1Parser *o, uint8_t **data)
 
     while (left > 0) {
         ASSERT(left >= sizeof(struct BProto_header_s))
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + o->g_start + o->g_pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + o->g_start + o->g_pos, sizeof(header));
         o->g_pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
@@ -944,11 +993,12 @@ int msg1Parser_Getg (msg1Parser *o, uint8_t **data)
             case BPROTO_TYPE_CONSTDATA:
             {
                 ASSERT(left >= sizeof(struct BProto_data_header_s))
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + o->g_start + o->g_pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + o->g_start + o->g_pos, sizeof(val));
                 o->g_pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 ASSERT(left >= payload_len)
                 uint8_t *payload = o->buf + o->g_start + o->g_pos;
                 o->g_pos += payload_len;

+ 202 - 121
generated/bproto_msgproto.h

@@ -4,6 +4,7 @@
 */
 
 #include <stdint.h>
+#include <string.h>
 
 #include <misc/debug.h>
 #include <misc/byteorder.h>
@@ -68,11 +69,15 @@ void msgWriter_Addtype (msgWriter *o, uint16_t v)
     ASSERT(o->type_count == 0)
     
 
-    ((struct BProto_header_s *)(o->out + o->used))->id = htol16(1);
-    ((struct BProto_header_s *)(o->out + o->used))->type = htol16(BPROTO_TYPE_UINT16);
+    struct BProto_header_s header;
+    header.id = htol16(1);
+    header.type = htol16(BPROTO_TYPE_UINT16);
+    memcpy(o->out + o->used, &header, sizeof(header));
     o->used += sizeof(struct BProto_header_s);
 
-    ((struct BProto_uint16_s *)(o->out + o->used))->v = htol16(v);
+    struct BProto_uint16_s data;
+    data.v = htol16(v);
+    memcpy(o->out + o->used, &data, sizeof(data));
     o->used += sizeof(struct BProto_uint16_s);
 
     o->type_count++;
@@ -84,11 +89,15 @@ uint8_t * msgWriter_Addpayload (msgWriter *o, int len)
     ASSERT(o->payload_count == 0)
     ASSERT(len >= 0 && len <= UINT32_MAX)
 
-    ((struct BProto_header_s *)(o->out + o->used))->id = htol16(2);
-    ((struct BProto_header_s *)(o->out + o->used))->type = htol16(BPROTO_TYPE_DATA);
+    struct BProto_header_s header;
+    header.id = htol16(2);
+    header.type = htol16(BPROTO_TYPE_DATA);
+    memcpy(o->out + o->used, &header, sizeof(header));
     o->used += sizeof(struct BProto_header_s);
 
-    ((struct BProto_data_header_s *)(o->out + o->used))->len = htol32(len);
+    struct BProto_data_header_s data;
+    data.len = htol32(len);
+    memcpy(o->out + o->used, &data, sizeof(data));
     o->used += sizeof(struct BProto_data_header_s);
 
     uint8_t *dest = (o->out + o->used);
@@ -124,11 +133,12 @@ int msgParser_Init (msgParser *o, uint8_t *buf, int buf_len)
         if (!(left >= sizeof(struct BProto_header_s))) {
             return 0;
         }
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + pos, sizeof(header));
         pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
@@ -192,11 +202,12 @@ int msgParser_Init (msgParser *o, uint8_t *buf, int buf_len)
                 if (!(left >= sizeof(struct BProto_data_header_s))) {
                     return 0;
                 }
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + pos, sizeof(val));
                 pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 if (!(left >= payload_len)) {
                     return 0;
                 }
@@ -251,11 +262,12 @@ int msgParser_Gettype (msgParser *o, uint16_t *v)
 
     while (left > 0) {
         ASSERT(left >= sizeof(struct BProto_header_s))
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + o->type_start + o->type_pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + o->type_start + o->type_pos, sizeof(header));
         o->type_pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
@@ -265,12 +277,13 @@ int msgParser_Gettype (msgParser *o, uint16_t *v)
             } break;
             case BPROTO_TYPE_UINT16: {
                 ASSERT(left >= sizeof(struct BProto_uint16_s))
-                struct BProto_uint16_s *val = (struct BProto_uint16_s *)(o->buf + o->type_start + o->type_pos);
+                struct BProto_uint16_s val;
+                memcpy(&val, o->buf + o->type_start + o->type_pos, sizeof(val));
                 o->type_pos += sizeof(struct BProto_uint16_s);
                 left -= sizeof(struct BProto_uint16_s);
 
                 if (id == 1) {
-                    *v = ltoh16(val->v);
+                    *v = ltoh16(val.v);
                     return 1;
                 }
             } break;
@@ -288,11 +301,12 @@ int msgParser_Gettype (msgParser *o, uint16_t *v)
             case BPROTO_TYPE_CONSTDATA:
             {
                 ASSERT(left >= sizeof(struct BProto_data_header_s))
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + o->type_start + o->type_pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + o->type_start + o->type_pos, sizeof(val));
                 o->type_pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 ASSERT(left >= payload_len)
                 o->type_pos += payload_len;
                 left -= payload_len;
@@ -324,11 +338,12 @@ int msgParser_Getpayload (msgParser *o, uint8_t **data, int *data_len)
 
     while (left > 0) {
         ASSERT(left >= sizeof(struct BProto_header_s))
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + o->payload_start + o->payload_pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + o->payload_start + o->payload_pos, sizeof(header));
         o->payload_pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
@@ -355,11 +370,12 @@ int msgParser_Getpayload (msgParser *o, uint8_t **data, int *data_len)
             case BPROTO_TYPE_CONSTDATA:
             {
                 ASSERT(left >= sizeof(struct BProto_data_header_s))
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + o->payload_start + o->payload_pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + o->payload_start + o->payload_pos, sizeof(val));
                 o->payload_pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 ASSERT(left >= payload_len)
                 uint8_t *payload = o->buf + o->payload_start + o->payload_pos;
                 o->payload_pos += payload_len;
@@ -458,11 +474,15 @@ uint8_t * msg_youconnectWriter_Addaddr (msg_youconnectWriter *o, int len)
     
     ASSERT(len >= 0 && len <= UINT32_MAX)
 
-    ((struct BProto_header_s *)(o->out + o->used))->id = htol16(1);
-    ((struct BProto_header_s *)(o->out + o->used))->type = htol16(BPROTO_TYPE_DATA);
+    struct BProto_header_s header;
+    header.id = htol16(1);
+    header.type = htol16(BPROTO_TYPE_DATA);
+    memcpy(o->out + o->used, &header, sizeof(header));
     o->used += sizeof(struct BProto_header_s);
 
-    ((struct BProto_data_header_s *)(o->out + o->used))->len = htol32(len);
+    struct BProto_data_header_s data;
+    data.len = htol32(len);
+    memcpy(o->out + o->used, &data, sizeof(data));
     o->used += sizeof(struct BProto_data_header_s);
 
     uint8_t *dest = (o->out + o->used);
@@ -479,11 +499,15 @@ uint8_t * msg_youconnectWriter_Addkey (msg_youconnectWriter *o, int len)
     ASSERT(o->key_count == 0)
     ASSERT(len >= 0 && len <= UINT32_MAX)
 
-    ((struct BProto_header_s *)(o->out + o->used))->id = htol16(2);
-    ((struct BProto_header_s *)(o->out + o->used))->type = htol16(BPROTO_TYPE_DATA);
+    struct BProto_header_s header;
+    header.id = htol16(2);
+    header.type = htol16(BPROTO_TYPE_DATA);
+    memcpy(o->out + o->used, &header, sizeof(header));
     o->used += sizeof(struct BProto_header_s);
 
-    ((struct BProto_data_header_s *)(o->out + o->used))->len = htol32(len);
+    struct BProto_data_header_s data;
+    data.len = htol32(len);
+    memcpy(o->out + o->used, &data, sizeof(data));
     o->used += sizeof(struct BProto_data_header_s);
 
     uint8_t *dest = (o->out + o->used);
@@ -500,11 +524,15 @@ void msg_youconnectWriter_Addpassword (msg_youconnectWriter *o, uint64_t v)
     ASSERT(o->password_count == 0)
     
 
-    ((struct BProto_header_s *)(o->out + o->used))->id = htol16(3);
-    ((struct BProto_header_s *)(o->out + o->used))->type = htol16(BPROTO_TYPE_UINT64);
+    struct BProto_header_s header;
+    header.id = htol16(3);
+    header.type = htol16(BPROTO_TYPE_UINT64);
+    memcpy(o->out + o->used, &header, sizeof(header));
     o->used += sizeof(struct BProto_header_s);
 
-    ((struct BProto_uint64_s *)(o->out + o->used))->v = htol64(v);
+    struct BProto_uint64_s data;
+    data.v = htol64(v);
+    memcpy(o->out + o->used, &data, sizeof(data));
     o->used += sizeof(struct BProto_uint64_s);
 
     o->password_count++;
@@ -539,11 +567,12 @@ int msg_youconnectParser_Init (msg_youconnectParser *o, uint8_t *buf, int buf_le
         if (!(left >= sizeof(struct BProto_header_s))) {
             return 0;
         }
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + pos, sizeof(header));
         pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
@@ -607,11 +636,12 @@ int msg_youconnectParser_Init (msg_youconnectParser *o, uint8_t *buf, int buf_le
                 if (!(left >= sizeof(struct BProto_data_header_s))) {
                     return 0;
                 }
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + pos, sizeof(val));
                 pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 if (!(left >= payload_len)) {
                     return 0;
                 }
@@ -681,11 +711,12 @@ int msg_youconnectParser_Getaddr (msg_youconnectParser *o, uint8_t **data, int *
 
     while (left > 0) {
         ASSERT(left >= sizeof(struct BProto_header_s))
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + o->addr_start + o->addr_pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + o->addr_start + o->addr_pos, sizeof(header));
         o->addr_pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
@@ -712,11 +743,12 @@ int msg_youconnectParser_Getaddr (msg_youconnectParser *o, uint8_t **data, int *
             case BPROTO_TYPE_CONSTDATA:
             {
                 ASSERT(left >= sizeof(struct BProto_data_header_s))
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + o->addr_start + o->addr_pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + o->addr_start + o->addr_pos, sizeof(val));
                 o->addr_pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 ASSERT(left >= payload_len)
                 uint8_t *payload = o->buf + o->addr_start + o->addr_pos;
                 o->addr_pos += payload_len;
@@ -755,11 +787,12 @@ int msg_youconnectParser_Getkey (msg_youconnectParser *o, uint8_t **data, int *d
 
     while (left > 0) {
         ASSERT(left >= sizeof(struct BProto_header_s))
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + o->key_start + o->key_pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + o->key_start + o->key_pos, sizeof(header));
         o->key_pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
@@ -786,11 +819,12 @@ int msg_youconnectParser_Getkey (msg_youconnectParser *o, uint8_t **data, int *d
             case BPROTO_TYPE_CONSTDATA:
             {
                 ASSERT(left >= sizeof(struct BProto_data_header_s))
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + o->key_start + o->key_pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + o->key_start + o->key_pos, sizeof(val));
                 o->key_pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 ASSERT(left >= payload_len)
                 uint8_t *payload = o->buf + o->key_start + o->key_pos;
                 o->key_pos += payload_len;
@@ -829,11 +863,12 @@ int msg_youconnectParser_Getpassword (msg_youconnectParser *o, uint64_t *v)
 
     while (left > 0) {
         ASSERT(left >= sizeof(struct BProto_header_s))
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + o->password_start + o->password_pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + o->password_start + o->password_pos, sizeof(header));
         o->password_pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
@@ -853,12 +888,13 @@ int msg_youconnectParser_Getpassword (msg_youconnectParser *o, uint64_t *v)
             } break;
             case BPROTO_TYPE_UINT64: {
                 ASSERT(left >= sizeof(struct BProto_uint64_s))
-                struct BProto_uint64_s *val = (struct BProto_uint64_s *)(o->buf + o->password_start + o->password_pos);
+                struct BProto_uint64_s val;
+                memcpy(&val, o->buf + o->password_start + o->password_pos, sizeof(val));
                 o->password_pos += sizeof(struct BProto_uint64_s);
                 left -= sizeof(struct BProto_uint64_s);
 
                 if (id == 3) {
-                    *v = ltoh64(val->v);
+                    *v = ltoh64(val.v);
                     return 1;
                 }
             } break;
@@ -866,11 +902,12 @@ int msg_youconnectParser_Getpassword (msg_youconnectParser *o, uint64_t *v)
             case BPROTO_TYPE_CONSTDATA:
             {
                 ASSERT(left >= sizeof(struct BProto_data_header_s))
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + o->password_start + o->password_pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + o->password_start + o->password_pos, sizeof(val));
                 o->password_pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 ASSERT(left >= payload_len)
                 o->password_pos += payload_len;
                 left -= payload_len;
@@ -951,11 +988,15 @@ uint8_t * msg_youconnect_addrWriter_Addname (msg_youconnect_addrWriter *o, int l
     ASSERT(o->name_count == 0)
     ASSERT(len >= 0 && len <= UINT32_MAX)
 
-    ((struct BProto_header_s *)(o->out + o->used))->id = htol16(1);
-    ((struct BProto_header_s *)(o->out + o->used))->type = htol16(BPROTO_TYPE_DATA);
+    struct BProto_header_s header;
+    header.id = htol16(1);
+    header.type = htol16(BPROTO_TYPE_DATA);
+    memcpy(o->out + o->used, &header, sizeof(header));
     o->used += sizeof(struct BProto_header_s);
 
-    ((struct BProto_data_header_s *)(o->out + o->used))->len = htol32(len);
+    struct BProto_data_header_s data;
+    data.len = htol32(len);
+    memcpy(o->out + o->used, &data, sizeof(data));
     o->used += sizeof(struct BProto_data_header_s);
 
     uint8_t *dest = (o->out + o->used);
@@ -972,11 +1013,15 @@ uint8_t * msg_youconnect_addrWriter_Addaddr (msg_youconnect_addrWriter *o, int l
     ASSERT(o->addr_count == 0)
     ASSERT(len >= 0 && len <= UINT32_MAX)
 
-    ((struct BProto_header_s *)(o->out + o->used))->id = htol16(2);
-    ((struct BProto_header_s *)(o->out + o->used))->type = htol16(BPROTO_TYPE_DATA);
+    struct BProto_header_s header;
+    header.id = htol16(2);
+    header.type = htol16(BPROTO_TYPE_DATA);
+    memcpy(o->out + o->used, &header, sizeof(header));
     o->used += sizeof(struct BProto_header_s);
 
-    ((struct BProto_data_header_s *)(o->out + o->used))->len = htol32(len);
+    struct BProto_data_header_s data;
+    data.len = htol32(len);
+    memcpy(o->out + o->used, &data, sizeof(data));
     o->used += sizeof(struct BProto_data_header_s);
 
     uint8_t *dest = (o->out + o->used);
@@ -1012,11 +1057,12 @@ int msg_youconnect_addrParser_Init (msg_youconnect_addrParser *o, uint8_t *buf,
         if (!(left >= sizeof(struct BProto_header_s))) {
             return 0;
         }
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + pos, sizeof(header));
         pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
@@ -1073,11 +1119,12 @@ int msg_youconnect_addrParser_Init (msg_youconnect_addrParser *o, uint8_t *buf,
                 if (!(left >= sizeof(struct BProto_data_header_s))) {
                     return 0;
                 }
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + pos, sizeof(val));
                 pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 if (!(left >= payload_len)) {
                     return 0;
                 }
@@ -1142,11 +1189,12 @@ int msg_youconnect_addrParser_Getname (msg_youconnect_addrParser *o, uint8_t **d
 
     while (left > 0) {
         ASSERT(left >= sizeof(struct BProto_header_s))
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + o->name_start + o->name_pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + o->name_start + o->name_pos, sizeof(header));
         o->name_pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
@@ -1173,11 +1221,12 @@ int msg_youconnect_addrParser_Getname (msg_youconnect_addrParser *o, uint8_t **d
             case BPROTO_TYPE_CONSTDATA:
             {
                 ASSERT(left >= sizeof(struct BProto_data_header_s))
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + o->name_start + o->name_pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + o->name_start + o->name_pos, sizeof(val));
                 o->name_pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 ASSERT(left >= payload_len)
                 uint8_t *payload = o->buf + o->name_start + o->name_pos;
                 o->name_pos += payload_len;
@@ -1216,11 +1265,12 @@ int msg_youconnect_addrParser_Getaddr (msg_youconnect_addrParser *o, uint8_t **d
 
     while (left > 0) {
         ASSERT(left >= sizeof(struct BProto_header_s))
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + o->addr_start + o->addr_pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + o->addr_start + o->addr_pos, sizeof(header));
         o->addr_pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
@@ -1247,11 +1297,12 @@ int msg_youconnect_addrParser_Getaddr (msg_youconnect_addrParser *o, uint8_t **d
             case BPROTO_TYPE_CONSTDATA:
             {
                 ASSERT(left >= sizeof(struct BProto_data_header_s))
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + o->addr_start + o->addr_pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + o->addr_start + o->addr_pos, sizeof(val));
                 o->addr_pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 ASSERT(left >= payload_len)
                 uint8_t *payload = o->buf + o->addr_start + o->addr_pos;
                 o->addr_pos += payload_len;
@@ -1350,11 +1401,15 @@ void msg_seedWriter_Addseed_id (msg_seedWriter *o, uint16_t v)
     ASSERT(o->seed_id_count == 0)
     
 
-    ((struct BProto_header_s *)(o->out + o->used))->id = htol16(1);
-    ((struct BProto_header_s *)(o->out + o->used))->type = htol16(BPROTO_TYPE_UINT16);
+    struct BProto_header_s header;
+    header.id = htol16(1);
+    header.type = htol16(BPROTO_TYPE_UINT16);
+    memcpy(o->out + o->used, &header, sizeof(header));
     o->used += sizeof(struct BProto_header_s);
 
-    ((struct BProto_uint16_s *)(o->out + o->used))->v = htol16(v);
+    struct BProto_uint16_s data;
+    data.v = htol16(v);
+    memcpy(o->out + o->used, &data, sizeof(data));
     o->used += sizeof(struct BProto_uint16_s);
 
     o->seed_id_count++;
@@ -1366,11 +1421,15 @@ uint8_t * msg_seedWriter_Addkey (msg_seedWriter *o, int len)
     ASSERT(o->key_count == 0)
     ASSERT(len >= 0 && len <= UINT32_MAX)
 
-    ((struct BProto_header_s *)(o->out + o->used))->id = htol16(2);
-    ((struct BProto_header_s *)(o->out + o->used))->type = htol16(BPROTO_TYPE_DATA);
+    struct BProto_header_s header;
+    header.id = htol16(2);
+    header.type = htol16(BPROTO_TYPE_DATA);
+    memcpy(o->out + o->used, &header, sizeof(header));
     o->used += sizeof(struct BProto_header_s);
 
-    ((struct BProto_data_header_s *)(o->out + o->used))->len = htol32(len);
+    struct BProto_data_header_s data;
+    data.len = htol32(len);
+    memcpy(o->out + o->used, &data, sizeof(data));
     o->used += sizeof(struct BProto_data_header_s);
 
     uint8_t *dest = (o->out + o->used);
@@ -1387,11 +1446,15 @@ uint8_t * msg_seedWriter_Addiv (msg_seedWriter *o, int len)
     ASSERT(o->iv_count == 0)
     ASSERT(len >= 0 && len <= UINT32_MAX)
 
-    ((struct BProto_header_s *)(o->out + o->used))->id = htol16(3);
-    ((struct BProto_header_s *)(o->out + o->used))->type = htol16(BPROTO_TYPE_DATA);
+    struct BProto_header_s header;
+    header.id = htol16(3);
+    header.type = htol16(BPROTO_TYPE_DATA);
+    memcpy(o->out + o->used, &header, sizeof(header));
     o->used += sizeof(struct BProto_header_s);
 
-    ((struct BProto_data_header_s *)(o->out + o->used))->len = htol32(len);
+    struct BProto_data_header_s data;
+    data.len = htol32(len);
+    memcpy(o->out + o->used, &data, sizeof(data));
     o->used += sizeof(struct BProto_data_header_s);
 
     uint8_t *dest = (o->out + o->used);
@@ -1431,11 +1494,12 @@ int msg_seedParser_Init (msg_seedParser *o, uint8_t *buf, int buf_len)
         if (!(left >= sizeof(struct BProto_header_s))) {
             return 0;
         }
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + pos, sizeof(header));
         pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
@@ -1499,11 +1563,12 @@ int msg_seedParser_Init (msg_seedParser *o, uint8_t *buf, int buf_len)
                 if (!(left >= sizeof(struct BProto_data_header_s))) {
                     return 0;
                 }
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + pos, sizeof(val));
                 pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 if (!(left >= payload_len)) {
                     return 0;
                 }
@@ -1573,11 +1638,12 @@ int msg_seedParser_Getseed_id (msg_seedParser *o, uint16_t *v)
 
     while (left > 0) {
         ASSERT(left >= sizeof(struct BProto_header_s))
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + o->seed_id_start + o->seed_id_pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + o->seed_id_start + o->seed_id_pos, sizeof(header));
         o->seed_id_pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
@@ -1587,12 +1653,13 @@ int msg_seedParser_Getseed_id (msg_seedParser *o, uint16_t *v)
             } break;
             case BPROTO_TYPE_UINT16: {
                 ASSERT(left >= sizeof(struct BProto_uint16_s))
-                struct BProto_uint16_s *val = (struct BProto_uint16_s *)(o->buf + o->seed_id_start + o->seed_id_pos);
+                struct BProto_uint16_s val;
+                memcpy(&val, o->buf + o->seed_id_start + o->seed_id_pos, sizeof(val));
                 o->seed_id_pos += sizeof(struct BProto_uint16_s);
                 left -= sizeof(struct BProto_uint16_s);
 
                 if (id == 1) {
-                    *v = ltoh16(val->v);
+                    *v = ltoh16(val.v);
                     return 1;
                 }
             } break;
@@ -1610,11 +1677,12 @@ int msg_seedParser_Getseed_id (msg_seedParser *o, uint16_t *v)
             case BPROTO_TYPE_CONSTDATA:
             {
                 ASSERT(left >= sizeof(struct BProto_data_header_s))
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + o->seed_id_start + o->seed_id_pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + o->seed_id_start + o->seed_id_pos, sizeof(val));
                 o->seed_id_pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 ASSERT(left >= payload_len)
                 o->seed_id_pos += payload_len;
                 left -= payload_len;
@@ -1646,11 +1714,12 @@ int msg_seedParser_Getkey (msg_seedParser *o, uint8_t **data, int *data_len)
 
     while (left > 0) {
         ASSERT(left >= sizeof(struct BProto_header_s))
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + o->key_start + o->key_pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + o->key_start + o->key_pos, sizeof(header));
         o->key_pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
@@ -1677,11 +1746,12 @@ int msg_seedParser_Getkey (msg_seedParser *o, uint8_t **data, int *data_len)
             case BPROTO_TYPE_CONSTDATA:
             {
                 ASSERT(left >= sizeof(struct BProto_data_header_s))
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + o->key_start + o->key_pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + o->key_start + o->key_pos, sizeof(val));
                 o->key_pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 ASSERT(left >= payload_len)
                 uint8_t *payload = o->buf + o->key_start + o->key_pos;
                 o->key_pos += payload_len;
@@ -1720,11 +1790,12 @@ int msg_seedParser_Getiv (msg_seedParser *o, uint8_t **data, int *data_len)
 
     while (left > 0) {
         ASSERT(left >= sizeof(struct BProto_header_s))
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + o->iv_start + o->iv_pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + o->iv_start + o->iv_pos, sizeof(header));
         o->iv_pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
@@ -1751,11 +1822,12 @@ int msg_seedParser_Getiv (msg_seedParser *o, uint8_t **data, int *data_len)
             case BPROTO_TYPE_CONSTDATA:
             {
                 ASSERT(left >= sizeof(struct BProto_data_header_s))
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + o->iv_start + o->iv_pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + o->iv_start + o->iv_pos, sizeof(val));
                 o->iv_pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 ASSERT(left >= payload_len)
                 uint8_t *payload = o->buf + o->iv_start + o->iv_pos;
                 o->iv_pos += payload_len;
@@ -1832,11 +1904,15 @@ void msg_confirmseedWriter_Addseed_id (msg_confirmseedWriter *o, uint16_t v)
     ASSERT(o->seed_id_count == 0)
     
 
-    ((struct BProto_header_s *)(o->out + o->used))->id = htol16(1);
-    ((struct BProto_header_s *)(o->out + o->used))->type = htol16(BPROTO_TYPE_UINT16);
+    struct BProto_header_s header;
+    header.id = htol16(1);
+    header.type = htol16(BPROTO_TYPE_UINT16);
+    memcpy(o->out + o->used, &header, sizeof(header));
     o->used += sizeof(struct BProto_header_s);
 
-    ((struct BProto_uint16_s *)(o->out + o->used))->v = htol16(v);
+    struct BProto_uint16_s data;
+    data.v = htol16(v);
+    memcpy(o->out + o->used, &data, sizeof(data));
     o->used += sizeof(struct BProto_uint16_s);
 
     o->seed_id_count++;
@@ -1863,11 +1939,12 @@ int msg_confirmseedParser_Init (msg_confirmseedParser *o, uint8_t *buf, int buf_
         if (!(left >= sizeof(struct BProto_header_s))) {
             return 0;
         }
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + pos, sizeof(header));
         pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
@@ -1931,11 +2008,12 @@ int msg_confirmseedParser_Init (msg_confirmseedParser *o, uint8_t *buf, int buf_
                 if (!(left >= sizeof(struct BProto_data_header_s))) {
                     return 0;
                 }
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + pos, sizeof(val));
                 pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 if (!(left >= payload_len)) {
                     return 0;
                 }
@@ -1975,11 +2053,12 @@ int msg_confirmseedParser_Getseed_id (msg_confirmseedParser *o, uint16_t *v)
 
     while (left > 0) {
         ASSERT(left >= sizeof(struct BProto_header_s))
-        struct BProto_header_s *header = (struct BProto_header_s *)(o->buf + o->seed_id_start + o->seed_id_pos);
+        struct BProto_header_s header;
+        memcpy(&header, o->buf + o->seed_id_start + o->seed_id_pos, sizeof(header));
         o->seed_id_pos += sizeof(struct BProto_header_s);
         left -= sizeof(struct BProto_header_s);
-        uint16_t type = ltoh16(header->type);
-        uint16_t id = ltoh16(header->id);
+        uint16_t type = ltoh16(header.type);
+        uint16_t id = ltoh16(header.id);
 
         switch (type) {
             case BPROTO_TYPE_UINT8: {
@@ -1989,12 +2068,13 @@ int msg_confirmseedParser_Getseed_id (msg_confirmseedParser *o, uint16_t *v)
             } break;
             case BPROTO_TYPE_UINT16: {
                 ASSERT(left >= sizeof(struct BProto_uint16_s))
-                struct BProto_uint16_s *val = (struct BProto_uint16_s *)(o->buf + o->seed_id_start + o->seed_id_pos);
+                struct BProto_uint16_s val;
+                memcpy(&val, o->buf + o->seed_id_start + o->seed_id_pos, sizeof(val));
                 o->seed_id_pos += sizeof(struct BProto_uint16_s);
                 left -= sizeof(struct BProto_uint16_s);
 
                 if (id == 1) {
-                    *v = ltoh16(val->v);
+                    *v = ltoh16(val.v);
                     return 1;
                 }
             } break;
@@ -2012,11 +2092,12 @@ int msg_confirmseedParser_Getseed_id (msg_confirmseedParser *o, uint16_t *v)
             case BPROTO_TYPE_CONSTDATA:
             {
                 ASSERT(left >= sizeof(struct BProto_data_header_s))
-                struct BProto_data_header_s *val = (struct BProto_data_header_s *)(o->buf + o->seed_id_start + o->seed_id_pos);
+                struct BProto_data_header_s val;
+                memcpy(&val, o->buf + o->seed_id_start + o->seed_id_pos, sizeof(val));
                 o->seed_id_pos += sizeof(struct BProto_data_header_s);
                 left -= sizeof(struct BProto_data_header_s);
 
-                uint32_t payload_len = ltoh32(val->len);
+                uint32_t payload_len = ltoh32(val.len);
                 ASSERT(left >= payload_len)
                 o->seed_id_pos += payload_len;
                 left -= payload_len;