From de6abbfddf1b0e15f444f4fe2a642d3a9775eec7 Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Mon, 21 Aug 2017 23:40:07 +0100 Subject: Small bug fixed --- netbytes.c | 12 +++++++----- netbytes.h | 24 ++++++++++++------------ 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/netbytes.c b/netbytes.c index 8831b33..07c1301 100644 --- a/netbytes.c +++ b/netbytes.c @@ -519,7 +519,7 @@ int nb_load( netbyte_store *store, uint8_t *data ) __NBT_SIZE size; memcpy( &size, c, sizeof(__NBT_SIZE) ); - printf("size: %d\n", size); + printf("NB_LOAD size: %d\n", size); size -= sizeof(__NBT_SIZE); c += sizeof(__NBT_SIZE); @@ -600,12 +600,14 @@ int nb_load( netbyte_store *store, uint8_t *data ) } case NBT_U32: { - nb_u32 *u32 = malloc( sizeof(nb_u32) ); - - memcpy( u32, c, sizeof(nb_u32) ); + //FIXIT in all places + //nb_u32 *u32 = malloc( sizeof(nb_u32) ); + nb_u32 u32; + + memcpy( &u32, c, sizeof(nb_u32) ); c += sizeof(nb_u32); - nb_add_u32( store, u32 ); + nb_add_u32( store, &u32 ); break; } case NBT_U32ARRAY: diff --git a/netbytes.h b/netbytes.h index a77ef24..6e008bc 100644 --- a/netbytes.h +++ b/netbytes.h @@ -47,25 +47,25 @@ #define __NBT_MAX_TYPES (256) //creating netbyte structure -typedef struct __nb_type { +typedef struct __attribute__((packed)) __nb_type { __NBT_TYPED type; uint8_t *nb_val; -} __nb_type; +} __nb_type ; -typedef struct netbyte_store +typedef struct __attribute__((packed)) netbyte_store { __NBT_SIZE size; int count; __nb_type types[__NBT_MAX_TYPES]; } netbyte_store; -typedef struct nb_u8 +typedef struct __attribute__((packed)) nb_u8 { __NBT_TYPED type; uint8_t val; } nb_u8; -typedef struct nb_u8arr +typedef struct __attribute__((packed)) nb_u8arr { __NBT_TYPED type; __NBT_U8ARR_LEN len; @@ -74,13 +74,13 @@ typedef struct nb_u8arr /*-----------------*/ -typedef struct nb_u16 +typedef struct __attribute__((packed)) nb_u16 { __NBT_TYPED type; uint16_t val; } nb_u16; -typedef struct nb_u16arr +typedef struct __attribute__((packed)) nb_u16arr { __NBT_TYPED type; __NBT_U16ARR_LEN len; @@ -89,13 +89,13 @@ typedef struct nb_u16arr /*-----------------*/ -typedef struct nb_u32 +typedef struct __attribute__((packed)) nb_u32 { __NBT_TYPED type; uint32_t val; } nb_u32; -typedef struct nb_u32arr +typedef struct __attribute__((packed)) nb_u32arr { __NBT_TYPED type; __NBT_U32ARR_LEN len; @@ -104,13 +104,13 @@ typedef struct nb_u32arr /*------------------*/ -typedef struct nb_u64 +typedef struct __attribute__((packed)) nb_u64 { __NBT_TYPED type; uint64_t val; } nb_u64; -typedef struct nb_u64arr +typedef struct __attribute__((packed)) nb_u64arr { __NBT_TYPED type; __NBT_U64ARR_LEN len; @@ -118,7 +118,7 @@ typedef struct nb_u64arr } nb_u64arr; //loading/parsing netbyte structure -typedef struct netbyte_load +typedef struct __attribute__((packed)) netbyte_load { __NBT_SIZE size; uint8_t *buf; -- cgit v1.2.3