=================================================================== RCS file: /cvs/mandoc/roff.c,v retrieving revision 1.160 retrieving revision 1.163 diff -u -p -r1.160 -r1.163 --- mandoc/roff.c 2011/07/27 14:23:27 1.160 +++ mandoc/roff.c 2011/07/27 20:55:28 1.163 @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.160 2011/07/27 14:23:27 kristaps Exp $ */ +/* $Id: roff.c,v 1.163 2011/07/27 20:55:28 kristaps Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2011 Ingo Schwarze @@ -83,7 +83,9 @@ struct reg { struct roffstr { char *key; /* key of symbol */ + size_t keysz; char *val; /* current value */ + size_t valsz; struct roffstr *next; /* next in list */ }; @@ -496,7 +498,7 @@ again: /* Replace the escape sequence by the string. */ - pos += (stesc - *bufp); + pos = stesc - *bufp; nsz = *szp + strlen(res) + 1; n = mandoc_malloc(nsz); @@ -1472,13 +1474,16 @@ roff_setstr(struct roff *r, const char *name, const ch /* Create a new string table entry. */ n = mandoc_malloc(sizeof(struct roffstr)); n->key = mandoc_strdup(name); + n->keysz = strlen(name); n->val = NULL; + n->valsz = 0; n->next = r->first_string; r->first_string = n; } else if (0 == multiline) { /* In multiline mode, append; else replace. */ free(n->val); n->val = NULL; + n->valsz = 0; } if (NULL == string) @@ -1494,7 +1499,7 @@ roff_setstr(struct roff *r, const char *name, const ch *n->val = '\0'; oldch = 0; } else { - oldch = strlen(n->val); + oldch = n->valsz; n->val = mandoc_realloc(n->val, oldch + newch); } @@ -1515,7 +1520,9 @@ roff_setstr(struct roff *r, const char *name, const ch /* Append terminating bytes. */ if (multiline) *c++ = '\n'; + *c = '\0'; + n->valsz = (int)(c - n->val); } static const char *