summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2018-06-16 14:58:11 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2018-06-16 14:58:31 -0400
commit58065f9eed68fae83ddf98c8dff24ae8f0b62f0c (patch)
tree062609a688eb31a7421791fb0115899adbf9cd54
parent8870e2978fc5db5741229f5cddc7bcc24ee52000 (diff)
Avoid unnecessary use of strncpy in a couple of places in ecpg.
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
-rw-r--r--src/interfaces/ecpg/ecpglib/descriptor.c2
-rw-r--r--src/interfaces/ecpg/pgtypeslib/common.c6
2 files changed, 3 insertions, 5 deletions
diff --git a/src/interfaces/ecpg/ecpglib/descriptor.c b/src/interfaces/ecpg/ecpglib/descriptor.c
index 15fd7a08a53..89965610783 100644
--- a/src/interfaces/ecpg/ecpglib/descriptor.c
+++ b/src/interfaces/ecpg/ecpglib/descriptor.c
@@ -217,7 +217,7 @@ get_char_item(int lineno, void *var, enum ECPGttype vartype, char *value, int va
(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);
diff --git a/src/interfaces/ecpg/pgtypeslib/common.c b/src/interfaces/ecpg/pgtypeslib/common.c
index 9084fd06b4e..fd29e30a3bb 100644
--- a/src/interfaces/ecpg/pgtypeslib/common.c
+++ b/src/interfaces/ecpg/pgtypeslib/common.c
@@ -42,10 +42,8 @@ pgtypes_fmt_replace(union un_fmt_comb replace_val, int replace_type, char **outp
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)