<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.8" -->
<?xml-stylesheet href="https://baszerr.eu/lib/exe/css.php?s=feed" type="text/css"?>
<rss version="2.0">
    <channel xmlns:g="http://base.google.com/ns/1.0">
        <title>BaSzErr - blog:2013:05:25</title>
        <description></description>
        <link>https://baszerr.eu/</link>
        <lastBuildDate>Sat, 02 May 2026 10:36:18 +0000</lastBuildDate>
        <generator>FeedCreator 1.8</generator>
        <image>
            <url>https://baszerr.eu/lib/exe/fetch.php?media=wiki:dokuwiki.svg</url>
            <title>BaSzErr</title>
            <link>https://baszerr.eu/</link>
        </image>
        <item>
            <title>asan</title>
            <link>https://baszerr.eu/doku.php?id=blog:2013:05:25:asan</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;address_sanitizer&quot;&gt;2013.05.25 - address sanitizer&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
when it comes to debugging memory issues two tools have a warm place in my heart: &lt;a href=&quot;https://en.wikipedia.org/wiki/Duma (software)&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/Duma (software)&quot;&gt;duma&lt;/a&gt; and &lt;a href=&quot;https://en.wikipedia.org/wiki/valgrind&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/valgrind&quot;&gt;valgrind&lt;/a&gt;. both are nice, but there is always some “but”. duma is fast, but is only able to detect issues related to a heap. valgrind is a bit more robust (in fact – not limited to out-of-range r/w detection), but is terribly slow. recently i got aware of a new kid in town – &lt;a href=&quot;https://code.google.com/p/address-sanitizer&quot; class=&quot;urlextern&quot; title=&quot;https://code.google.com/p/address-sanitizer&quot; rel=&quot;ugc nofollow&quot;&gt;address sanitizer&lt;/a&gt; plugin for &lt;a href=&quot;https://en.wikipedia.org/wiki/clang&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/clang&quot;&gt;clang&lt;/a&gt;, starting with version 3.1. it is &lt;a href=&quot;http://clang.llvm.org/docs/AddressSanitizer.html&quot; class=&quot;urlextern&quot; title=&quot;http://clang.llvm.org/docs/AddressSanitizer.html&quot; rel=&quot;ugc nofollow&quot;&gt;incredibly easy to use&lt;/a&gt;: it is enough to pass &lt;em&gt;-g -fsanitize=address -fno-omit-frame-pointer&lt;/em&gt; flags to compilation and linking, and it is done – code is instrumented using Asan!
&lt;/p&gt;

&lt;p&gt;
the main idea behind this tool is to instrument code, in places that “might go wrong”, instead of relying on page allocations (heap-only) or full emulation (slow). most of the memory issues can be detected this way, while having minimal overhead on the performance (~2x, typically) and extra memory usage (both heap and stack).
&lt;/p&gt;

&lt;p&gt;
having sample program:
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;iostream&amp;gt;&lt;/span&gt;
using namespace std&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt; mkStr&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;string const&lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt; in&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; in.&lt;span class=&quot;me1&quot;&gt;c_str&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; main&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&quot;kw4&quot;&gt;auto&lt;/span&gt; str &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; mkStr&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;abc&amp;quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
  cout &lt;span class=&quot;sy0&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; str &lt;span class=&quot;sy0&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; endl&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
and running binary compiled with llvm/clang-trunk (i.e. pre-3.3 release), produces the following output:
&lt;/p&gt;

&lt;p&gt;
&lt;a href=&quot;https://baszerr.eu/lib/exe/detail.php?id=blog%3A2013%3A05%3A25%3Aasan&amp;amp;media=blog:2013:05:25:asan_error_report.png&quot; class=&quot;media&quot; title=&quot;blog:2013:05:25:asan_error_report.png&quot;&gt;&lt;img src=&quot;https://baszerr.eu/lib/exe/fetch.php?media=blog:2013:05:25:asan_error_report.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; title=&quot;asan error report: heap&quot; alt=&quot;asan error report: heap&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
similarly out-of-bound reads on stack can be detected. happy debugging! :)
&lt;/p&gt;

&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Tue, 15 Jun 2021 20:09:05 +0000</pubDate>
        </item>
    </channel>
</rss>
