debug: Call depth: Indent the debug text
authorPavel Filipenský <pfilipensky@samba.org>
Fri, 26 Aug 2022 09:42:42 +0000 (11:42 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Thu, 26 Jan 2023 14:10:36 +0000 (14:10 +0000)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15287

Signed-off-by: Pavel Filipenský <pfilipensky@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
lib/util/debug.c

index 04537bdc142861b23cda7835acfa430c8c666a05..43d5151fbab20fe305b7eea3fa6aced12a659119 100644 (file)
@@ -1635,8 +1635,21 @@ static void format_debug_text( const char *msg )
        for( i = 0; msg[i]; i++ ) {
                /* Indent two spaces at each new line. */
                if(timestamp && 0 == format_pos) {
+                       /* Limit the maximum indentation to 20 levels */
+                       size_t depth = MIN(20, debug_call_depth);
                        format_bufr[0] = format_bufr[1] = ' ';
                        format_pos = 2;
+                       /*
+                        * Indent by four spaces for each depth level,
+                        * but only if the current debug level is >= 8.
+                        */
+                       if (depth > 0 && debuglevel_get() >= 8 &&
+                           format_pos + 4 * depth < FORMAT_BUFR_SIZE) {
+                               memset(&format_bufr[format_pos],
+                                      ' ',
+                                      4 * depth);
+                               format_pos += 4 * depth;
+                       }
                }
 
                /* If there's room, copy the character to the format buffer. */