<div dir="ltr"><div class="markdown-here-wrapper" style=""><p style="margin:0px 0px 1.2em!important">To whom it may concern,</p>
<p style="margin:0px 0px 1.2em!important">tl;dr I think I found a bug in the clang static analyzer. Could someone please help me find a workaround/where to properly report the bug?</p>
<p style="margin:0px 0px 1.2em!important">I have a statement in a class initializer list:</p>
<p style="margin:0px 0px 1.2em!important"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">data_ptr((rhs.has_data() && rhs.size_in_bytes() > 0)? malloc(rhs.size_in_bytes()) : nullptr)</code></p>
<p style="margin:0px 0px 1.2em!important">rhs.has_data() is a const function that returns t/f if rhs.data_ptr != null</p>
<p style="margin:0px 0px 1.2em!important">rhs.size_in_bytes() a const function that returns the number of bytes in the structure <strong>if has_data was true</strong></p>
<p style="margin:0px 0px 1.2em!important">i.e. it is possible that rhs.has_data() is false, and rhs.size_in_bytes() > 0</p>
<p style="margin:0px 0px 1.2em!important">However the clang static analyzer seems to get a false positive here.</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code class="hljs language-console" style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline;white-space:pre;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important;display:block;overflow-x:auto;padding:0.5em;color:rgb(51,51,51);background:rgb(248,248,248) none repeat scroll 0% 0%">/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/include/g++-v8/bits/unique_ptr.h:831:34: note: Calling copy constructor for 'pressio_data'
../include/libpressio_ext/cpp/data.h:247:15: note: Left side of '&&' is true
data_ptr((rhs.has_data() && rhs.size_in_bytes() > 0)? malloc(rhs.size_in_bytes()) : nullptr),
^
../include/libpressio_ext/cpp/data.h:247:33: note: Assuming the condition is true
data_ptr((rhs.has_data() && rhs.size_in_bytes() > 0)? malloc(rhs.size_in_bytes()) : nullptr),
^
../include/libpressio_ext/cpp/data.h:247:14: note: '?' condition is true
data_ptr((rhs.has_data() && rhs.size_in_bytes() > 0)? malloc(rhs.size_in_bytes()) : nullptr),
^
../include/libpressio_ext/cpp/data.h:247:66: note: Calling 'pressio_data::size_in_bytes'
data_ptr((rhs.has_data() && rhs.size_in_bytes() > 0)? malloc(rhs.size_in_bytes()) : nullptr),
^
../include/libpressio_ext/cpp/data.h:384:12: note: Calling 'data_size_in_bytes<unsigned long>'
return data_size_in_bytes(data_dtype, num_dimensions(), dims.data());
^
../include/libpressio_ext/cpp/data.h:31:5: note: Returning zero
return data_size_in_elements(dimensions, dims) * pressio_dtype_size(type);
^
../include/libpressio_ext/cpp/data.h:384:12: note: Returning from 'data_size_in_bytes<unsigned long>'
return data_size_in_bytes(data_dtype, num_dimensions(), dims.data());
^
../include/libpressio_ext/cpp/data.h:384:5: note: Returning zero
return data_size_in_bytes(data_dtype, num_dimensions(), dims.data());
^
../include/libpressio_ext/cpp/data.h:247:66: note: Returning from 'pressio_data::size_in_bytes'
data_ptr((rhs.has_data() && rhs.size_in_bytes() > 0)? malloc(rhs.size_in_bytes()) : nullptr),
^
../include/libpressio_ext/cpp/data.h:247:59: note: Call to 'malloc' has an allocation size of 0 bytes
data_ptr((rhs.has_data() && rhs.size_in_bytes() > 0)? malloc(rhs.size_in_bytes()) : nullptr),
</code></pre>
<p style="margin:0px 0px 1.2em!important">Is there a way to instruct the static analyzer that malloc cannot be called with size_in_bytes == 0 because saying (rhs.size_in_bytes() > 0) isn’t enough. I’m using clang-9.0.1 on gentoo.</p>
<p style="margin:0px 0px 1.2em!important">Respectfully,<br>Robert Underwood</p>
<div title="MDH:PGRpdj5UbyB3aG9tIGl0IG1heSBjb25jZXJuLDwvZGl2Pjxka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