diff options
author | Alexander Wenzel <Alexander.AW.Wenzel@bmw.de> | 2013-11-29 08:44:53 +0100 |
---|---|---|
committer | Alexander Wenzel <Alexander.AW.Wenzel@bmw.de> | 2014-01-10 07:15:44 +0100 |
commit | 2ac9cc302f661cc4955ad2901cc02ea84c3ff81f (patch) | |
tree | 3ad327c96fbfdb74d9c07b8d3c6cb90bc22e9285 | |
parent | cc157f0df7b05a1643af759407e070df213ae849 (diff) | |
download | DLT-daemon-2ac9cc302f661cc4955ad2901cc02ea84c3ff81f.tar.gz |
Added further checks to dlt_buffer.
Signed-off-by: Alexander Wenzel <Alexander.AW.Wenzel@bmw.de>
-rwxr-xr-x | src/shared/dlt_common.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c index f0657e6..52eabed 100755 --- a/src/shared/dlt_common.c +++ b/src/shared/dlt_common.c @@ -2441,13 +2441,15 @@ int dlt_buffer_free_static(DltBuffer *buf) int dlt_buffer_free_dynamic(DltBuffer *buf) { - if(!buf->mem) { + if(!buf->shm) { // buffer not initialised dlt_log(LOG_ERR,"Buffer: Buffer not initialised\n"); return -1; /* ERROR */ } free(buf->shm); + buf->shm = 0; + buf->mem = 0; return 0; } @@ -2603,7 +2605,7 @@ int dlt_buffer_push3(DltBuffer *buf,const unsigned char *data1,unsigned int size int write, read, count; DltBufferBlockHead head; - if(!buf->mem) { + if(!buf->shm) { // buffer not initialised dlt_log(LOG_ERR,"Buffer: Buffer not initialised\n"); return -1; /* ERROR */ @@ -2669,7 +2671,7 @@ int dlt_buffer_get(DltBuffer *buf,unsigned char *data, int max_size,int delete) char head_compare[] = DLT_BUFFER_HEAD; DltBufferBlockHead head; - if(!buf->mem) { + if(!buf->shm) { // shm not initialised dlt_log(LOG_ERR,"Buffer: SHM not initialised\n"); return -1; /* ERROR */ @@ -2807,6 +2809,10 @@ void dlt_buffer_status(DltBuffer *buf) int write, read, count; char str[256]; + /* check if buffer available */ + if(!buf->shm) + return; + write = ((int*)(buf->shm))[0]; read = ((int*)(buf->shm))[1]; count = ((int*)(buf->shm))[2]; @@ -2828,6 +2834,10 @@ int dlt_buffer_get_used_size(DltBuffer *buf) { int write, read, count; + /* check if buffer available */ + if(!buf->shm) + return 0; + write = ((int*)(buf->shm))[0]; read = ((int*)(buf->shm))[1]; count = ((int*)(buf->shm))[2]; @@ -2843,7 +2853,11 @@ int dlt_buffer_get_used_size(DltBuffer *buf) int dlt_buffer_get_message_count(DltBuffer *buf) { - return ((int*)(buf->shm))[2]; + /* check if buffer available */ + if(!buf->shm) + return 0; + + return ((int*)(buf->shm))[2]; } #if !defined (__WIN32__) |