<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">If you’re talking about UBSan’s out of bounds detection, this is a known gap, it only handles the most trivial cases where you’re directly indexing an array with a known size. Round-tripping through a temporary pointer variable as in your case is enough to obfuscate it so it doesn’t know the array’s bounds and will only detect pointer overflow (as in, wrapping the address space). Whilst you could relatively easily teach UBSan to be able to peek through such cases, in the general case detecting out of bounds indices requires a whole new ABI that modifies pointers such that they carry the bounds of their underlying object (whatever your interpretation of C has that mean).<br class=""><div class="">
<div dir="auto" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div dir="auto" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div dir="auto" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div dir="auto" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div dir="auto" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><br class="Apple-interchange-newline">Jess</span></div></div></div></div></div>
</div>
<div><br class=""><blockquote type="cite" class=""><div class="">On 27 Jan 2022, at 09:16, phy coder via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">So, I was trying to do this  , what I was expecting is undefined behavior by ptr[-4] and b[-4] but the undefined behavior is only shown by b[-4] . I know that a pointer can have a negative index when there is some defined value at that address . But in this case , sanitizer has to give undefined behavior for ptr[-4]  but there is no such error . I'm not sure if this is considered as Undefined Behavior or not . Or maybe some other tools exist for this type of undefined behavior .<br class=""></div><div class=""><br class=""></div><div class=""><table class="gmail-ajC" cellpadding="0"><tbody class=""><tr class="gmail-ajv"><td colspan="2" tabindex="0" class="gmail-gG"><span class="gmail-gI"></span><br class=""></td><td colspan="2" tabindex="0" class="gmail-gL"><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:Consolas,"Liberation Mono",Courier,monospace,"Droid Sans Mono","monospace",monospace,"Droid Sans Fallback";font-weight:normal;font-size:14px;line-height:19px;white-space:pre" class=""><div class=""><span style="color:rgb(86,156,214)" class="">#include</span><span style="color:rgb(212,212,212)" class=""> </span><span style="color:rgb(86,156,214)" class=""><</span><span style="color:rgb(206,145,120)" class="">iostream</span><span style="color:rgb(86,156,214)" class="">></span></div><br class=""><div class=""><span style="color:rgb(86,156,214)" class="">int</span><span style="color:rgb(212,212,212)" class=""> main</span><span style="color:rgb(220,220,220)" class="">()</span><span style="color:rgb(212,212,212)" class=""> </span><span style="color:rgb(220,220,220)" class="">{</span></div><div class=""><span style="color:rgb(212,212,212)" class="">  </span></div><div class=""><span style="color:rgb(212,212,212)" class="">    </span><span style="color:rgb(86,156,214)" class="">int</span><span style="color:rgb(212,212,212)" class=""> b</span><span style="color:rgb(220,220,220)" class="">[]=</span><span style="color:rgb(212,212,212)" class=""> </span><span style="color:rgb(220,220,220)" class="">{</span><span style="color:rgb(181,206,168)" class="">7</span><span style="color:rgb(220,220,220)" class="">,</span><span style="color:rgb(181,206,168)" class="">5</span><span style="color:rgb(220,220,220)" class="">,</span><span style="color:rgb(181,206,168)" class="">4</span><span style="color:rgb(220,220,220)" class="">,</span><span style="color:rgb(181,206,168)" class="">3</span><span style="color:rgb(220,220,220)" class="">,</span><span style="color:rgb(181,206,168)" class="">2</span><span style="color:rgb(220,220,220)" class="">}</span><span style="color:rgb(212,212,212)" class=""> </span><span style="color:rgb(220,220,220)" class="">;</span></div><br class=""><div class=""><span style="color:rgb(212,212,212)" class="">    </span><span style="color:rgb(86,156,214)" class="">char</span><span style="color:rgb(212,212,212)" class=""> a</span><span style="color:rgb(220,220,220)" class="">[]</span><span style="color:rgb(212,212,212)" class=""> </span><span style="color:rgb(220,220,220)" class="">=</span><span style="color:rgb(212,212,212)" class=""> </span><span style="color:rgb(206,145,120)" class="">"hello"</span><span style="color:rgb(220,220,220)" class="">;</span></div><div class=""><span style="color:rgb(212,212,212)" class="">    </span><span style="color:rgb(86,156,214)" class="">char</span><span style="color:rgb(212,212,212)" class=""> </span><span style="color:rgb(220,220,220)" class="">*</span><span style="color:rgb(212,212,212)" class="">ptr </span><span style="color:rgb(220,220,220)" class="">=</span><span style="color:rgb(212,212,212)" class=""> a</span><span style="color:rgb(220,220,220)" class="">;</span></div><div class=""><span style="color:rgb(212,212,212)" class="">    std::cout</span><span style="color:rgb(220,220,220)" class=""><<</span><span style="color:rgb(212,212,212)" class=""> ptr</span><span style="color:rgb(220,220,220)" class="">[</span><span style="color:rgb(181,206,168)" class="">0</span><span style="color:rgb(220,220,220)" class="">]</span><span style="color:rgb(212,212,212)" class=""> </span><span style="color:rgb(220,220,220)" class=""><<</span><span style="color:rgb(212,212,212)" class=""> ptr</span><span style="color:rgb(220,220,220)" class="">[-</span><span style="color:rgb(181,206,168)" class="">4</span><span style="color:rgb(220,220,220)" class="">]</span><span style="color:rgb(212,212,212)" class=""> </span><span style="color:rgb(220,220,220)" class=""><<</span><span style="color:rgb(212,212,212)" class=""> b</span><span style="color:rgb(220,220,220)" class="">[</span><span style="color:rgb(181,206,168)" class="">0</span><span style="color:rgb(220,220,220)" class="">]</span><span style="color:rgb(212,212,212)" class=""> </span><span style="color:rgb(220,220,220)" class=""><<</span><span style="color:rgb(212,212,212)" class=""> b</span><span style="color:rgb(220,220,220)" class="">[-</span><span style="color:rgb(181,206,168)" class="">4</span><span style="color:rgb(220,220,220)" class="">];</span></div><div class=""><span style="color:rgb(220,220,220)" class="">}<br class=""></span></div></div></td></tr></tbody></table></div></div>
_______________________________________________<br class="">cfe-dev mailing list<br class=""><a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a><br class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev<br class=""></div></blockquote></div><br class=""></body></html>