From a3afde347295238bbb907e7a79f48a8ee6ba7425 Mon Sep 17 00:00:00 2001 From: Rene Cannao Date: Thu, 22 Jan 2026 11:42:08 +0000 Subject: [PATCH] fix: Address copilot review concerns for Discovery_Schema.cpp - Fix comment mismatch: Changed _2 suffix to match actual function name (mysql_query_digest_and_first_comment, not _2) - Make get_def_mysql_opts() static to avoid symbol pollution - Fix NULL first_comment parameter to prevent potential segfault - Pass valid char* pointer instead of NULL - Free first_comment if allocated by the function --- lib/Discovery_Schema.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/Discovery_Schema.cpp b/lib/Discovery_Schema.cpp index 5e6ff4a99..667fab95c 100644 --- a/lib/Discovery_Schema.cpp +++ b/lib/Discovery_Schema.cpp @@ -2972,7 +2972,7 @@ uint64_t Discovery_Schema::compute_mcp_digest( return hash1; } -options get_def_mysql_opts() { +static options get_def_mysql_opts() { options opts {}; opts.lowercase = false; @@ -3019,7 +3019,7 @@ options get_def_mysql_opts() { // the same fingerprint. // // SQL Handling: For arguments where key is "sql", the value is replaced by a -// digest generated using mysql_query_digest_and_first_comment_2 instead of "?". +// digest generated using mysql_query_digest_and_first_comment instead of "?". // This normalizes SQL queries (removes comments, extra whitespace, etc.) so that // semantically equivalent queries produce the same fingerprint. std::string Discovery_Schema::fingerprint_mcp_args(const nlohmann::json& arguments) { @@ -3039,13 +3039,17 @@ std::string Discovery_Schema::fingerprint_mcp_args(const nlohmann::json& argumen if (it.key() == "sql") { std::string sql_value = it.value().get(); const options def_opts { get_def_mysql_opts() }; + char* first_comment = nullptr; // Will be allocated by the function if needed char* digest = mysql_query_digest_and_first_comment( sql_value.c_str(), sql_value.length(), - NULL, // first_comment - not needed + &first_comment, NULL, // buffer - not needed &def_opts ); + if (first_comment) { + free(first_comment); + } // Escape the digest for JSON and add it to result result += "\""; if (digest) {