summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/buffer.c42
1 files changed, 39 insertions, 3 deletions
diff --git a/common/buffer.c b/common/buffer.c
index a5b18a7..0bba3bf 100644
--- a/common/buffer.c
+++ b/common/buffer.c
@@ -18,6 +18,8 @@
void buffer_bump(ha_buffer_t* buf, int count)
{
+ ASSERT(buf && count);
+
if(ha_buferr(buf))
return;
@@ -49,12 +51,15 @@ void buffer_bump(ha_buffer_t* buf, int count)
void ha_bufinit(ha_buffer_t* buf)
{
+ ASSERT(buf);
memset(buf, 0, sizeof(*buf));
ha_bufreset(buf);
}
void ha_bufreset(ha_buffer_t* buf)
{
+ ASSERT(buf);
+
if(!buf->_dt || buf->_al == 0)
{
buf->_dt = (char*)reallocf(buf->_dt, 256 * sizeof(char));
@@ -75,6 +80,8 @@ void ha_bufreset(ha_buffer_t* buf)
void ha_buffree(ha_buffer_t* buf)
{
+ ASSERT(buf);
+
if(buf->_dt)
free(buf->_dt);
@@ -87,6 +94,9 @@ int ha_bufreadline(int fd, ha_buffer_t* buf)
{
int l;
+ ASSERT(buf);
+ ASSERT(fd != -1);
+
if(ha_buferr(buf))
return 0;
@@ -142,6 +152,8 @@ char* ha_bufparseword(ha_buffer_t* buf, const char* delims)
{
char* word = NULL;
+ ASSERT(buf && delims);
+
if(ha_buferr(buf))
return NULL;
@@ -191,6 +203,8 @@ char* ha_bufparseline(ha_buffer_t* buf, int trim)
char* t;
char* line = NULL;
+ ASSERT(buf);
+
if(ha_buferr(buf))
return NULL;
@@ -237,6 +251,8 @@ char* ha_bufmcat(ha_buffer_t* buf, ...)
const char* str;
va_list ap;
+ ASSERT(buf);
+
va_start(ap, buf);
if(ha_buferr(buf))
@@ -267,12 +283,18 @@ char* ha_bufmcat(ha_buffer_t* buf, ...)
char* ha_bufcpy(ha_buffer_t* buf, const char* src)
{
- size_t len = strlen(src);
+ size_t len;
+
+ ASSERT(buf && src);
+
+ len = strlen(src);
return ha_bufncpy(buf, src, len);
}
char* ha_bufncpy(ha_buffer_t* buf, const char* src, size_t len)
{
+ ASSERT(buf && src);
+
if(ha_buferr(buf))
return NULL;
@@ -296,6 +318,8 @@ void* ha_bufmalloc(ha_buffer_t* buf, size_t sz)
{
void* ret;
+ ASSERT(buf && sz);
+
if(ha_buferr(buf))
return NULL;
@@ -315,9 +339,13 @@ void* ha_bufmalloc(ha_buffer_t* buf, size_t sz)
void* ha_bufmemdup(ha_buffer_t* buf, const void* src, size_t bytes)
{
- void* mem = ha_bufmalloc(buf, bytes);
- if(mem)
+ void* mem;
+
+ ASSERT(buf && src && bytes);
+
+ if((mem = ha_bufmalloc(buf, bytes)) != NULL)
memcpy(mem, src, bytes);
+
return mem;
}
@@ -357,6 +385,8 @@ char* ha_bufenc64(ha_buffer_t* buf, const void* source, size_t len)
unsigned char* src = (unsigned char*)source;
size_t i;
+ ASSERT(buf && source && len);
+
if(ha_buferr(buf))
return NULL;
@@ -422,6 +452,8 @@ void* ha_bufdec64(ha_buffer_t* buf, const char* src, size_t bytes)
char* pos;
size_t done = 0;
+ ASSERT(buf && src);
+
if(ha_buferr(buf))
return NULL;
@@ -491,6 +523,8 @@ char* ha_bufenchex(ha_buffer_t* buf, const void* source, size_t len)
unsigned char* src = (unsigned char*)source;
unsigned char j;
+ ASSERT(buf && source && len);
+
buffer_bump(buf, (len * 2) + 1);
if(ha_buferr(buf))
@@ -524,6 +558,8 @@ void* ha_bufdechex(ha_buffer_t* buf, const char* src, size_t bytes)
size_t done = 0;
char* pos;
+ ASSERT(buf && src);
+
if(bytes != 0)
{
buffer_bump(buf, bytes + 1);