From 1e253910afaa56890dd6e8e0a7388cd0a4eac5b2 Mon Sep 17 00:00:00 2001 From: Jean-Michel Rouet <36963549+jmrouet@users.noreply.github.com> Date: Wed, 15 Dec 2021 16:05:19 +0100 Subject: [PATCH] Fix infinite loop in NewCommentLine Fixes an infinite loop that occur in NewCommentLine, eg on a simple file like: /* somme non doxygen comment */ void foo(int * ptr) { *ptr = 0; } Note that we also want to avoid the completion to think "*ptr = 0;" is a comment and create a new line with a * --- AutoDoxyDoc/DoxygenCompletionCommandHandler.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/AutoDoxyDoc/DoxygenCompletionCommandHandler.cs b/AutoDoxyDoc/DoxygenCompletionCommandHandler.cs index a2af323..b22120e 100644 --- a/AutoDoxyDoc/DoxygenCompletionCommandHandler.cs +++ b/AutoDoxyDoc/DoxygenCompletionCommandHandler.cs @@ -241,7 +241,7 @@ private void NewCommentLine(string currentLine) int oldOffset = ts.ActivePoint.LineCharOffset; int extraIndent = 0; - while (!currentLine.StartsWith("/*!")) + while (!currentLine.StartsWith("/*")) { if (m_regexTagSection.IsMatch(currentLine)) { @@ -249,6 +249,12 @@ private void NewCommentLine(string currentLine) break; } + // protect from infinite loop when we reach the top of the document an end of comment + // the NewCommentLine() call is protected with a weak IsInsideComment() check + // that could be flawed with lines like: *pointer = value; + if (ts.ActivePoint.Line <= 1 || currentLine.Contains("*/")) + return; + ts.LineUp(); currentLine = ts.ActivePoint.CreateEditPoint().GetLines(ts.ActivePoint.Line, ts.ActivePoint.Line + 1); currentLine = currentLine.TrimStart();