hmm slight problem:
I have this kind of thing:
Code:
int some_function(char *message) {
DATE tx_header;
uint8_t options[64]; // this isn't always totally full (normally only the first two elements) so hence the strlen below:
void* tx_buffer = malloc(sizeof(tx_header) + strlen(options) + strlen(message));
// fill the transmit buffer
memcpy(tx_buffer, &tx_header, sizeof(tx_header));
memcpy(tx_buffer + sizeof(tx_header), options, strlen(options));
memcpy(tx_buffer + sizeof(tx_header) + strlen(options), message, strlen(message));
printf("strlen(options): %d\n", strlen(options));
printf("strlen(message): %d\n", strlen(message));
printf("sizeof(tx_header) is : %d\n", sizeof(tx_header));
printf("sizeof(tx_buffer) is: %d, strlen(tx_buffer) is: %d\n", sizeof(tx_buffer), strlen(tx_buffer));
}
this gives the following output with a message of :"the quick" (minus quotes):
Code:
strlen(options): 2 // two options
strlen(message): 10 // 9 characters plus the \n
sizeof(tx_header) is : 12 // this should be twelve (this is a differen't struct to the one in the first post)
sizeof(tx_buffer) is: 4, strlen(tx_buffer) is: 9 // what the hell?