Skip to content

Conversation

@wwpreston
Copy link

This PR suggests a fix for an issue some users are experiencing where results are missing from the 'problems' window in VS Code (#223).

Summary

There is loop with range i to -1 that I think should be i to 0 (inclusive).

Details

Sometimes linters (specifically cppcheck) return output for multiple files when asked to evaluate a specific file (e.g. evaluating a .c file returns issues with included .h files).

A loop in server.ts processes the results.
It loops over the array processing 1 file in each iteration.
After processing a result it is removed from the list (result.splice(i, 1)).
Eventually the list is empty.

There appears to be a bug with the loop range.
In while (i-- >= 0) variable i has range result.length-1 to -1 inclusive.
When i is -1 it can remove a result from the list that is not marked for the current file (result.splice(-1, 1)).
This causes missing items in the 'problems' window in VS Code.

Proposed fix: change the loop to while (--i >= 0), then variable i has range result.length-1 to 0 inclusive.

Simplified example

This is a simplified example of the loop in server.ts.

let result = [
	{ file: 'file1.h', issue: 'Issue A' },
	{ file: 'file1.h', issue: 'Issue B' },
	{ file: 'file2.h', issue: 'Issue C' },
	{ file: 'file2.h', issue: 'Issue D' },
	{ file: 'file3.c', issue: 'Issue E' },
	{ file: 'file3.c', issue: 'Issue F' },
];

while (result.length > 0) {
	let currentFile = '';
	let i = result.length;
	while (--i >= 0) {
		let msg = result[i];
		
		if (msg === null || msg === undefined || msg.parseError || msg.source === '') {
			result.splice(i, 1);
			continue;
		}
		
		if (currentFile === '') {
			currentFile = msg.file;
		}
		
		if (currentFile !== msg.file) {
			continue;
		}
		
		console.log("Processed result: file="+msg.file+" issue="+msg.issue);
		result.splice(i, 1);
	}
}

Output with while (i-- >= 0) (misses 2 items):

Processed result: file=file3.c issue=Issue F
Processed result: file=file3.c issue=Issue E
Processed result: file=file2.h issue=Issue C
Processed result: file=file1.h issue=Issue A

Output with while (--i >= 0):

Processed result: file=file3.c issue=Issue F
Processed result: file=file3.c issue=Issue E
Processed result: file=file2.h issue=Issue D
Processed result: file=file2.h issue=Issue C
Processed result: file=file1.h issue=Issue B
Processed result: file=file1.h issue=Issue A

Hotfix

You can easily apply this change to the release version (1.15.0) of the extension.

  1. Open the following file:

    • ~/.vscode/extensions/jbenden.c-cpp-flylint-1.15.0/server/out/server.js
      • If you're using a VSCode on a remote server .vscode might be .vscode-remote or .vscode-server.
  2. Find:

for(;r-- >=0;){let i=e[r];if(null==i||i.parseError||!i.hasOwnProperty("line")||""===i.source){e.splice(r,1);continue}
  1. Replace with:
for(;--r >=0;){let i=e[r];if(null==i||i.parseError||!i.hasOwnProperty("line")||""===i.source){e.splice(r,1);continue}
  1. Restart VS Code.

`while (i-- >= 0)` -> `i` is `result.length-1` to `-1` inclusive.
`while (--i >= 0)` -> `i` is `result.length-1` to `0` inclusive.
@wwpreston wwpreston requested a review from jbenden as a code owner March 4, 2025 16:18
@fr43nk
Copy link

fr43nk commented Nov 15, 2025

@wwpreston it seems that the maintainer of this extension no longer is active in any way. The github activity is empty since almost a year. I also tried to reach him via email.
If you want, I can create a fork of this an try to keep the extension alive with a new name in the marketplace and your fix can be implemented into the sources. Please have a look here: https://github.com/fr43nk/vscode-lint-for-cpp

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants