Overview
| Artifact ID: | 508cd8ea6c9a3e0410b773f47c7760bd7aa11ed262f718a1180027c785c41ee9 |
|---|---|
| Ticket: | 96551aca555c70e4e2157c534c8fdb11acf784e9
Avoid pointer arithmetic with NULL in FOREACH_STRUCT() |
| User & Date: | chrstphrchvz on 2023-04-22 21:37:53 |
Changes
- comment changed to:
Not aware exactly what Tcl code triggers this, but this <tt>-fsanitize=pointer-overflow</tt> error is emitted at the beginning of output from <s><tt>tcltest</tt> during <tt>make test</tt></s> <tt>tclsh</tt>: <blockquote><pre> <b>generic/tclOOMethod.c:1108:2: <span style="color:firebrick">runtime error:</span> applying zero offset to null pointer</b> </pre></blockquote> Something like the following is needed (<tt>var</tt> should also be parenthesized to avoid surprises): <blockquote><pre> --- generic/tclOOInt.h.orig +++ generic/tclOOInt.h @@ -594,7 +594,7 @@ MODULE_SCOPE void TclOOSetupVariableResolver(Tcl_Namespace *nsPtr); */ #define FOREACH_STRUCT(var,ary) \ <span style="color:firebrick">- for(i=0 ; var=&((ary).list[i]), i<(ary).num; i++)</span> <span style="color:green">+ for(i=0 ; (var)=((ary).list ? &((ary).list[i]) : NULL), i<(ary).num; i++)</span> /* * Convenience macros for iterating through hash tables. FOREACH_HASH_DECLS </pre></blockquote> <pre> </pre>
- icomment:
This happens somewhere deep within <tt>TclOOInit()</tt> (so any time an interpreter is created rather than just <tt>tcltest</tt>), during tclOOScript.tcl:416 ("<tt>superclass class</tt>" while in "<tt>class create singleton …</tt>"). - login: "chrstphrchvz"
- mimetype: "text/x-fossil-wiki"