diff --git a/c/cmake_modules/AdbcDefines.cmake b/c/cmake_modules/AdbcDefines.cmake index 466c90d8e3..5cc2eaa60b 100644 --- a/c/cmake_modules/AdbcDefines.cmake +++ b/c/cmake_modules/AdbcDefines.cmake @@ -75,7 +75,12 @@ if(MSVC) elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(ADBC_C_CXX_FLAGS_CHECKIN -Wall -Werror) + set(ADBC_C_CXX_FLAGS_CHECKIN + -Wall + -Wextra + -Wpedantic + -Werror + -Wno-unused-parameter) set(ADBC_C_CXX_FLAGS_PRODUCTION -Wall) else() message(WARNING "Unknown compiler: ${CMAKE_CXX_COMPILER_ID}") diff --git a/c/driver/postgresql/connection.cc b/c/driver/postgresql/connection.cc index 1b256b6761..08ff9027c3 100644 --- a/c/driver/postgresql/connection.cc +++ b/c/driver/postgresql/connection.cc @@ -242,7 +242,8 @@ class PqGetObjectsHelper { AdbcStatusCode AppendSchemas(std::string db_name) { // postgres only allows you to list schemas for the currently connected db if (!strcmp(db_name.c_str(), PQdb(conn_))) { - struct StringBuilder query = {0}; + struct StringBuilder query; + std::memset(&query, 0, sizeof(query)); if (StringBuilderInit(&query, /*initial_size*/ 256)) { return ADBC_STATUS_INTERNAL; } @@ -291,7 +292,8 @@ class PqGetObjectsHelper { } AdbcStatusCode AppendCatalogs() { - struct StringBuilder query = {0}; + struct StringBuilder query; + std::memset(&query, 0, sizeof(query)); if (StringBuilderInit(&query, /*initial_size=*/256) != 0) return ADBC_STATUS_INTERNAL; if (StringBuilderAppend(&query, "%s", "SELECT datname FROM pg_catalog.pg_database")) { @@ -330,7 +332,8 @@ class PqGetObjectsHelper { } AdbcStatusCode AppendTables(std::string schema_name) { - struct StringBuilder query = {0}; + struct StringBuilder query; + std::memset(&query, 0, sizeof(query)); if (StringBuilderInit(&query, /*initial_size*/ 512)) { return ADBC_STATUS_INTERNAL; } @@ -429,7 +432,8 @@ class PqGetObjectsHelper { } AdbcStatusCode AppendColumns(std::string schema_name, std::string table_name) { - struct StringBuilder query = {0}; + struct StringBuilder query; + std::memset(&query, 0, sizeof(query)); if (StringBuilderInit(&query, /*initial_size*/ 512)) { return ADBC_STATUS_INTERNAL; } @@ -516,7 +520,8 @@ class PqGetObjectsHelper { } AdbcStatusCode AppendConstraints(std::string schema_name, std::string table_name) { - struct StringBuilder query = {0}; + struct StringBuilder query; + std::memset(&query, 0, sizeof(query)); if (StringBuilderInit(&query, /*initial_size*/ 4096)) { return ADBC_STATUS_INTERNAL; } @@ -796,8 +801,10 @@ AdbcStatusCode PostgresConnection::GetInfo(struct AdbcConnection* connection, info_codes_length = sizeof(kSupportedInfoCodes) / sizeof(kSupportedInfoCodes[0]); } - struct ArrowSchema schema = {0}; - struct ArrowArray array = {0}; + struct ArrowSchema schema; + std::memset(&schema, 0, sizeof(schema)); + struct ArrowArray array; + std::memset(&array, 0, sizeof(array)); AdbcStatusCode status = PostgresConnectionGetInfoImpl(codes, info_codes_length, &schema, &array, error); @@ -814,8 +821,10 @@ AdbcStatusCode PostgresConnection::GetObjects( struct AdbcConnection* connection, int depth, const char* catalog, const char* db_schema, const char* table_name, const char** table_types, const char* column_name, struct ArrowArrayStream* out, struct AdbcError* error) { - struct ArrowSchema schema = {0}; - struct ArrowArray array = {0}; + struct ArrowSchema schema; + std::memset(&schema, 0, sizeof(schema)); + struct ArrowArray array; + std::memset(&array, 0, sizeof(array)); PqGetObjectsHelper helper = PqGetObjectsHelper(conn_, depth, catalog, db_schema, table_name, table_types, @@ -837,7 +846,8 @@ AdbcStatusCode PostgresConnection::GetTableSchema(const char* catalog, struct ArrowSchema* schema, struct AdbcError* error) { AdbcStatusCode final_status = ADBC_STATUS_OK; - struct StringBuilder query = {0}; + struct StringBuilder query; + std::memset(&query, 0, sizeof(query)); std::vector params; if (StringBuilderInit(&query, /*initial_size=*/256) != 0) return ADBC_STATUS_INTERNAL; @@ -937,8 +947,10 @@ AdbcStatusCode PostgresConnectionGetTableTypesImpl(struct ArrowSchema* schema, AdbcStatusCode PostgresConnection::GetTableTypes(struct AdbcConnection* connection, struct ArrowArrayStream* out, struct AdbcError* error) { - struct ArrowSchema schema = {0}; - struct ArrowArray array = {0}; + struct ArrowSchema schema; + std::memset(&schema, 0, sizeof(schema)); + struct ArrowArray array; + std::memset(&array, 0, sizeof(array)); AdbcStatusCode status = PostgresConnectionGetTableTypesImpl(&schema, &array, error); if (status != ADBC_STATUS_OK) { diff --git a/c/driver/sqlite/statement_reader.c b/c/driver/sqlite/statement_reader.c index b434dae91c..366c0fa1f3 100644 --- a/c/driver/sqlite/statement_reader.c +++ b/c/driver/sqlite/statement_reader.c @@ -719,7 +719,10 @@ AdbcStatusCode StatementReaderAppendInt64ToBinary(struct ArrowBuffer* offsets, int written = 0; while (1) { written = snprintf(output, buffer_size, "%" PRId64, value); - if (written >= buffer_size) { + if (written < 0) { + SetError(error, "Encoding error when upcasting double to string"); + return ADBC_STATUS_INTERNAL; + } else if (((size_t)written) >= buffer_size) { // Truncated, resize and try again // Check for overflow - presumably this can never happen...? if (UINT_MAX - buffer_size < buffer_size) { @@ -749,7 +752,10 @@ AdbcStatusCode StatementReaderAppendDoubleToBinary(struct ArrowBuffer* offsets, int written = 0; while (1) { written = snprintf(output, buffer_size, "%e", value); - if (written >= buffer_size) { + if (written < 0) { + SetError(error, "Encoding error when upcasting double to string"); + return ADBC_STATUS_INTERNAL; + } else if (((size_t)written) >= buffer_size) { // Truncated, resize and try again // Check for overflow - presumably this can never happen...? if (UINT_MAX - buffer_size < buffer_size) { @@ -977,7 +983,7 @@ AdbcStatusCode AdbcSqliteExportReader(sqlite3* db, sqlite3_stmt* stmt, if (status == ADBC_STATUS_OK && !reader->done) { int64_t num_rows = 0; - while (num_rows < batch_size) { + while (((size_t)num_rows) < batch_size) { int rc = sqlite3_step(stmt); if (rc == SQLITE_DONE) { if (!binder) {