<!DOCTYPE qhelp PUBLIC
  "-//Semmle//qhelp//EN"
  "qhelp.dtd">
<qhelp>
<overview>
<p>Casting arbitrary pointers into <tt>char*</tt> and then accessing their
contents should be done with care. The results may not be portable.</p>

<p>
This query finds pointer arithmetic expressions where a pointer to
<tt>char</tt> (or similar) is dereferenced even though the underlying value is
of a type larger than <tt>char</tt>.
</p>

</overview>
<recommendation>

<ol>
<li>Whenever possible, use the array subscript operator rather than
pointer arithmetic. For example, replace <tt>*(p+k)</tt>
with <tt>p[k]</tt>.</li>
<li>Cast to the correct type before using pointer arithmetic. For
example, if the type of <tt>p</tt> is <tt>char*</tt> but it really
points to an array of type <tt>double[]</tt> then use the syntax
<tt>(double*)p + k</tt> to get a pointer to the <tt>k</tt>'th element
of the array.</li>
</ol>

</recommendation>
<example>

<sample src="IncorrectPointerScalingChar.cpp" />

</example>
<references>

</references>
</qhelp>
