-/* $Id: argv.c,v 1.39 2009/03/08 11:41:22 kristaps Exp $ */
+/* $Id: argv.c,v 1.41 2009/03/08 12:46:38 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
return(ARGV_ERROR);
if (NULL == (arg = *v)) {
- v = xcalloc(1, sizeof(struct mdoc_arg));
+ *v = xcalloc(1, sizeof(struct mdoc_arg));
arg = *v;
- }
+ }
arg->argc++;
arg->argv = xrealloc(arg->argv, arg->argc *
- sizeof(struct mdoc_arg));
+ sizeof(struct mdoc_argv));
(void)memcpy(&arg->argv[(int)arg->argc - 1],
&tmp, sizeof(struct mdoc_argv));
{
int i, j;
- if (p->refcnt && --(p->refcnt) > 0)
+ if (NULL == p)
return;
+ if (p->refcnt) {
+ --(p->refcnt);
+ if (p->refcnt)
+ return;
+ }
+
+ assert(p->argc);
+
/* LINTED */
for (i = 0; i < (int)p->argc; i++) {
if (0 == p->argv[i].sz)
/* LINTED */
for (j = 0; j < (int)p->argv[i].sz; j++)
free(p->argv[i].value[j]);
+
free(p->argv[i].value);
}
- if (p->argc)
- free(p->argv);
+ free(p->argv);
free(p);
}
v->value = xrealloc(v->value,
(v->sz + 5) * sizeof(char *));
- v->value[(int)v->sz] = p;
+ v->value[(int)v->sz] = xstrdup(p);
}
if (v->sz)
v->sz = 1;
v->value = xcalloc(1, sizeof(char *));
- v->value[0] = p;
+ v->value[0] = xstrdup(p);
return(1);
}
v->sz = 1;
v->value = xcalloc(1, sizeof(char *));
- v->value[0] = p;
+ v->value[0] = xstrdup(p);
return(1);
}