Caphyon / clang-format-editor

Clang-Format Editor is a tool that helps you find the best Clang-Format Style for your C++, C#, Java, JavaScript, and Objective-C code.
https://clangpowertools.com/clang-format-editor.html
Apache License 2.0
43 stars 7 forks source link

Struct declaration with weird comments can crash the editor #23

Open Absolucy opened 2 years ago

Absolucy commented 2 years ago

Example

//comment
EmptyStruct emptyStruct = EmptyStruct{}; //1 space after ';'' otherwise: ;//1 space after...

Description

Crashes upon trying to format. Removing either //comment or //1 space after ';'' otherwise: ;//1 space after... will not crash.

Crash info

image

System.ArgumentOutOfRangeException
  HResult=0x80131502
  Message=Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
  Source=System.Private.CoreLib
  StackTrace:
   at System.ThrowHelper.ThrowArgumentOutOfRange_IndexException()
   at System.Collections.Generic.List`1.get_Item(Int32 index)
   at ClangFormatEditor.DiffMatchPatchWrapper.DetectOperationPerLine(String input, String output, List`1 inputOperationPerLine, List`1 outputOperationPerLine) in C:\Users\Lucy\Downloads\clang-format-editor\ClangFormatEditor\DiffStyle\DiffMatchPatchWrapper.cs:line 209
   at ClangFormatEditor.DiffMatchPatchWrapper.DiffAsFlowDocuments(String input, String output) in C:\Users\Lucy\Downloads\clang-format-editor\ClangFormatEditor\DiffStyle\DiffMatchPatchWrapper.cs:line 153
   at ClangFormatEditor.MVVM.Controllers.DiffController.<CreateFlowDocumentAsync>d__13.MoveNext() in C:\Users\Lucy\Downloads\clang-format-editor\ClangFormatEditor\MVVM\Controllers\DiffController.cs:line 78
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at ClangFormatEditor.ConfiguratorViewModel.<RunFormatAsync>d__77.MoveNext() in C:\Users\Lucy\Downloads\clang-format-editor\ClangFormatEditor\MVVM\ViewModel\ConfiguratorViewModel.cs:line 301
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
   at ClangFormatEditor.TaskExtensions.<SafeFireAndForget>d__0.MoveNext() in C:\Users\Lucy\Downloads\clang-format-editor\ClangFormatEditor\Extensions\TaskExtensions.cs:line 25

  This exception was originally thrown at this call stack:
    [External Code]
    ClangFormatEditor.DiffMatchPatchWrapper.DetectOperationPerLine(string, string, System.Collections.Generic.List<(object, ClangFormatEditor.DiffMatchPatchWrapper.LineChanges)>, System.Collections.Generic.List<(object, ClangFormatEditor.DiffMatchPatchWrapper.LineChanges)>) in DiffMatchPatchWrapper.cs
    ClangFormatEditor.DiffMatchPatchWrapper.DiffAsFlowDocuments(string, string) in DiffMatchPatchWrapper.cs
    ClangFormatEditor.MVVM.Controllers.DiffController.CreateFlowDocumentAsync(string, ClangFormatEditor.Enums.FormatStyle, System.Collections.Generic.List<ClangFormatEditor.Interfaces.IFormatOption>, System.Threading.CancellationToken) in DiffController.cs
    [External Code]
    ClangFormatEditor.ConfiguratorViewModel.RunFormatAsync() in ConfiguratorViewModel.cs
    [External Code]
    ClangFormatEditor.TaskExtensions.SafeFireAndForget(System.Threading.Tasks.Task, bool, System.Action<System.Exception>) in TaskExtensions.cs

Autos

  Name Value Type
  continueOnCapturedContext true bool
task Id = 748, Status = Faulted, Method = "{null}", Result = "{Not yet computed}" System.Threading.Tasks.Task {System.Runtime.CompilerServices.AsyncTaskMethodBuilder.AsyncStateMachineBox<ClangFormatEditor.ConfiguratorViewModel.d__77>}
  AsyncState null object
  CancellationPending false bool
  CreationOptions None System.Threading.Tasks.TaskCreationOptions
  ▶ Exception Count = 1 System.Exception {System.AggregateException}
  Id 748 int
  Result {System.Threading.Tasks.VoidTaskResult} System.Threading.Tasks.VoidTaskResult
  Status Faulted System.Threading.Tasks.TaskStatus
  ◢ Raw View    
  AsyncState null object
  ▶ Context null System.Threading.ExecutionContext
  CreationOptions None System.Threading.Tasks.TaskCreationOptions
  ▶ Exception Count = 1 System.AggregateException
  Id 748 int
  IsCanceled false bool
  IsCompleted true bool
  IsCompletedSuccessfully false bool
  IsFaulted true bool
  ▶ MoveNextAction {Method = {Void MoveNext()}} System.Action
  StateMachine null ClangFormatEditor.ConfiguratorViewModel.d__77
  Status Faulted System.Threading.Tasks.TaskStatus
  ◢ Static members    
  ◢ CompletedTask Id = 764, Status = RanToCompletion, Method = "{null}", Result = "System.Threading.Tasks.VoidTaskResult" System.Threading.Tasks.Task {System.Threading.Tasks.Task}
  AsyncState null object
  CancellationPending false bool
  CreationOptions None System.Threading.Tasks.TaskCreationOptions
  ▶ Exception null System.Exception
  Id 764 int
  Result {System.Threading.Tasks.VoidTaskResult} System.Threading.Tasks.VoidTaskResult
  Status RanToCompletion System.Threading.Tasks.TaskStatus
  ▶ Raw View    
  CurrentId null int?
  ▶ Factory (System.Threading.Tasks.Task) {System.Threading.Tasks.TaskFactory} System.Threading.Tasks.TaskFactory
  ▶ Factory {System.Threading.Tasks.TaskFactory} System.Threading.Tasks.TaskFactory
  ▶ Non-Public members    
  ◢ Non-Public members    
  ▶ CancellationToken IsCancellationRequested = false System.Threading.CancellationToken
  ▶ CapturedContext {System.Threading.ExecutionContext} System.Threading.ExecutionContext
  ▶ CompletedEvent Set = true System.Threading.ManualResetEventSlim
  DebuggerDisplayMethodDescription (System.Threading.Tasks.Task) "{null}" string
  DebuggerDisplayMethodDescription "{null}" string
  DebuggerDisplayResultDescription "{Not yet computed}" string
  ExceptionRecorded true bool
  ▶ ExecutingTaskScheduler null System.Threading.Tasks.TaskScheduler
  IsCancellationAcknowledged false bool
  IsCancellationRequested false bool
  IsDelegateInvoked false bool
  IsExceptionObservedByParent false bool
  IsWaitNotificationEnabled false bool
  IsWaitNotificationEnabledOrNotRanToCompletion true bool
  Options 1024 System.Threading.Tasks.TaskCreationOptions
  ▶ ParentForDebugger null System.Threading.Tasks.Task
  ResultOnSuccess {System.Threading.Tasks.VoidTaskResult} System.Threading.Tasks.VoidTaskResult
  ShouldNotifyDebuggerOfWaitCompletion false bool
  StateFlagsForDebugger 102761472 int
  ▶ System.IAsyncResult.AsyncWaitHandle {System.Threading.ManualResetEvent} System.Threading.WaitHandle {System.Threading.ManualResetEvent}
  System.IAsyncResult.CompletedSynchronously false bool
  ▶ _moveNextAction {Method = {Void MoveNext()}} System.Action
  m_action null System.Delegate
  ▶ m_contingentProperties {System.Threading.Tasks.Task.ContingentProperties} System.Threading.Tasks.Task.ContingentProperties
  m_continuationObject {object} object
  m_result {System.Threading.Tasks.VoidTaskResult} System.Threading.Tasks.VoidTaskResult
  m_stateFlags 102761472 int
  m_stateObject null object
  m_taskId 748 int
  ▶ m_taskScheduler null System.Threading.Tasks.TaskScheduler
mariru27 commented 1 year ago

Hi @Absolucy,

Do you still have the same problem? Try to update Clang Format Editor to version 2023.4.2

Kind regards, Marina