On Wed, Oct 14, 2009 at 9:13 AM, Michael Widenius <monty@stripped> wrote:
>>>>>> "MARK" == MARK CALLAGHAN <mdcallag@stripped> writes:
> MARK> 2) Change the name of c_ptr as it doesn't return a C pointer to a
> MARK> string. If it did, the result would be nul terminated and there would
> MARK> be no need for c_ptr_unsafe.
> c_ptr does return a pointer to a \0 terminated string. It does however
> don't know if the last byte is initialized memory or not, which is a
> problem for valgrind but not normally for MySQL as Strings is mainly
> used for thread specific memory.
If you use it in that way then this code has a race. When
Ptr[str_length] == 0, it doesn't realloc and nul-terminate the string.
But Ptr[str_length] might not have been allocated for this string. So
it Ptr[str_length] might be 0 when the check is made and then not 0
when this returns.
inline char *c_ptr()
if (!Ptr || Ptr[str_length]) /* Should be safe */