diff options
Diffstat (limited to 'src/shared/dlt_common.c')
-rw-r--r-- | src/shared/dlt_common.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c index 8757296..c597468 100644 --- a/src/shared/dlt_common.c +++ b/src/shared/dlt_common.c @@ -2431,7 +2431,10 @@ void dlt_buffer_write_block(DltBuffer *buf, int *write, const unsigned char *dat *write += (int) size; } else { - if(buf->size > (unsigned int) (*write)) { + /* when (*write) = buf->size, write only the second block + * and update write position correspondingly. + */ + if((unsigned int) (*write) <= buf->size) { /* 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)); @@ -2458,11 +2461,14 @@ void dlt_buffer_read_block(DltBuffer *buf, int *read, unsigned char *data, unsig *read += (int)size; } else { - if (buf->size > (unsigned int)(*read)) { + /* when (*read) = buf->size, read only the second block + * and update read position correspondingly. + */ + if ((unsigned int)(*read) <= buf->size) { /* 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); } } } |