On 28 January 2018 at 12:12, Chris Wright <c...@daverandom.com> wrote:
>
> Here is some code that demonstrates the problem:
>
>     /* This is the only way to know for certain how big float is on the
> local system */
>     define('FLOAT_WIDTH', strlen(pack('f', 0.0)));
>
>     /* an exaggerated example using two variable width codes and a code
> that
>        does not produce output but modifies the input buffer offset */
>     $pieces = unpack('f/X/Z*', $data, $offset);
>
>     /* we now have to modify the offset before we can continue to unpack
> data */
>     $offset += FLOAT_WIDTH         // f
>              - 1                   // x
>              + strlen($pieces[3]); // Z*
>

Re-reading this mail I have noticed there was a small mistake in the code
sample, in that I forgot to include the terminating null byte for the Z*
data.

This (unintentionally) demonstrates the exact reason I would like to add
this, as it's very easy to accidentally write subtle bugs.

Reply via email to