Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 58065f9

Browse files
committed
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
1 parent 8870e29 commit 58065f9

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

src/interfaces/ecpg/ecpglib/descriptor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ get_char_item(int lineno, void *var, enum ECPGttype vartype, char *value, int va
217217
(struct ECPGgeneric_varchar *) var;
218218

219219
if (varcharsize == 0)
220-
strncpy(variable->arr, value, strlen(value));
220+
memcpy(variable->arr, value, strlen(value));
221221
else
222222
strncpy(variable->arr, value, varcharsize);
223223

src/interfaces/ecpg/pgtypeslib/common.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ pgtypes_fmt_replace(union un_fmt_comb replace_val, int replace_type, char **outp
4242
i = strlen(replace_val.str_val);
4343
if (i + 1 <= *pstr_len)
4444
{
45-
/*
46-
* copy over i + 1 bytes, that includes the tailing terminator
47-
*/
48-
strncpy(*output, replace_val.str_val, i + 1);
45+
/* include trailing terminator in what we copy */
46+
memcpy(*output, replace_val.str_val, i + 1);
4947
*pstr_len -= i;
5048
*output += i;
5149
if (replace_type == PGTYPES_TYPE_STRING_MALLOCED)

0 commit comments

Comments
 (0)