www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4906] New: Dereferencing null error in a single expression

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4906

           Summary: Dereferencing null error in a single expression
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc


--- Comment #0 from bearophile_hugs eml.cc 2010-09-21 04:44:16 PDT ---
To find null dereferencing in code the compiler probably needs to perform flow
analysis.
But the compiler can spot and flag as errors at compile-time expressions that
follow explicit comparisons to null:


if (obj is null && obj.foo()) { ...


Where the programmer probably meant to write:
if (obj !is null && obj.foo()) { ...
Or:
if (obj is null || obj.foo()) { ...


This test doesn't cover several cases of dereference null errors that span
different lines of code, but the cases it covers seem common enough to me.

See also bug 4595
See also bug 4571


See also:

http://code.google.com/intl/en-EN/webtoolkit/tools/codepro/doc/features/audit/audit_rules_com.instantiations.assist.eclipse.auditGroup.semanticErrors.html#com.instantiations.assist.eclipse.analysis.audit.rule.dereferencingNullPointer

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 21 2010
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4906


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2012-12-09
09:11:03 PST ---
(In reply to comment #0)
 To find null dereferencing in code the compiler probably needs to perform flow
 analysis.
 But the compiler can spot and flag as errors at compile-time expressions that
 follow explicit comparisons to null:
 
 
 if (obj is null && obj.foo()) { ...
What if 'foo' is a UFCS function? There's a slight possibility that such a check was expected. I guess the compiler could be more lax in the UFCS case and more careful if 'foo' is actually a method, so maybe this is implementable.. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 09 2012