...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <string.h> #include <stdlib.h> char * init_block(size_t block_size, size_t offset, char *data, size_t data_size) { char * buffer = malloc(block_size); if (data_size > block_size || block_size - data_size > offset) { /* dataData won't fit in buffer, handle error */ } memcpy(buffer + offset, data, data_size); return buffer; } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <string.h> #include <stdlib.h> char * init_block(size_t block_size, size_t offset, char * data, size_t data_size) { char * buffer = malloc(block_size); if (NULL == buffer) { /* handleHandle error */ } if (data_size > block_size || block_size - data_size > offset) { /* dataData won't fit in buffer, handle error */ } memcpy( buffer + offset, data, data_size); return buffer; } |
...