Upstream issue: https://lists.gnu.org/archive/html/bug-indent/2024-01/msg00001.html
Signed-off-by: Petr Písař
---
regression/TEST | 2 +-
regression/input/comment-parent-heap-underread.c | 3 +++
regression/standard/comment-parent-heap-underread.c | 5 +++++
src/output.c | 2 +-
4 files changed, 10 insertions(+), 2 deletions(-)
create mode 100644 regression/input/comment-parent-heap-underread.c
create mode 100644 regression/standard/comment-parent-heap-underread.c
diff --git a/regression/TEST b/regression/TEST
index 7c07c2e..951b1a2 100755
--- a/regression/TEST
+++ b/regression/TEST
@@ -40,6 +40,7 @@ BUGS="case-label.c one-line-1.c one-line-2.c one-line-3.c \
macro.c enum.c elif.c nested.c wrapped-string.c minus_predecrement.c \
bug-gnu-33364.c float-constant-suffix.c block-comments.c \
- no-forced-nl-in-block-init.c hexadecimal_float.c binary-constant.c"
+ no-forced-nl-in-block-init.c hexadecimal_float.c binary-constant.c \
+ comment-parent-heap-underread.c"
INDENTSRC="args.c backup.h backup.c dirent_def.h globs.c indent.h \
indent.c indent_globs.h io.c lexi.c memcpy.c parse.c pr_comment.c \
diff --git a/regression/input/comment-parent-heap-underread.c
b/regression/input/comment-parent-heap-underread.c
new file mode 100644
index 0000000..68e13cf
--- /dev/null
+++ b/regression/input/comment-parent-heap-underread.c
@@ -0,0 +1,3 @@
+void foo(void) {
+/*a*/(1);
+}
diff --git a/regression/standard/comment-parent-heap-underread.c
b/regression/standard/comment-parent-heap-underread.c
new file mode 100644
index 0000000..9a1c6e3
--- /dev/null
+++ b/regression/standard/comment-parent-heap-underread.c
@@ -0,0 +1,5 @@
+void
+foo (void)
+{
+/*a*/ (1);
+}
diff --git a/src/output.c b/src/output.c
index ee01bcc..17eee6e 100644
--- a/src/output.c
+++ b/src/output.c
@@ -290,7 +290,7 @@ void set_buf_break (
/* Did we just parse a bracket that will be put on the next line
* by this line break? */
- if ((*token == '(') || (*token == '['))
+ if (level > 0 && ((*token == '(') || (*token == '[')))
{
--level; /* then don't take it into account */
}
--
2.43.0