Skip to content

Commit

Permalink
fix: don't bind atoms that are prefixed with nil as NULL (#258)
Browse files Browse the repository at this point in the history
This patch changes the comparison from `utf8ncmp` to `utf8cmp` in order
to explicitly match on the size of the atom. I noticed a case of
inserting an atom of `:nil_safe?` that was cast to `NULL`.

I wasn't sure the correct level to add a test, so please let me know the
best place and I can get it added.
  • Loading branch information
mhanberg authored Aug 17, 2023
1 parent 02097c9 commit a78c756
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion c_src/sqlite3_nif.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ bind(ErlNifEnv* env, const ERL_NIF_TERM arg, sqlite3_stmt* statement, int index)
}

if (enif_get_atom(env, arg, the_atom, sizeof(the_atom), ERL_NIF_LATIN1)) {
if (0 == utf8ncmp("undefined", the_atom, 9) || 0 == utf8ncmp("nil", the_atom, 3)) {
if (0 == utf8cmp("undefined", the_atom) || 0 == utf8cmp("nil", the_atom)) {
return sqlite3_bind_null(statement, index);
}

Expand Down

0 comments on commit a78c756

Please sign in to comment.