I have a statement
strncpy(&data->m_bin->data,versionStr,data->m_bin->sizeData);
in my application which itself is fine and works well. Here data->m_bin->data is a char where the calling application ensures it is followed by a datablock which is large enough to keep all the data handed over by strncpy().
But when I build this as release using GCC/Linux, this function crashes in __strncpy_chk(). So it seems my strncpy() was replaced by __strncpy_chk() using a wrong length for parameter s1.
So how can I ensure __strncpy_chk() is called with the correct length for s1?
Thanks!
The
address ofoperator looks suspicious to me. I would expect something like:Or maybe:
Well, you can't per se. This is part of
FORTIFY_SOURCEand object size checking, and the destination buffer size is used when the compiler can deduce it.You could possibly do something like the following, assuming
datais an array of sizesizeData.You should probably turn on warnings with
-Wall. I suspect you should get one for using theaddress ofoperator.