@@ -254,26 +254,32 @@ async function runCppcheckOnFileXML(
254254 continue ;
255255 }
256256
257- // Cppcheck line number is 1-indexed, while VS Code uses 0-indexing
258257 const mainLoc = locations [ locations . length - 1 ] . $ ;
259258
260259 // If main location is not current file, then skip displaying warning
261260 if ( ! filePath . endsWith ( mainLoc . file ) ) {
262261 continue ;
263262 }
264263
264+ // Cppcheck line number is 1-indexed, while VS Code uses 0-indexing
265265 const line = Number ( mainLoc . line ) - 1 ;
266266 // Invalid line number usually means non-analysis output
267267 if ( isNaN ( line ) || line < 0 || line >= document . lineCount ) {
268268 continue ;
269269 }
270270
271+ // Cppcheck col number is 1-indexed, while VS Code uses 0-indexing
272+ let col = Number ( mainLoc . column ) - 1 ;
273+ if ( isNaN ( col ) || col < 0 || col > document . lineAt ( line ) . text . length ) {
274+ col = 0 ;
275+ }
276+
271277 const severity = parseSeverity ( e . $ . severity ) ;
272278 if ( severityToNumber ( severity ) < minSevNum ) {
273279 continue ;
274280 }
275281
276- const range = new vscode . Range ( line , 0 , line , document . lineAt ( line ) . text . length ) ;
282+ const range = new vscode . Range ( line , col , line , document . lineAt ( line ) . text . length ) ;
277283 const diagnostic = new vscode . Diagnostic ( range , e . $ . msg , severity ) ;
278284 diagnostic . source = "cppcheck" ;
279285 diagnostic . code = e . $ . id ;
0 commit comments