Commit df7ba781 by Marcus Winter

mtapi_network_c: buffer pop operations set values to zero on failure

parent 55a04f15
...@@ -107,6 +107,7 @@ int embb_mtapi_network_buffer_pop_front_int8( ...@@ -107,6 +107,7 @@ int embb_mtapi_network_buffer_pop_front_int8(
embb_mtapi_network_buffer_t * that, embb_mtapi_network_buffer_t * that,
int8_t * value) { int8_t * value) {
if (that->position + 1 > that->size) { if (that->position + 1 > that->size) {
*value = 0;
return 0; return 0;
} }
memcpy(value, that->data + that->position, 1); memcpy(value, that->data + that->position, 1);
...@@ -118,6 +119,7 @@ int embb_mtapi_network_buffer_pop_front_int16( ...@@ -118,6 +119,7 @@ int embb_mtapi_network_buffer_pop_front_int16(
embb_mtapi_network_buffer_t * that, embb_mtapi_network_buffer_t * that,
int16_t * value) { int16_t * value) {
if (that->position + 2 > that->size) { if (that->position + 2 > that->size) {
*value = 0;
return 0; return 0;
} }
memcpy(value, that->data + that->position, 2); memcpy(value, that->data + that->position, 2);
...@@ -129,6 +131,7 @@ int embb_mtapi_network_buffer_pop_front_int32( ...@@ -129,6 +131,7 @@ int embb_mtapi_network_buffer_pop_front_int32(
embb_mtapi_network_buffer_t * that, embb_mtapi_network_buffer_t * that,
int32_t * value) { int32_t * value) {
if (that->position + 4 > that->size) { if (that->position + 4 > that->size) {
*value = 0;
return 0; return 0;
} }
memcpy(value, that->data + that->position, 4); memcpy(value, that->data + that->position, 4);
...@@ -141,6 +144,7 @@ int embb_mtapi_network_buffer_pop_front_rawdata( ...@@ -141,6 +144,7 @@ int embb_mtapi_network_buffer_pop_front_rawdata(
int32_t size, int32_t size,
void * rawdata) { void * rawdata) {
if (that->position + size > that->size) { if (that->position + size > that->size) {
memset(rawdata, 0, (size_t)size);
return 0; return 0;
} }
memcpy(rawdata, that->data + that->position, (size_t)size); memcpy(rawdata, that->data + that->position, (size_t)size);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment