summaryrefslogtreecommitdiffstats
path: root/mdoc_argv.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2010-04-03 14:02:10 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2010-04-03 14:02:10 +0000
commite2afc6f7327836c862d47783571b5f518d1bb517 (patch)
tree762ba6eca1ca365d77753d75c94391275b6595ba /mdoc_argv.c
parentd9b4ef04d59b4dfd661c39eee2c8bb5faafc55cf (diff)
downloadmandoc-e2afc6f7327836c862d47783571b5f518d1bb517.tar.gz
Merged Ingo Schwarze's patch (plus documentation) for removing extraneous list types, which happens fairly often.
Diffstat (limited to 'mdoc_argv.c')
-rw-r--r--mdoc_argv.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/mdoc_argv.c b/mdoc_argv.c
index f1be3755..2aaa8a61 100644
--- a/mdoc_argv.c
+++ b/mdoc_argv.c
@@ -288,7 +288,7 @@ mdoc_argv(struct mdoc *m, int line, enum mdoct tok,
void
mdoc_argv_free(struct mdoc_arg *p)
{
- int i, j;
+ int i;
if (NULL == p)
return;
@@ -300,23 +300,28 @@ mdoc_argv_free(struct mdoc_arg *p)
}
assert(p->argc);
- /* LINTED */
- for (i = 0; i < (int)p->argc; i++) {
- if (0 == p->argv[i].sz)
- continue;
- if (NULL == p->argv[i].value)
- continue;
+ for (i = (int)p->argc - 1; i >= 0; i--)
+ mdoc_argn_free(p, i);
+
+ free(p->argv);
+ free(p);
+}
+
- /* LINTED */
- for (j = 0; j < (int)p->argv[i].sz; j++)
- if (p->argv[i].value[j])
- free(p->argv[i].value[j]);
+void
+mdoc_argn_free(struct mdoc_arg *p, int iarg)
+{
+ struct mdoc_argv *arg = &p->argv[iarg];
+ int j;
- free(p->argv[i].value);
+ if (arg->sz && arg->value) {
+ for (j = (int)arg->sz - 1; j >= 0; j--)
+ free(arg->value[j]);
+ free(arg->value);
}
- free(p->argv);
- free(p);
+ for (--p->argc; iarg < (int)p->argc; iarg++)
+ p->argv[iarg] = p->argv[iarg+1];
}