Skip to content

Commit f51dddc

Browse files
committed
fixed some implicit null to zero conversions
1 parent 0cfd7e2 commit f51dddc

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/extension.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,12 @@ async function runCppcheckOnFileXML(
278278
const mainLoc = locations.length ? locations[locations.length - 1]?.$ : [];
279279

280280
// If main location is not current file, then skip displaying warning unless it is critical
281-
if (!isCriticalError && !filePath.endsWith(mainLoc.file)) {
281+
if (!isCriticalError && !filePath.endsWith(mainLoc?.file)) {
282282
continue;
283283
}
284284

285285
// Cppcheck line number is 1-indexed, while VS Code uses 0-indexing
286-
let line = Number(mainLoc.line) - 1;
286+
let line = Number(mainLoc?.line ?? 0) - 1;
287287
// Invalid line number usually means non-analysis output
288288
if (isNaN(line) || line < 0 || line >= document.lineCount) {
289289
if (isCriticalError) {
@@ -294,7 +294,7 @@ async function runCppcheckOnFileXML(
294294
}
295295

296296
// Cppcheck col number is 1-indexed, while VS Code uses 0-indexing
297-
let col = Number(mainLoc.column) - 1;
297+
let col = Number(mainLoc?.column ?? 0) - 1;
298298
if (isNaN(col) || col < 0 || col > document.lineAt(line).text.length) {
299299
col = 0;
300300
}

0 commit comments

Comments
 (0)