From d9fe0567cd2922a8a2b9114d11ebb593e09ac557 Mon Sep 17 00:00:00 2001 From: Dinh Cong Toan Date: Fri, 4 Jun 2021 11:08:16 +0700 Subject: dlt_common: Increment size after memcpy() This commit fixes to increment read and write point only if memcpy() succeeded in dlt_buffer_read_block() and dlt_buffer_write_block(). Related issues: https://github.com/GENIVI/dlt-daemon/issues/305 Signed-off-by: Sugiura, Saya --- src/shared/dlt_common.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c index 22ae5e8..c489d2d 100644 --- a/src/shared/dlt_common.c +++ b/src/shared/dlt_common.c @@ -2435,8 +2435,8 @@ void dlt_buffer_write_block(DltBuffer *buf, int *write, const unsigned char *dat /* write two blocks */ memcpy(buf->mem + *write, data, buf->size - (unsigned int) (*write)); memcpy(buf->mem, data + buf->size - *write, size - buf->size + (unsigned int) (*write)); + *write += (int) (size - buf->size); } - *write += (int) (size - buf->size); } } else { @@ -2462,9 +2462,8 @@ void dlt_buffer_read_block(DltBuffer *buf, int *read, unsigned char *data, unsig /* read two blocks */ memcpy(data, buf->mem + *read, buf->size - (unsigned int)(*read)); memcpy(data + buf->size - *read, buf->mem, size - buf->size + (unsigned int)(*read)); + *read += (int)(size - buf->size); } - - *read += (int)(size - buf->size); } } else { -- cgit v1.2.1