| Summary: | [checker] Add a simple checker for variable self-assignment | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Product: | [Tools] CDT | Reporter: | Severin Gehwolf <sgehwolf> | ||||||||
| Component: | cdt-codan | Assignee: | Project Inbox <cdt-core-inbox> | ||||||||
| Status: | RESOLVED FIXED | QA Contact: | Elena Laskavaia <elaskavaia.cdt> | ||||||||
| Severity: | normal | ||||||||||
| Priority: | P3 | CC: | cdt.genie, cdtdoug, overholt, sgehwolf | ||||||||
| Version: | 7.0 | ||||||||||
| Target Milestone: | 8.0 | ||||||||||
| Hardware: | PC | ||||||||||
| OS: | Linux | ||||||||||
| Whiteboard: | |||||||||||
| Attachments: |
|
||||||||||
|
Description
Severin Gehwolf
Can you submit a patch without creating a new plugin? Created attachment 170205 [details]
Patch (project level) on org.eclipse.cdt.codan.checkers
Certainly. Patch is attached. Please let me know if I did something inconvenient/unusual. Thanks! Severin Patch comments:
1) Checking rawSignature of expression is not entirely correct, i.e.
for cases like *x++ = *x++; but I could not think of example where it can be reasonably justified (i.e it is still an error).
2)
if (e instanceof IASTBinaryExpression && isAssignmentExpression(e)) {
instanceof check is redundant because isAssignmentExpression does it anyway.
Do we even need this extra function anyway (inline it?)
3)
Also description has text like
Finds expressions such as 'int value = 1; value = value;'
Should be
Finds expression where left and right side of the assignment is the same, i.e. 'value = value'
Thanks! The use of getRawSignature() bothered me from the start, but didn't know a better (the proper way) to do it. Any hints? I think it is ok for now. We can check for only "x = x" but it would miss interesting cases like arr[i]=arr[i] Actually it catches cases like a[i] = a[i]. Created attachment 170252 [details]
Patch (workspace level) on org.eclipse.cdt.codan.{checkers,core.test}
Thanks for your feedback. I've modified the patch and incorporated your suggestions. Also, I've added a few simple tests for this checker.
(In reply to comment #7) > Actually it catches cases like a[i] = a[i]. Yes this is my point, it does now because you are using getRawSignature. And lets keep it this way. -> 8.0 Patch applied on head, thanks. Next time please add copyright header for new files and externalize strings *** cdt cvs genie on behalf of elaskavaia *** Bug 314576: added assignment to itself checker, contribution from Severin Gehwolf [*] plugin.xml 1.27 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.checkers/plugin.xml?root=Tools_Project&r1=1.26&r2=1.27 [+] AssignmentToItselfChecker.java http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/AssignmentToItselfChecker.java?root=Tools_Project&revision=1.1&view=markup [*] bundle.properties 1.4 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/bundle.properties?root=Tools_Project&r1=1.3&r2=1.4 [+] AssignmentToItselfCheckerTest.java http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/AssignmentToItselfCheckerTest.java?root=Tools_Project&revision=1.1&view=markup [*] AutomatedIntegrationSuite.java 1.11 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/AutomatedIntegrationSuite.java?root=Tools_Project&r1=1.10&r2=1.11 |