Skip to content
Snippets Groups Projects
Commit 57b27ca1 authored by tewk's avatar tewk
Browse files

Added missing includes and fixed a few issues

added more assert checks
parent c70edac9
No related branches found
No related tags found
No related merge requests found
#include <assert.h> #include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <src/common/log.h> #include <src/common/log.h>
#include <src/common/xmalloc.h> #include <src/common/xmalloc.h>
#include <src/common/slurm_errno.h> #include <src/common/slurm_errno.h>
...@@ -10,6 +12,7 @@ ...@@ -10,6 +12,7 @@
#define MAX_BUFFER_SIZE ( ( 8192 * 10 ) ) #define MAX_BUFFER_SIZE ( ( 8192 * 10 ) )
static int assert_checks ( circular_buffer_t * buf ) ; static int assert_checks ( circular_buffer_t * buf ) ;
static int assert_checks_2 ( circular_buffer_t * buf ) ;
static int expand_buffer ( circular_buffer_t * buf ) ; static int expand_buffer ( circular_buffer_t * buf ) ;
static int shrink_buffer ( circular_buffer_t * buf ) ; static int shrink_buffer ( circular_buffer_t * buf ) ;
...@@ -56,6 +59,7 @@ int read_update ( circular_buffer_t * buf , unsigned int size ) ...@@ -56,6 +59,7 @@ int read_update ( circular_buffer_t * buf , unsigned int size )
/* before modifing the buffer lets do some sanity checks*/ /* before modifing the buffer lets do some sanity checks*/
assert ( size <= buf-> read_size ) ; assert ( size <= buf-> read_size ) ;
assert_checks ( buf ) ; assert_checks ( buf ) ;
assert_checks_2 ( buf ) ;
/*modify headning position of the buffer*/ /*modify headning position of the buffer*/
buf->head = buf->head + size ; buf->head = buf->head + size ;
...@@ -96,6 +100,7 @@ int read_update ( circular_buffer_t * buf , unsigned int size ) ...@@ -96,6 +100,7 @@ int read_update ( circular_buffer_t * buf , unsigned int size )
/* final sanity check */ /* final sanity check */
assert_checks ( buf ) ; assert_checks ( buf ) ;
assert_checks_2 ( buf ) ;
return SLURM_SUCCESS ; return SLURM_SUCCESS ;
} }
...@@ -111,6 +116,7 @@ int write_update ( circular_buffer_t * buf , unsigned int size ) ...@@ -111,6 +116,7 @@ int write_update ( circular_buffer_t * buf , unsigned int size )
/* before modifing the buffer lets do some sanity checks*/ /* before modifing the buffer lets do some sanity checks*/
assert ( size <= buf-> write_size ) ; assert ( size <= buf-> write_size ) ;
assert_checks ( buf ) ; assert_checks ( buf ) ;
assert_checks_2 ( buf ) ;
/*modify headning position of the buffer*/ /*modify headning position of the buffer*/
buf->tail = buf->tail + size ; buf->tail = buf->tail + size ;
...@@ -151,25 +157,21 @@ int write_update ( circular_buffer_t * buf , unsigned int size ) ...@@ -151,25 +157,21 @@ int write_update ( circular_buffer_t * buf , unsigned int size )
/* final sanity check */ /* final sanity check */
assert_checks ( buf ) ; assert_checks ( buf ) ;
assert_checks_2 ( buf ) ;
return SLURM_SUCCESS ; return SLURM_SUCCESS ;
} }
static int assert_checks ( circular_buffer_t * buf ) static int assert_checks_2 ( circular_buffer_t * buf )
{ {
/* sanity checks */ /* sanity checks */
assert ( buf != NULL ) ; /* buf struct is not null */
assert ( buf-> start == buf -> buffer ); /* stat hasn't moved */
assert ( ( buf -> start ) < ( buf -> end ) ); /* buf_end is after start */
assert ( buf-> end - buf -> start == buf -> buf_size ) ; /* buffer start and end haven't moved */
/* head pointer is between start and end */ /* head pointer is between start and end */
assert ( buf-> head >= buf -> start ) ; assert ( buf-> head >= buf -> start ) ;
assert ( buf-> head <= buf -> end ) ; assert ( buf-> head < buf -> end ) ;
/* tail pointer is between start and end */ /* tail pointer is between start and end */
assert ( buf-> tail >= buf -> start ) ; assert ( buf-> tail >= buf -> start ) ;
assert ( buf-> tail <= buf -> end ) ; assert ( buf-> tail < buf -> end ) ;
if ( buf->tail > buf->head ) if ( buf->tail > buf->head )
{ {
...@@ -186,6 +188,27 @@ static int assert_checks ( circular_buffer_t * buf ) ...@@ -186,6 +188,27 @@ static int assert_checks ( circular_buffer_t * buf )
assert ( buf -> write_size == buf -> buf_size ) ; assert ( buf -> write_size == buf -> buf_size ) ;
assert ( buf -> read_size == 0 ) ; assert ( buf -> read_size == 0 ) ;
} }
return SLURM_SUCCESS ;
}
static int assert_checks ( circular_buffer_t * buf )
{
/* sanity checks */
assert ( buf != NULL ) ; /* buf struct is not null */
assert ( buf-> start == buf -> buffer ); /* stat hasn't moved */
assert ( ( buf -> start ) < ( buf -> end ) ); /* buf_end is after start */
assert ( buf-> end - buf -> start == buf -> buf_size ) ; /* buffer start and end haven't moved */
/* head pointer is between start and end */
assert ( buf-> head >= buf -> start ) ;
assert ( buf-> head <= buf -> end ) ;
/* tail pointer is between start and end */
assert ( buf-> tail >= buf -> start ) ;
assert ( buf-> tail <= buf -> end ) ;
return SLURM_SUCCESS ; return SLURM_SUCCESS ;
} }
......
...@@ -12,7 +12,8 @@ typedef struct circular_buffer ...@@ -12,7 +12,8 @@ typedef struct circular_buffer
char * tail; /* end of the used portion of the buffer */ char * tail; /* end of the used portion of the buffer */
} circular_buffer_t ; } circular_buffer_t ;
int init_cir_buf ( circular_buffer_t ** buf_ptr ) ; int init_circular_buffer ( circular_buffer_t ** buf_ptr ) ;
void free_circular_buffer ( circular_buffer_t * buf_ptr ) ;
int read_update ( circular_buffer_t * buf , unsigned int size ) ; int read_update ( circular_buffer_t * buf , unsigned int size ) ;
int write_update ( circular_buffer_t * buf , unsigned int size ) ; int write_update ( circular_buffer_t * buf , unsigned int size ) ;
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment