From a78c7561bc5d3b8da98608c6ed7bbe786fd334b6 Mon Sep 17 00:00:00 2001 From: Mitchell Hanberg Date: Thu, 17 Aug 2023 01:02:07 -0400 Subject: [PATCH] fix: don't bind atoms that are prefixed with `nil` as NULL (#258) 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. --- c_src/sqlite3_nif.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c_src/sqlite3_nif.c b/c_src/sqlite3_nif.c index 77a672bf..e6309ea9 100644 --- a/c_src/sqlite3_nif.c +++ b/c_src/sqlite3_nif.c @@ -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); }