diff --git a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker.java b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker.java index 44287f7ea50..92cbfed1b00 100644 --- a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker.java +++ b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker.java @@ -197,11 +197,11 @@ public abstract class AbstractIndexAstChecker extends AbstractCheckerWithProblem return locFactory.createProblemLocation(getFile(), start, end, line); } } - if (line == astLocation.getEndingLineNumber()) { - return locFactory.createProblemLocation(getFile(), astLocation.getNodeOffset(), - astLocation.getNodeOffset() + astLocation.getNodeLength(), line); - } - return locFactory.createProblemLocation(getFile(), line); + // If the raw signature has more than one line, we highlight only the code + // related to the problem. + int start = astLocation.getNodeOffset(); + int end = start + astLocation.getNodeLength(); + return locFactory.createProblemLocation(getFile(), start, end, line); } protected static boolean enclosedInMacroExpansion(IASTNode node) { diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/AssignmentToItselfCheckerTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/AssignmentToItselfCheckerTest.java index e3c5968d7fc..18c39ada406 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/AssignmentToItselfCheckerTest.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/AssignmentToItselfCheckerTest.java @@ -11,6 +11,7 @@ package org.eclipse.cdt.codan.core.internal.checkers; import org.eclipse.cdt.codan.core.test.CheckerTestCase; +import org.eclipse.core.resources.IMarker; /** * Test for {@see AssignmentToItselfChecker} class @@ -63,4 +64,18 @@ public class AssignmentToItselfCheckerTest extends CheckerTestCase { loadCodeAndRun(getAboveComment()); checkNoErrors(); } + + // void foo() { + // int x = 0; x + // = x; + // } + public void testMarkerOffset_Bug486610() throws Exception { + String code = getAboveComment(); + loadCodeAndRun(code); + IMarker marker = checkErrorLine(2); + int start = marker.getAttribute(IMarker.CHAR_START, -1); + int end = marker.getAttribute(IMarker.CHAR_END, -1); + // The offset should start at the beginning of the expression "x = x" + assertEquals("x\n = x", code.substring(start, end)); + } }