=================================================================== RCS file: /cvs/mandoc/roff.c,v retrieving revision 1.162 retrieving revision 1.163 diff -u -p -r1.162 -r1.163 --- mandoc/roff.c 2011/07/27 17:25:30 1.162 +++ mandoc/roff.c 2011/07/27 20:55:28 1.163 @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.162 2011/07/27 17:25:30 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 @@ -1497,12 +1497,10 @@ roff_setstr(struct roff *r, const char *name, const ch if (NULL == n->val) { n->val = mandoc_malloc(newch); *n->val = '\0'; - n->valsz = newch - 1; oldch = 0; } else { oldch = n->valsz; - n->val = mandoc_realloc(n->val, n->valsz + newch); - n->valsz += newch - 1; + n->val = mandoc_realloc(n->val, oldch + newch); } /* Skip existing content in the destination buffer. */ @@ -1522,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 *