Added ASSERT statements.

This commit is contained in:
Robert James Kaes committed 2001-05-23 18:01:23 +00:00
1 parent 86313eb6f5
commit d32e0d1ccb
4 files changed
+60 -5

No files matched your search

+23 -2
View File
@@ -1,4 +1,4 @@
/* $Id: buffer.c,v 1.3 2000-09-11 23:41:32 rjkaes Exp $
/* $Id: buffer.c,v 1.4 2001-05-23 18:01:23 rjkaes Exp $
*
* The buffer used in each connection is a linked list of lines. As the lines
* are read in and written out the buffer expands and contracts. Basically,
@@ -48,6 +48,8 @@ struct buffer_s {
*/
unsigned int buffer_size(struct buffer_s *buffptr)
{
assert(buffptr != NULL);
return buffptr->size;
}
@@ -59,6 +61,8 @@ static struct bufline_s *makenewline(unsigned char *data, unsigned int length)
{
struct bufline_s *newline;
assert(data != NULL);
if (!(newline = malloc(sizeof(struct bufline_s))))
return NULL;
@@ -75,6 +79,8 @@ static struct bufline_s *makenewline(unsigned char *data, unsigned int length)
*/
static void free_line(struct bufline_s *line)
{
assert(line != NULL);
if (!line)
return;
@@ -108,6 +114,8 @@ void delete_buffer(struct buffer_s *buffptr)
{
struct bufline_s *next;
assert(buffptr != NULL);
while (BUFFER_HEAD(buffptr)) {
next = BUFFER_HEAD(buffptr)->next;
free_line(BUFFER_HEAD(buffptr));
@@ -127,6 +135,9 @@ static int add_to_buffer(struct buffer_s *buffptr, unsigned char *data,
{
struct bufline_s *newline;
assert(buffptr != NULL);
assert(data != NULL);
if (!(newline = makenewline(data, length)))
return -1;
@@ -148,6 +159,8 @@ static struct bufline_s *remove_from_buffer(struct buffer_s *buffptr)
{
struct bufline_s *line;
assert(buffptr != NULL);
if (!BUFFER_HEAD(buffptr) && !BUFFER_TAIL(buffptr)) {
line = BUFFER_HEAD(buffptr);
BUFFER_HEAD(buffptr) = BUFFER_TAIL(buffptr) = NULL;
@@ -176,6 +189,9 @@ int readbuff(int fd, struct buffer_s *buffptr)
unsigned char inbuf[MAXBUFFSIZE];
unsigned char *buffer;
assert(fd >= 0);
assert(buffptr != NULL);
if (buffer_size(buffptr) >= MAXBUFFSIZE)
return 0;
@@ -221,7 +237,12 @@ int readbuff(int fd, struct buffer_s *buffptr)
int writebuff(int fd, struct buffer_s *buffptr)
{
int bytessent;
struct bufline_s *line = BUFFER_HEAD(buffptr);
struct bufline_s *line;
assert(fd >= 0);
assert(buffptr != NULL);
line = BUFFER_HEAD(buffptr);
if (buffer_size(buffptr) <= 0)
return 0;