Use of strncpy with a length limit based on the source, rather than
the destination, is non-idiomatic and draws warnings from gcc 8.
Replace with memcpy, which does exactly the same thing in these cases,
but with less chance for confusion.
Backpatch to all supported branches.
Discussion: https://postgr.es/m/21789.
1529170195@sss.pgh.pa.us
(struct ECPGgeneric_varchar *) var;
if (varcharsize == 0)
- strncpy(variable->arr, value, strlen(value));
+ memcpy(variable->arr, value, strlen(value));
else
strncpy(variable->arr, value, varcharsize);
i = strlen(replace_val.str_val);
if (i + 1 <= *pstr_len)
{
- /*
- * copy over i + 1 bytes, that includes the tailing terminator
- */
- strncpy(*output, replace_val.str_val, i + 1);
+ /* include trailing terminator in what we copy */
+ memcpy(*output, replace_val.str_val, i + 1);
*pstr_len -= i;
*output += i;
if (replace_type == PGTYPES_TYPE_STRING_MALLOCED)