#include <string.h>
#include <stdarg.h>
#include <stdio.h>
+#include <xmalloc.h>
#include "strbuf.h"
};
struct pa_strbuf *pa_strbuf_new(void) {
- struct pa_strbuf *sb = malloc(sizeof(struct pa_strbuf));
- assert(sb);
+ struct pa_strbuf *sb = pa_xmalloc(sizeof(struct pa_strbuf));
sb->length = 0;
sb->head = sb->tail = NULL;
return sb;
while (sb->head) {
struct chunk *c = sb->head;
sb->head = sb->head->next;
- free(c);
+ pa_xfree(c);
}
- free(sb);
+ pa_xfree(sb);
}
char *pa_strbuf_tostring(struct pa_strbuf *sb) {
struct chunk *c;
assert(sb);
- t = malloc(sb->length+1);
- assert(t);
+ t = pa_xmalloc(sb->length+1);
e = t;
for (c = sb->head; c; c = c->next) {
if (!l)
return;
- c = malloc(sizeof(struct chunk)+l);
- assert(c);
+ c = pa_xmalloc(sizeof(struct chunk)+l);
c->next = NULL;
c->length = l;
for(;;) {
va_list ap;
- c = realloc(c, sizeof(struct chunk)+size);
- assert(c);
+ c = pa_xrealloc(c, sizeof(struct chunk)+size);
va_start(ap, format);
r = vsnprintf(c->text, size, format, ap);