Skip to content

Commit 0651383

Browse files
committed
terminate string by setting a 0
1 parent 8084c48 commit 0651383

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

c_src/libpg_query_ex.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@ static ERL_NIF_TERM parse_query(ErlNifEnv *env, int argc,
2222
ERL_NIF_TERM term;
2323

2424
if (argc == 1 && enif_inspect_binary(env, argv[0], &query)) {
25+
// add one more byte for the null termination
2526
char statement[query.size + 1];
26-
memset(statement, 0, sizeof(statement));
27+
2728
strncpy(statement, (char *)query.data, query.size);
2829

30+
// terminate the string
31+
statement[query.size] = 0;
32+
2933
PgQueryProtobufParseResult result = pg_query_parse_protobuf(statement);
3034

3135
if (result.error) {

0 commit comments

Comments
 (0)