aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/roff.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-07-27 17:25:30 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-07-27 17:25:30 +0000
commit08971ae0d318ca4384957d962d049ba2a3a3f8a7 (patch)
tree0aaf5b8b644f84b6c9c95c5bc74d6d04573ab165 /roff.c
parent352d15302e33e6a449c94e758aae49ad40418f79 (diff)
downloadmandoc-08971ae0d318ca4384957d962d049ba2a3a3f8a7.tar.gz
mandoc-08971ae0d318ca4384957d962d049ba2a3a3f8a7.tar.zst
mandoc-08971ae0d318ca4384957d962d049ba2a3a3f8a7.zip
Have roffstr keep track of string lengths.
Diffstat (limited to 'roff.c')
-rw-r--r--roff.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/roff.c b/roff.c
index bfe388fa..b2332224 100644
--- a/roff.c
+++ b/roff.c
@@ -1,4 +1,4 @@
-/* $Id: roff.c,v 1.161 2011/07/27 14:58:28 kristaps Exp $ */
+/* $Id: roff.c,v 1.162 2011/07/27 17:25:30 kristaps Exp $ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -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 */
};
@@ -1472,13 +1474,16 @@ roff_setstr(struct roff *r, const char *name, const char *string,
/* 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)
@@ -1492,10 +1497,12 @@ roff_setstr(struct roff *r, const char *name, const char *string,
if (NULL == n->val) {
n->val = mandoc_malloc(newch);
*n->val = '\0';
+ n->valsz = newch - 1;
oldch = 0;
} else {
- oldch = strlen(n->val);
- n->val = mandoc_realloc(n->val, oldch + newch);
+ oldch = n->valsz;
+ n->val = mandoc_realloc(n->val, n->valsz + newch);
+ n->valsz += newch - 1;
}
/* Skip existing content in the destination buffer. */