From: Todd C. Miller Date: Thu, 20 Sep 2018 21:15:14 +0000 (-0600) Subject: In print_member_json_int() eliminate the need_newline variable X-Git-Tag: SUDO_1_8_26^2~80 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=72ce2c807b686d7816859e894b41b9c8bb5b5804;p=sudo In print_member_json_int() eliminate the need_newline variable and just move the non-alias expansion printing bits into the else clause, including the newline and comma printing. --- diff --git a/plugins/sudoers/cvtsudoers_json.c b/plugins/sudoers/cvtsudoers_json.c index 901f2b104..8d57894e3 100644 --- a/plugins/sudoers/cvtsudoers_json.c +++ b/plugins/sudoers/cvtsudoers_json.c @@ -338,9 +338,8 @@ print_member_json_int(FILE *fp, struct sudoers_parse_tree *parse_tree, const char *typestr = NULL; const char *errstr; int alias_type = UNSPEC; - bool need_newline = true; id_t id; - debug_decl(print_member_json, SUDOERS_DEBUG_UTIL) + debug_decl(print_member_json_int, SUDOERS_DEBUG_UTIL) /* Most of the time we print a string. */ value.type = JSON_STRING; @@ -476,6 +475,7 @@ print_member_json_int(FILE *fp, struct sudoers_parse_tree *parse_tree, struct alias *a; struct member *m; + /* Print each member of the alias. */ if ((a = alias_get(parse_tree, value.u.string, alias_type)) != NULL) { TAILQ_FOREACH(m, &a->members, entries) { print_member_json_int(fp, parse_tree, m->name, m->type, @@ -484,23 +484,23 @@ print_member_json_int(FILE *fp, struct sudoers_parse_tree *parse_tree, last_one && TAILQ_NEXT(m, entries) == NULL, indent, true); } alias_put(a); - need_newline = false; } - } else if (negated) { - print_indent(fp, indent); - fputs("{\n", fp); - indent += 4; - print_pair_json(fp, NULL, typestr, &value, ",\n", indent); - value.type = JSON_BOOL; - value.u.boolean = true; - print_pair_json(fp, NULL, "negated", &value, "\n", indent); - indent -= 4; - print_indent(fp, indent); - putc('}', fp); } else { - print_pair_json(fp, "{ ", typestr, &value, " }", indent); - } - if (need_newline) { + if (negated) { + print_indent(fp, indent); + fputs("{\n", fp); + indent += 4; + print_pair_json(fp, NULL, typestr, &value, ",\n", indent); + value.type = JSON_BOOL; + value.u.boolean = true; + print_pair_json(fp, NULL, "negated", &value, "\n", indent); + indent -= 4; + print_indent(fp, indent); + putc('}', fp); + } else { + print_pair_json(fp, "{ ", typestr, &value, " }", indent); + } + if (!last_one) putc(',', fp); putc('\n', fp);