<p dir="ltr">What are you really trying to do? How do you intend to use the result of this function?</p>
<div class="gmail_quote">On 17 Sep 2013 12:26, "Jeffrey Walton" <<a href="mailto:noloader@gmail.com">noloader@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I'm working with some source code that does the following. Its<br>
declared as a static method.<br>
<br>
167  long<br>
168  cbdata::MakeOffset()<br>
169  {<br>
170      cbdata *zero = (cbdata *)0L;<br>
171      void **dataOffset = &zero->data;<br>
172      return (long)dataOffset;<br>
173  }<br>
<br>
Under UBSan, the code creates an entry for each use of MakeOffset():<br>
<br>
    runtime error: member access within null pointer of type 'cbdata'<br>
<br>
The code is not amicable to use of offsetof(...). I think its because<br>
there's a Stack member, but I don't know the C/C++ language rules like<br>
most folks.<br>
<br>
   cbdata.cc:176:19: error: offset of on non-POD type 'struct cbdata'<br>
<br>
But I'm fairly certain (correct me here) it falls under case 2 listed<br>
at <a href="http://gcc.gnu.org/ml/gcc/2003-11/msg00281.html" target="_blank">http://gcc.gnu.org/ml/gcc/2003-11/msg00281.html</a>:<br>
<br>
    2) Those cases where any reasonable implementation (and all<br>
       implementations we know of) give the right answer, but ISO<br>
       C++ says "undefined".<br>
<br>
Is there a way to code MakeOffset() so that UBSan will be happy so as<br>
to avoid the runtime error? Or will this have to go into an ignore<br>
list?<br>
<br>
Thanks in advance.<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</blockquote></div>