diff options
-rw-r--r-- | action.c | 14 | ||||
-rw-r--r-- | argv.c | 25 | ||||
-rw-r--r-- | mdoc.c | 2 | ||||
-rw-r--r-- | validate.c | 6 |
4 files changed, 27 insertions, 20 deletions
@@ -514,7 +514,7 @@ post_bl_width(struct mdoc *m) size_t width; int i, tok; char buf[32]; - char **p; + char *p; if (NULL == m->last->args) return(merr(m, ENOWIDTH)); @@ -526,29 +526,29 @@ post_bl_width(struct mdoc *m) if (i == (int)m->last->args->argc) return(merr(m, ENOWIDTH)); - p = &m->last->args->argv[i].value[0]; + p = m->last->args->argv[i].value[0]; /* * If the value to -width is a macro, then we re-write it to be * the macro's width as set in share/tmac/mdoc/doc-common. */ - if (xstrcmp(*p, "Ds")) + if (xstrcmp(p, "Ds")) width = 8; - else if (MDOC_MAX == (tok = mdoc_tokhash_find(m->htab, *p))) + else if (MDOC_MAX == (tok = mdoc_tokhash_find(m->htab, p))) return(1); else if (0 == (width = mdoc_macro2len(tok))) return(mwarn(m, WNOWIDTH)); mdoc_msg(m, "re-writing %s argument: %s -> %zun", - mdoc_argnames[MDOC_Width], *p, width); + mdoc_argnames[MDOC_Width], p, width); /* The value already exists: free and reallocate it. */ (void)snprintf(buf, sizeof(buf), "%zun", width); - free(*p); - *p = xstrdup(buf); + free(m->last->args->argv[i].value[0]); + m->last->args->argv[i].value[0] = xstrdup(buf); return(1); } @@ -273,13 +273,13 @@ mdoc_argv(struct mdoc *mdoc, int line, int tok, 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)); @@ -293,8 +293,13 @@ mdoc_argv_free(struct mdoc_arg *p) { int i, j; - if (p->refcnt && --(p->refcnt) > 0) - return; + if (p->refcnt) { + --(p->refcnt); + if (p->refcnt) + return; + } + + assert(p->argc); /* LINTED */ for (i = 0; i < (int)p->argc; i++) { @@ -303,11 +308,11 @@ mdoc_argv_free(struct mdoc_arg *p) /* 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); } @@ -742,7 +747,7 @@ argv_multi(struct mdoc *mdoc, int line, 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) @@ -770,7 +775,7 @@ argv_opt_single(struct mdoc *mdoc, int line, v->sz = 1; v->value = xcalloc(1, sizeof(char *)); - v->value[0] = p; + v->value[0] = xstrdup(p); return(1); } @@ -795,7 +800,7 @@ argv_single(struct mdoc *mdoc, int line, v->sz = 1; v->value = xcalloc(1, sizeof(char *)); - v->value[0] = p; + v->value[0] = xstrdup(p); return(1); } @@ -519,6 +519,8 @@ parsemacro(struct mdoc *m, int ln, char *buf) break; } + /* FIXME: be able to skip unknown macro lines! */ + mac[i - 1] = 0; if (i == 5 || i <= 2) { @@ -638,6 +638,7 @@ check_args(struct mdoc *m, const struct mdoc_node *n) if (NULL == n->args) return(1); + assert(n->args->argc); for (i = 0; i < (int)n->args->argc; i++) if ( ! check_argv(m, n, &n->args->argv[i])) return(0); @@ -684,8 +685,7 @@ check_text(struct mdoc *mdoc, int line, int pos, const char *p) p += (int)c - 1; continue; } - return(mdoc_perr(mdoc, line, pos, - "invalid escape sequence: %s", p)); + return(mdoc_perr(mdoc, line, pos, "invalid escape")); } return(1); @@ -891,7 +891,7 @@ static int pre_an(PRE_ARGS) { - if (n->args && 1 >= n->args->argc) + if (NULL == n->args || 1 == n->args->argc) return(1); return(mdoc_nerr(mdoc, n, "only one argument allowed")); } |