summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/path.c4
-rw-r--r--src/win32/.clang-tidy8
-rw-r--r--src/win32/filesystem_win32.c4
-rw-r--r--test/cpp/test_headers_cpp.cpp2
-rw-r--r--test/cpp/test_path_std.cpp16
-rw-r--r--test/test_btree.c2
-rw-r--r--test/test_hash.c2
-rw-r--r--test/test_ring.c10
-rw-r--r--test/test_tree.c2
9 files changed, 38 insertions, 12 deletions
diff --git a/src/path.c b/src/path.c
index aedf059..7568100 100644
--- a/src/path.c
+++ b/src/path.c
@@ -182,6 +182,10 @@ ZIX_PURE_FUNC
static ZixIndexRange
zix_path_filename_range(const ZixStringView path)
{
+ if (!path.length) {
+ return zix_make_range(0, 0);
+ }
+
// Find the first filename character (skip leading root path if any)
const size_t begin = zix_path_root_path_range(path.data).end;
if (begin == path.length || is_dir_sep(path.data[path.length - 1U])) {
diff --git a/src/win32/.clang-tidy b/src/win32/.clang-tidy
new file mode 100644
index 0000000..386137b
--- /dev/null
+++ b/src/win32/.clang-tidy
@@ -0,0 +1,8 @@
+# Copyright 2021-2022 David Robillard <d@drobilla.net>
+# SPDX-License-Identifier: 0BSD OR ISC
+
+Checks: >
+ -hicpp-signed-bitwise,
+ -misc-misplaced-const,
+ -performance-no-int-to-ptr,
+InheritParentConfig: true
diff --git a/src/win32/filesystem_win32.c b/src/win32/filesystem_win32.c
index 0484684..0038189 100644
--- a/src/win32/filesystem_win32.c
+++ b/src/win32/filesystem_win32.c
@@ -90,7 +90,7 @@ zix_create_temporary_directory(ZixAllocator* const allocator,
// Ensure that the pattern ends with "XXXXXX"
const size_t length = strlen(path_pattern);
- if (length < 7 || strcmp(path_pattern + length - 6, "XXXXXX")) {
+ if (length < 7 || !!strcmp(path_pattern + length - 6, "XXXXXX")) {
errno = EINVAL;
return NULL;
}
@@ -206,7 +206,7 @@ zix_canonical_path(ZixAllocator* const allocator, const char* const path)
}
char* const final = (char*)zix_calloc(allocator, final_size + 1U, 1U);
- if (final && !GetFinalPathNameByHandle(h, final, final_size + 1U, flags)) {
+ if (!final || !GetFinalPathNameByHandle(h, final, final_size + 1U, flags)) {
zix_free(allocator, final);
CloseHandle(h);
return NULL;
diff --git a/test/cpp/test_headers_cpp.cpp b/test/cpp/test_headers_cpp.cpp
index 3fabe6e..f8038c1 100644
--- a/test/cpp/test_headers_cpp.cpp
+++ b/test/cpp/test_headers_cpp.cpp
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: ISC
#ifdef _WIN32
-# define WIN32_LEAN_AND_MEAN 1
+# define WIN32_LEAN_AND_MEAN
#endif
#include "zix/allocator.h" // IWYU pragma: keep
diff --git a/test/cpp/test_path_std.cpp b/test/cpp/test_path_std.cpp
index 50ccad4..6c0e450 100644
--- a/test/cpp/test_path_std.cpp
+++ b/test/cpp/test_path_std.cpp
@@ -433,8 +433,8 @@ equal(const std::filesystem::path& path, const ZixStringView view)
path.u8string() == std::string{view.data, view.length});
}
-int
-main()
+static void
+run()
{
using Path = std::filesystem::path;
@@ -493,3 +493,15 @@ main()
zix_path_lexically_relative(nullptr, relatives.rhs, relatives.lhs)));
}
}
+
+int
+main()
+{
+ try {
+ run();
+ } catch (...) {
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/test/test_btree.c b/test/test_btree.c
index a6f724a..7fd73bc 100644
--- a/test/test_btree.c
+++ b/test/test_btree.c
@@ -97,7 +97,7 @@ test_fail(ZixBTree* t, const char* fmt, ...)
return EXIT_SUCCESS;
}
- va_list args;
+ va_list args; // NOLINT(cppcoreguidelines-init-variables)
va_start(args, fmt);
fprintf(stderr, "error: ");
vfprintf(stderr, fmt, args);
diff --git a/test/test_hash.c b/test/test_hash.c
index 5101aa8..c3aaaba 100644
--- a/test/test_hash.c
+++ b/test/test_hash.c
@@ -35,7 +35,7 @@ test_fail(ZixHash* const hash,
...)
{
if (!expect_failure) {
- va_list args;
+ va_list args; // NOLINT(cppcoreguidelines-init-variables)
va_start(args, fmt);
fprintf(stderr, "error: ");
vfprintf(stderr, fmt, args);
diff --git a/test/test_ring.c b/test/test_ring.c
index fc3d982..644f333 100644
--- a/test/test_ring.c
+++ b/test/test_ring.c
@@ -102,11 +102,13 @@ test_ring(const unsigned size)
const ZixStatus st = zix_ring_mlock(ring);
assert(!st || st == ZIX_STATUS_NOT_SUPPORTED);
- ZixThread reader_thread; // NOLINT
- assert(!zix_thread_create(&reader_thread, MSG_SIZE * 4UL, reader, NULL));
+ static const size_t stack_size = (size_t)MSG_SIZE * 4U;
- ZixThread writer_thread; // NOLINT
- assert(!zix_thread_create(&writer_thread, MSG_SIZE * 4UL, writer, NULL));
+ ZixThread reader_thread; // NOLINT(cppcoreguidelines-init-variables)
+ assert(!zix_thread_create(&reader_thread, stack_size, reader, NULL));
+
+ ZixThread writer_thread; // NOLINT(cppcoreguidelines-init-variables)
+ assert(!zix_thread_create(&writer_thread, stack_size, writer, NULL));
assert(!zix_thread_join(reader_thread));
assert(!zix_thread_join(writer_thread));
diff --git a/test/test_tree.c b/test/test_tree.c
index 700729b..b51bb29 100644
--- a/test/test_tree.c
+++ b/test/test_tree.c
@@ -49,7 +49,7 @@ ZIX_LOG_FUNC(1, 2)
static int
test_fail(const char* const fmt, ...)
{
- va_list args;
+ va_list args; // NOLINT(cppcoreguidelines-init-variables)
va_start(args, fmt);
fprintf(stderr, "error: ");