Skip to content

Fix guest parser offset on the last line with CRLF line endings #4267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

b4n
Copy link
Member

@b4n b4n commented Jun 2, 2025

This is related to #4266, and is basically the test part of #4097 that is actually still relevant, only the CRLF got lost in translation.
This is just a test case showing the issue, so we have something to work on.

FWIW, here's the output:

$ ./ctags -o- $(cat Units/parser-php.r/subparser-crlf.b/args.ctags) Units/parser-php.r/subparser-crlf.b/input.php
ctags: memory for mio may be exhausted

If we trick mini-geany to run it, it's worse:

$ git diff
diff --git a/main/mini-geany.c b/main/mini-geany.c
index e02b3c19a..06d2f8be6 100644
--- a/main/mini-geany.c
+++ b/main/mini-geany.c
@@ -370,7 +370,7 @@ extern int main (int argc, char **argv)
         {
             printf("\nParsing %s:\n", argv[i]);
             /* parseRawBuffer() is called repeatadly during Geany execution */
-            parseRawBuffer(argv[i], NULL, 0, getNamedLanguage("C", 0), tagArray);
+            parseRawBuffer(argv[i], NULL, 0, getNamedLanguage("PHP", 0), tagArray);
 
             processCollectedTags(tagArray);
         }
$ ./mini-geany Units/parser-php.r/subparser-crlf.b/input.php
This parser only parses C files - provide them as arguments on the command line or get a hard-coded buffer parsed when no arguments are provided


Parsing Units/parser-php.r/subparser-crlf.b/input.php:
Error: memory for mio may be exhausted
Segmentation fault

But that's only because with it the fatal() call does not call exit(), and thus does not prevent the use of an NULL submio.

Copy link

codecov bot commented Jun 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.95%. Comparing base (74ff528) to head (cadd213).
Report is 11 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4267   +/-   ##
=======================================
  Coverage   85.95%   85.95%           
=======================================
  Files         246      246           
  Lines       63470    63435   -35     
=======================================
- Hits        54554    54526   -28     
+ Misses       8916     8909    -7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@b4n b4n changed the title php: Add unit test for broken guest parser with CRLF line endings Fix guest parser offset on the last line with CRLF line endings Jun 2, 2025
@b4n
Copy link
Member Author

b4n commented Jun 2, 2025

@masatake I have a fix that mostly look reasonable, but I'm still not sure I get everything around this, so please review carefully and don't trust the logic :) Results seem solid though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants