X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fq.c;h=94c0b3e6df0ab8bab7709b9da2cfdc542b21c6fd;hb=d9028caacb25b27d07c6b642556e8d372bb267a1;hp=0a9cb9f8692b8b968316b6a4b134fdfa9d8abd46;hpb=ab2f7a4cd0eda09ff3af29058c45d098f869b598;p=swftools.git diff --git a/lib/q.c b/lib/q.c index 0a9cb9f..94c0b3e 100644 --- a/lib/q.c +++ b/lib/q.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -47,6 +48,21 @@ char*qstrndup(const char*string, int len) { return strdup_n(string, len); } +char* allocprintf(const char*format, ...) +{ + va_list arglist1; + va_start(arglist1, format); + char dummy; + int l = vsnprintf(&dummy, 1, format, arglist1); + va_end(arglist1); + + va_list arglist2; + va_start(arglist2, format); + char*buf = malloc(l+1); + vsnprintf(buf, l+1, format, arglist2); + va_end(arglist2); + return buf; +} // ------------------------------- mem_t -------------------------------------- @@ -249,6 +265,7 @@ void* heap_max(heap_t*h) void* heap_chopmax(heap_t*h) { void*p = h->elements[0]; + assert(h->size); h->elements[0] = h->elements[--h->size]; down(h,0); return p; @@ -1181,6 +1198,8 @@ void dict_destroy_shallow(dict_t*dict) void dict_destroy(dict_t*dict) { + if(!dict) + return; dict_clear(dict); rfx_free(dict); }