aboutsummaryrefslogtreecommitdiffstats
path: root/src/vty/utils.c
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2013-08-06 14:29:15 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2013-08-06 14:56:35 +0200
commitcd195fa267b1869156e6d675032fdafe3035bf5e (patch)
treecb3e84282faf43d336601a85c366111af729ab6e /src/vty/utils.c
parentae15a2cac1a01e98e34b4ccd8932ae8f1b99186c (diff)
vty: Support multi-char separators and end strings
In vty_cmd_string_from_valstr() include the real string lengths of the sep and end arguments into the buffer size calculation.
Diffstat (limited to 'src/vty/utils.c')
-rw-r--r--src/vty/utils.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/vty/utils.c b/src/vty/utils.c
index 88932fa8..d0ad431d 100644
--- a/src/vty/utils.c
+++ b/src/vty/utils.c
@@ -69,12 +69,13 @@ char *vty_cmd_string_from_valstr(void *ctx, const struct value_string *vals,
const char *end, int do_lower)
{
int len = 0, offset = 0, ret, rem;
- int size = strlen(prefix);
+ int size = strlen(prefix) + strlen(end);
+ int sep_len = strlen(sep);
const struct value_string *vs;
char *str;
for (vs = vals; vs->value || vs->str; vs++)
- size += strlen(vs->str) + 1;
+ size += strlen(vs->str) + sep_len;
rem = size;
str = talloc_zero_size(ctx, size);
@@ -102,8 +103,8 @@ char *vty_cmd_string_from_valstr(void *ctx, const struct value_string *vals,
OSMO_SNPRINTF_RET(ret, rem, offset, len);
}
}
- offset--; /* to remove the trailing | */
- rem++;
+ offset -= sep_len; /* to remove the trailing sep */
+ rem += sep_len;
ret = snprintf(str + offset, rem, "%s", end);
if (ret < 0)