diff options
author | FreeArtMan <dos21h@gmail.com> | 2017-08-21 23:40:07 +0100 |
---|---|---|
committer | FreeArtMan <dos21h@gmail.com> | 2017-08-21 23:40:07 +0100 |
commit | de6abbfddf1b0e15f444f4fe2a642d3a9775eec7 (patch) | |
tree | 7f243d875461034ce56d0d62d6ac302d66d0e702 | |
parent | 40e4b1da84808b4e592126e037601f5b6ccc0e25 (diff) | |
download | netbytes-de6abbfddf1b0e15f444f4fe2a642d3a9775eec7.tar.gz netbytes-de6abbfddf1b0e15f444f4fe2a642d3a9775eec7.zip |
Small bug fixed
-rw-r--r-- | netbytes.c | 12 | ||||
-rw-r--r-- | netbytes.h | 24 |
2 files changed, 19 insertions, 17 deletions
@@ -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: @@ -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; |