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>
This commit is contained in:
parent
dfe446e2a9
commit
155bf39896
1 changed files with 6 additions and 10 deletions
|
@ -135,21 +135,17 @@ static bool blobmsg_puts(struct strbuf *s, const char *c, int len)
|
||||||
|
|
||||||
static void add_separator(struct strbuf *s)
|
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";
|
const char *indent_chars = "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
|
||||||
int indent;
|
int len;
|
||||||
char *start;
|
|
||||||
|
|
||||||
if (!s->indent)
|
if (!s->indent)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
indent = s->indent_level;
|
len = s->indent_level + 1;
|
||||||
if (indent > 16)
|
if (len > strlen(indent_chars))
|
||||||
indent = 16;
|
len = strlen(indent_chars);
|
||||||
|
|
||||||
start = &indent_chars[sizeof(indent_chars) - indent - 1];
|
blobmsg_puts(s, indent_chars, len);
|
||||||
*start = '\n';
|
|
||||||
blobmsg_puts(s, start, indent + 1);
|
|
||||||
*start = '\t';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue