Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Compilers, and most static analyzers, do not try to warn for everything wrong a program might do, because that would entail too many false positives (warnings that do not correspond to actual problems in the source code).</p> <p>Macmade recommends <a href="http://clang.llvm.org" rel="noreferrer">Clang</a> in the comments, a recommendation I can second. Note that Clang still aims at being useful for most developers by minimizing false positives. This means that it has false negatives, or, in other words, that it misses some real issues (when unsure that there is a problem, it may remains silent rather than risk wasting the developer's time with a false positive).</p> <hr> <p>Note that it is even arguable whether there really is a problem in function <code>f()</code> in your program. Function <code>h()</code> below is clearly fine, although the calling code mustn't use <code>p</code> after it returns:</p> <pre><code>char *p; void h(void) { char c; p = &amp;c; } </code></pre> <hr> <p>Another static analyzer I can recommend is <a href="http://frama-c.com/value.html" rel="noreferrer">Frama-C's value analysis</a> (I am one of the developers). This one does not leave any false negatives, for some families of errors (including dangling pointers), when used in controlled conditions.</p> <pre><code>char *f(void) { char c; return &amp;c; } char *g(void) { char c; char *p = &amp;c; return p; } $ frama-c -val -lib-entry -main g r.c ... r.c:11:[value] warning: locals {c} escaping the scope of g through \result ... $ frama-c -val -lib-entry -main f r.c ... r.c:4:[value] warning: locals {c} escaping the scope of f through \result ... </code></pre> <p>The above are only informative messages, they do not mean the function is necessarily wrong. There is one for my function <code>h()</code> too:</p> <pre><code>h.c:7:[value] warning: locals {c} escaping the scope of h through p </code></pre> <p>The real error, characterized by the word “assert” in Frama-C's output, is if a function calls <code>h()</code> and then uses <code>p</code>:</p> <pre><code>void caller(void) { char d; h(); d = *p; } $ frama-c -val -lib-entry -main caller h.c ... h.c:7:[value] warning: locals {c} escaping the scope of h through p ... h.c:13:[kernel] warning: accessing left-value p that contains escaping addresses; assert(Ook) h.c:13:[kernel] warning: completely undefined value in {{ p -&gt; {0} }} (size:&lt;32&gt;). </code></pre> <p>Frama-C's value analysis is called <a href="http://en.wikipedia.org/wiki/Data-flow_analysis#Sensitivities" rel="noreferrer">context-sensitive</a>. It analyses function <code>h()</code> for each call, with the values that are actually passed to it. It also analyzes the code that comes after the call to <code>h()</code> in function <code>caller()</code> with the values that can actually be returned by <code>h()</code>. This is more expensive than the context-insensitive analyses that Clang or GCC typically do, but more precise.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload