Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(c): satisfy -Wextra -Wpedantic #917

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion c/cmake_modules/AdbcDefines.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
36 changes: 24 additions & 12 deletions c/driver/postgresql/connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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")) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand All @@ -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<std::string> params;
if (StringBuilderInit(&query, /*initial_size=*/256) != 0) return ADBC_STATUS_INTERNAL;

Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 9 additions & 3 deletions c/driver/sqlite/statement_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
Loading