Skip to content

Commit 7598236

Browse files
committed
Update pgsql.c
1 parent e0ac056 commit 7598236

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

ext/pgsql/pgsql.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3428,9 +3428,12 @@ static zend_result pgsql_copy_from_query(PGconn *pgsql, PGresult *pgsql_result,
34283428

34293429
int result;
34303430
if (ZSTR_LEN(tmp) > 0 && ZSTR_VAL(tmp)[ZSTR_LEN(tmp) - 1] != '\n') {
3431-
zend_string *new_tmp = zend_string_concat2(ZSTR_VAL(tmp), ZSTR_LEN(tmp), "\n", 1);
3432-
result = PQputCopyData(pgsql, ZSTR_VAL(new_tmp), ZSTR_LEN(new_tmp));
3433-
zend_string_release(new_tmp);
3431+
char *zquery = emalloc(ZSTR_LEN(tmp) + 2);
3432+
memcpy(zquery, ZSTR_VAL(tmp), ZSTR_LEN(tmp));
3433+
zquery[ZSTR_LEN(tmp)] = '\n';
3434+
zquery[ZSTR_LEN(tmp) + 1] = '\0';
3435+
result = PQputCopyData(pgsql, zquery, ZSTR_LEN(tmp) + 1);
3436+
efree(zquery);
34343437
} else {
34353438
result = PQputCopyData(pgsql, ZSTR_VAL(tmp), ZSTR_LEN(tmp));
34363439
}

0 commit comments

Comments
 (0)