universal-ctags / ctags

A maintained ctags implementation
https://ctags.io
GNU General Public License v2.0
6.51k stars 622 forks source link

main: count the added tags after emitting parser-specific ptags #3936

Closed masatake closed 7 months ago

masatake commented 7 months ago

Close #3935.

C++ may return RESCAN_FAILED when giving a broken input. Just "private" is an example of a broken input:

echo private > input.cpp

When a parser returns RESCAN_FAILED, the main part must reset the state of parsing to the initial state. The main part records the initial state for the case when the reset is needed.

The bug comes from the code not implemented as the expectation:

EXPECTATION:

ORIGINAL CODE: The number of emitted tags is recorded before the main part emitting the parser-specific ptags.

internalSortTags() takes the number of emitted tags. With the original, the number can become incorrect when the a parser returns RESCAN_FAILED.

Acknowledgments: @terminatorul found the minimum input for reproducing the bug. @leleliu008 found --disable-external-sort as the critical condition for reproducing the bug.

masatake commented 7 months ago

Though the bug was mysterious. The fix is so simple and obvious. I will merge this in soon.

codecov[bot] commented 7 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (6701fc4) 85.37% compared to head (3af25f9) 85.38%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #3936 +/- ## ========================================== + Coverage 85.37% 85.38% +0.01% ========================================== Files 234 234 Lines 56199 56200 +1 ========================================== + Hits 47980 47987 +7 + Misses 8219 8213 -6 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.