Skip to content

Commit

Permalink
tidy: enable cert checks
Browse files Browse the repository at this point in the history
Though we don't aim to be certified in any sense, these checks are still
useful. Most of the changes are targeted at cert-err58-cpp, which checks
that no errors are thrown during global initialization and the like.
The check is helpful to us because it points out cases when it would
make sense to use non-allocating globals, like `const char*` or
`string_view`.

The constructors of one function were changed because when the function
names are `const char*`, C++ selects the wrong constructor.
Additionally, the constructor arguments were inconsistently ordered.
  • Loading branch information
Riolku committed Nov 29, 2023
1 parent c92c046 commit ff5e450
Show file tree
Hide file tree
Showing 17 changed files with 254 additions and 241 deletions.
5 changes: 5 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Comments go at the top because otherwise clang-tidy interprets them as breaking up our list of checks.
# Bugprone exception escape is super unhelpful.
# cert-str34-c is an alias for signed-char-misuse.
Checks:
-*,

Expand All @@ -10,6 +12,9 @@ Checks:
-bugprone-narrowing-conversions,
-bugprone-signed-char-misuse,

cert-*,
-cert-str34-c,

concurrency-*,

cppcoreguidelines-virtual-class-destructor,
Expand Down
23 changes: 13 additions & 10 deletions src/common/copier_config/copier_config.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
#include "common/copier_config/copier_config.h"

#include <unordered_map>

#include "common/assert.h"
#include "common/exception/copy.h"

namespace kuzu {
namespace common {

const static std::unordered_map<std::string, FileType> fileTypeMap{{".csv", FileType::CSV},
{".parquet", FileType::PARQUET}, {".npy", FileType::NPY}, {".ttl", FileType::TURTLE}};

FileType FileTypeUtils::getFileTypeFromExtension(const std::string& extension) {
auto entry = fileTypeMap.find(extension);
if (entry == fileTypeMap.end()) {
throw CopyException("Unsupported file type " + extension);
FileType FileTypeUtils::getFileTypeFromExtension(std::string_view extension) {
if (extension == ".csv") {
return FileType::CSV;
}
if (extension == ".parquet") {
return FileType::PARQUET;
}
if (extension == ".npy") {
return FileType::NPY;
}
if (extension == ".ttl") {
return FileType::TURTLE;
}
return entry->second;
throw CopyException(std::string("Unsupported file type ").append(extension));
}

std::string FileTypeUtils::toString(FileType fileType) {
Expand Down
1 change: 1 addition & 0 deletions src/common/types/int128_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace kuzu::common {

// NOLINTNEXTLINE(cert-err58-cpp): This initialization won't actually throw.
const int128_t Int128_t::powerOf10[]{
int128_t(1),
int128_t(10),
Expand Down
9 changes: 3 additions & 6 deletions src/common/types/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,9 @@ LogicalType::LogicalType(const LogicalType& other) {
}

LogicalType& LogicalType::operator=(const LogicalType& other) {
typeID = other.typeID;
physicalType = other.physicalType;
if (other.extraTypeInfo != nullptr) {
extraTypeInfo = other.extraTypeInfo->copy();
}
return *this;
// Reuse the copy constructor and move assignment operator.
LogicalType copy(other);
return *this = std::move(copy);
}

bool LogicalType::operator==(const LogicalType& other) const {
Expand Down
2 changes: 1 addition & 1 deletion src/include/common/copier_config/copier_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct CSVReaderConfig : public CSVOption {
enum class FileType : uint8_t { UNKNOWN = 0, CSV = 1, PARQUET = 2, NPY = 3, TURTLE = 4 };

struct FileTypeUtils {
static FileType getFileTypeFromExtension(const std::string& extension);
static FileType getFileTypeFromExtension(std::string_view extension);
static std::string toString(FileType fileType);
};

Expand Down
Loading

0 comments on commit ff5e450

Please sign in to comment.