diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2016-04-06 18:40:22 +0300 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2016-04-06 18:43:47 +0300 |
commit | 155bf39896f126b1ba121b816922a88dc34c31e3 (patch) | |
tree | 90fe058b74d98327ba5f2565bbe7e5b68739ac49 /blobmsg_json.c | |
parent | dfe446e2a981eaa83cb41df3840ca7c649dc7527 (diff) |
blobmsg_json: simplify add_separator and fix thread-safety
The hard-coded length limits are replaced with strlen to make the code more
robust.
Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
Diffstat (limited to 'blobmsg_json.c')
-rw-r--r-- | blobmsg_json.c | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/blobmsg_json.c b/blobmsg_json.c index 2d1d80d..5713948 100644 --- a/blobmsg_json.c +++ b/blobmsg_json.c @@ -135,21 +135,17 @@ static bool blobmsg_puts(struct strbuf *s, const char *c, int len) static void add_separator(struct strbuf *s) { - static char indent_chars[17] = "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; - int indent; - char *start; + const char *indent_chars = "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; + int len; if (!s->indent) return; - indent = s->indent_level; - if (indent > 16) - indent = 16; + len = s->indent_level + 1; + if (len > strlen(indent_chars)) + len = strlen(indent_chars); - start = &indent_chars[sizeof(indent_chars) - indent - 1]; - *start = '\n'; - blobmsg_puts(s, start, indent + 1); - *start = '\t'; + blobmsg_puts(s, indent_chars, len); } |