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

Commit 6b74f5e

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 5d923eb commit 6b74f5e

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
@@ -218,7 +218,7 @@ get_char_item(int lineno, void *var, enum ECPGttype vartype, char *value, int va
218218
(struct ECPGgeneric_varchar *) var;
219219

220220
if (varcharsize == 0)
221-
strncpy(variable->arr, value, strlen(value));
221+
memcpy(variable->arr, value, strlen(value));
222222
else
223223
strncpy(variable->arr, value, varcharsize);
224224

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)