From: Volker Lendecke Date: Sat, 7 Jun 2025 09:34:18 +0000 (+0200) Subject: libndr: Simplify indentation in ndr_print X-Git-Tag: tevent-0.17.0~23 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9ac5f58a264cb889898cc7bfc844192d6fad8139;p=thirdparty%2Fsamba.git libndr: Simplify indentation in ndr_print printf can take care of the for-loop Signed-off-by: Volker Lendecke Reviewed-by: Martin Schwenke --- diff --git a/librpc/ndr/ndr.c b/librpc/ndr/ndr.c index 896f682d2c2..082bacc2fa6 100644 --- a/librpc/ndr/ndr.c +++ b/librpc/ndr/ndr.c @@ -305,7 +305,6 @@ _PUBLIC_ void ndr_print_debugc_helper(struct ndr_print *ndr, const char *format, { va_list ap; char *s = NULL; - uint32_t i; int ret; int dbgc_class; @@ -325,11 +324,7 @@ _PUBLIC_ void ndr_print_debugc_helper(struct ndr_print *ndr, const char *format, return; } - for (i=0;idepth;i++) { - DEBUGADDC(dbgc_class, 1,(" ")); - } - - DEBUGADDC(dbgc_class, 1,("%s\n", s)); + DEBUGADDC(dbgc_class, 1, ("%*.s\n", 4 * ndr->depth, s)); free(s); } @@ -337,7 +332,6 @@ _PUBLIC_ void ndr_print_debug_helper(struct ndr_print *ndr, const char *format, { va_list ap; char *s = NULL; - uint32_t i; int ret; va_start(ap, format); @@ -354,23 +348,16 @@ _PUBLIC_ void ndr_print_debug_helper(struct ndr_print *ndr, const char *format, return; } - for (i=0;idepth;i++) { - DEBUGADD(1,(" ")); - } - - DEBUGADD(1,("%s\n", s)); + DEBUGADD(1, ("%*.s%s\n", 4 * ndr->depth, "", s)); free(s); } _PUBLIC_ void ndr_print_printf_helper(struct ndr_print *ndr, const char *format, ...) { va_list ap; - uint32_t i; if (!ndr->no_newline) { - for (i=0;idepth;i++) { - printf(" "); - } + printf("%*.s", 4 * ndr->depth, ""); } va_start(ap, format); @@ -384,13 +371,12 @@ _PUBLIC_ void ndr_print_printf_helper(struct ndr_print *ndr, const char *format, _PUBLIC_ void ndr_print_string_helper(struct ndr_print *ndr, const char *format, ...) { va_list ap; - uint32_t i; if (!ndr->no_newline) { - for (i=0;idepth;i++) { - ndr->private_data = talloc_asprintf_append_buffer( - (char *)ndr->private_data, " "); - } + talloc_asprintf_addbuf((char **)&ndr->private_data, + "%*.s", + ndr->depth * 4, + ""); } va_start(ap, format); @@ -398,8 +384,7 @@ _PUBLIC_ void ndr_print_string_helper(struct ndr_print *ndr, const char *format, format, ap); va_end(ap); if (!ndr->no_newline) { - ndr->private_data = talloc_asprintf_append_buffer((char *)ndr->private_data, - "\n"); + talloc_asprintf_addbuf((char **)&ndr->private_data, "\n"); } } diff --git a/librpc/ndr/ndr_dnsp.c b/librpc/ndr/ndr_dnsp.c index 2f218edade4..43efa3466d7 100644 --- a/librpc/ndr/ndr_dnsp.c +++ b/librpc/ndr/ndr_dnsp.c @@ -193,10 +193,7 @@ _PUBLIC_ void ndr_print_dnsp_string_list(struct ndr_print *ndr, const char *name uint32_t i; ndr->no_newline = true; - for (i=0; idepth; i++) { - ndr->print(ndr, " "); - } - ndr->print(ndr, "%-25s:", name); + ndr->print(ndr, "%*.s%-25s:", 4 * ndr->depth, "", name); for (i=0; icount; i++) { ndr->print(ndr, " \"%s\"", list->str[i]); } diff --git a/source4/librpc/ndr/py_xattr.c b/source4/librpc/ndr/py_xattr.c index 523c1ab4a19..df134e01a9a 100644 --- a/source4/librpc/ndr/py_xattr.c +++ b/source4/librpc/ndr/py_xattr.c @@ -44,7 +44,7 @@ static void ntacl_print_debug_helper(struct ndr_print *ndr, const char *format, { va_list ap; char *s = NULL; - int i, ret; + int ret; va_start(ap, format); ret = vasprintf(&s, format, ap); @@ -54,11 +54,8 @@ static void ntacl_print_debug_helper(struct ndr_print *ndr, const char *format, return; } - for (i=0;idepth;i++) { - printf(" "); - } + printf("%*.s\n", 4 * ndr->depth, s); - printf("%s\n", s); free(s); }