X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fngircd%2Farray.c;h=4cc793f18c02b3f4bea6dd1f46ed2914441740a5;hb=7207bef418c655107d3076b20dd797418ad82cd7;hp=75106f623926edb8c85cf2736d3aaf67325761a5;hpb=994a003aba9aac4a8adca7f4f4fec0889b0f2bb1;p=ngircd-alex.git diff --git a/src/ngircd/array.c b/src/ngircd/array.c index 75106f62..4cc793f1 100644 --- a/src/ngircd/array.c +++ b/src/ngircd/array.c @@ -5,28 +5,32 @@ * (at your option) any later version. * Please read the file COPYING, README and AUTHORS for more information. * - * functions to dynamically allocate arrays. + * libarray - dynamically allocate arrays. * Copyright (c) 2005 Florian Westphal (westphal@foo.fh-furtwangen.de) - * */ -#include "array.h" +/** + * @file + * Functions to dynamically allocate arrays. + */ -static char UNUSED id[] = "$Id: array.c,v 1.15 2007/11/18 15:05:35 alex Exp $"; +/* Additionan debug messages related to array handling: 0=off / 1=on */ +#define DEBUG_ARRAY 0 -#include +#include "array.h" +#include #include #include +#include -#include "log.h" - -/* Enable more Debug messages in alloc / append / memmove code. */ -/* #define DEBUG_ARRAY */ +#if DEBUG_ARRAY +# include "log.h" +#endif +#define array_UNUSABLE(x) ( !(x)->mem ) -#define array_UNUSABLE(x) ( !(x)->mem || (0 == (x)->allocated) ) static bool safemult_sizet(size_t a, size_t b, size_t *res) { @@ -63,7 +67,7 @@ array_alloc(array * a, size_t size, size_t pos) return NULL; if (a->allocated < alloc) { -#ifdef DEBUG_ARRAY +#if DEBUG_ARRAY Log(LOG_DEBUG, "array_alloc(): changing size from %u to %u bytes.", a->allocated, alloc); #endif @@ -93,6 +97,7 @@ array_length(const array * const a, size_t membersize) if (array_UNUSABLE(a)) return 0; + assert(a->allocated); return membersize ? a->used / membersize : 0; } @@ -104,6 +109,7 @@ array_copy(array * dest, const array * const src) if (array_UNUSABLE(src)) return false; + assert(src->allocated); return array_copyb(dest, src->mem, src->used); } @@ -162,7 +168,7 @@ array_catb(array * dest, const char *src, size_t len) assert(ptr != NULL); -#ifdef DEBUG_ARRAY +#if DEBUG_ARRAY Log(LOG_DEBUG, "array_catb(): appending %u bytes to array (now %u bytes in array).", len, tmp); @@ -242,7 +248,7 @@ void array_free(array * a) { assert(a != NULL); -#ifdef DEBUG_ARRAY +#if DEBUG_ARRAY Log(LOG_DEBUG, "array_free(): %u bytes free'd (%u bytes still used at time of free()).", a->allocated, a->used); @@ -308,7 +314,7 @@ array_moveleft(array * a, size_t membersize, size_t pos) if (!bytepos) return; /* nothing to do */ -#ifdef DEBUG_ARRAY +#if DEBUG_ARRAY Log(LOG_DEBUG, "array_moveleft(): %u bytes used in array, starting at position %u.", a->used, bytepos);