From aae5b746531755cd0f90cb6fb757f1ce5c8003a7 Mon Sep 17 00:00:00 2001 From: Davin Shearer Date: Tue, 21 Nov 2023 19:53:54 -0500 Subject: [PATCH] lint fixes --- core/src/examples/count_characters.c | 2 -- core/src/examples/profile.c | 1 - core/src/examples/simple_c.c | 5 +++-- core/src/examples/transform.c | 8 ++++++-- core/src/lib/filesystem.cpp | 10 +++++----- core/src/lib/impl_/model_segment_def.hpp | 1 + core/src/lib/utility.c | 4 ---- core/src/tests/omega_test.cpp | 4 ++-- 8 files changed, 17 insertions(+), 18 deletions(-) diff --git a/core/src/examples/count_characters.c b/core/src/examples/count_characters.c index 5ae2ef314..a51a28d05 100644 --- a/core/src/examples/count_characters.c +++ b/core/src/examples/count_characters.c @@ -12,8 +12,6 @@ * * **********************************************************************************************************************/ -#define __STDC_FORMAT_MACROS - #include #include #include diff --git a/core/src/examples/profile.c b/core/src/examples/profile.c index e574f48cf..dcd0efa67 100644 --- a/core/src/examples/profile.c +++ b/core/src/examples/profile.c @@ -15,7 +15,6 @@ /** * This application can be used to test out and demonstrate the Omega-Edit session profiler. */ -#define __STDC_FORMAT_MACROS #include #include diff --git a/core/src/examples/simple_c.c b/core/src/examples/simple_c.c index 4b28989d4..c92870c85 100644 --- a/core/src/examples/simple_c.c +++ b/core/src/examples/simple_c.c @@ -24,7 +24,8 @@ void vpt_change_cbk(const omega_viewport_t *viewport_ptr, omega_viewport_event_t char change_kind = viewport_event_ptr ? omega_change_get_kind_as_char((const omega_change_t *) (viewport_event_ptr)) : 'R'; - fprintf(stdout, "%c: [%s]\n", change_kind, omega_viewport_get_data(viewport_ptr)); + fprintf((FILE *) (omega_viewport_get_user_data_ptr(viewport_ptr)), "%c: [%s]\n", change_kind, + omega_viewport_get_data(viewport_ptr)); break; } default: @@ -34,7 +35,7 @@ void vpt_change_cbk(const omega_viewport_t *viewport_ptr, omega_viewport_event_t int main() { omega_session_t *session_ptr = omega_edit_create_session(NULL, NULL, NULL, NO_EVENTS, NULL); - omega_edit_create_viewport(session_ptr, 0, 100, 0, vpt_change_cbk, NULL, VIEWPORT_EVT_CREATE | VIEWPORT_EVT_EDIT); + omega_edit_create_viewport(session_ptr, 0, 100, 0, vpt_change_cbk, stdout, VIEWPORT_EVT_CREATE | VIEWPORT_EVT_EDIT); omega_edit_insert(session_ptr, 0, "Hello Weird!!!!", 0); omega_edit_overwrite(session_ptr, 7, "orl", 0); omega_edit_delete(session_ptr, 11, 3); diff --git a/core/src/examples/transform.c b/core/src/examples/transform.c index 2c1af56c0..d6096407a 100644 --- a/core/src/examples/transform.c +++ b/core/src/examples/transform.c @@ -19,9 +19,13 @@ #include #include -omega_byte_t to_lower(omega_byte_t byte, void *_unused) { return (omega_byte_t) tolower(byte); } +static inline omega_byte_t to_lower(omega_byte_t byte, __attribute__((unused)) void *_unused) { + return (omega_byte_t) tolower(byte); +} -omega_byte_t to_upper(omega_byte_t byte, void *_unused) { return (omega_byte_t) toupper(byte); } +static inline omega_byte_t to_upper(omega_byte_t byte, __attribute__((unused)) void *_unused) { + return (omega_byte_t) toupper(byte); +} int main(int argc, char **argv) { if (argc != 4) { diff --git a/core/src/lib/filesystem.cpp b/core/src/lib/filesystem.cpp index c32d883eb..6e946ea5a 100644 --- a/core/src/lib/filesystem.cpp +++ b/core/src/lib/filesystem.cpp @@ -152,7 +152,7 @@ int omega_util_compare_modification_times(const char *path1, const char *path2) } const char *omega_util_get_current_dir(char *buffer) { - static char buff[FILENAME_MAX];//create string buffer to hold path + static char buff[FILENAME_MAX]{};//create string buffer to hold path if (!buffer) { buffer = buff; } auto const path_str = fs::current_path().string(); assert(0 < path_str.length()); @@ -165,7 +165,7 @@ const char *omega_util_get_current_dir(char *buffer) { char *omega_util_dirname(char const *path, char *buffer) { assert(path); - static char buff[FILENAME_MAX];//create string buffer to hold path + static char buff[FILENAME_MAX]{};//create string buffer to hold path if (!buffer) { buffer = buff; } auto const dirname_str = fs::path(path).parent_path().string(); assert(0 <= dirname_str.length()); @@ -180,7 +180,7 @@ char *omega_util_basename(char const *path, char *buffer, int drop_suffix) { assert(path); assert(0 < strlen(path)); assert(FILENAME_MAX > strlen(path)); - static char buff[FILENAME_MAX];//create string buffer to hold path + static char buff[FILENAME_MAX]{};//create string buffer to hold path if (!buffer) { buffer = buff; } auto const basename_str = (drop_suffix == 0) ? fs::path(path).filename().string() : fs::path(path).stem().string(); auto const len = basename_str.copy(buffer, basename_str.length()); @@ -191,7 +191,7 @@ char *omega_util_basename(char const *path, char *buffer, int drop_suffix) { char *omega_util_file_extension(char const *path, char *buffer) { assert(path); - static char buff[FILENAME_MAX];//create string buffer to hold path + static char buff[FILENAME_MAX]{};//create string buffer to hold path if (!buffer) { buffer = buff; } auto const path_str = fs::path(path).extension().string(); assert(0 <= path_str.length()); @@ -217,7 +217,7 @@ char *omega_util_normalize_path(char const *path, char *buffer) { char *omega_util_available_filename(char const *path, char *buffer) { assert(path); - static char buff[FILENAME_MAX];//create string buffer to hold path + static char buff[FILENAME_MAX]{};//create string buffer to hold path if (!buffer) { buffer = buff; } if (!omega_util_file_exists(path)) { memcpy(buffer, path, strlen(path) + 1); diff --git a/core/src/lib/impl_/model_segment_def.hpp b/core/src/lib/impl_/model_segment_def.hpp index 512e3c2a4..0a4914492 100644 --- a/core/src/lib/impl_/model_segment_def.hpp +++ b/core/src/lib/impl_/model_segment_def.hpp @@ -22,6 +22,7 @@ enum class model_segment_kind_t { SEGMENT_READ, SEGMENT_INSERT }; +// NOTE: omega_model_segment_struct is used in internal_fwd_defs.hpp despite what sonarlint says struct omega_model_segment_struct { int64_t computed_offset{}; ///< Computed offset can differ from the change as segments move and split int64_t computed_length{}; ///< Computed length can differ from the change as segments split diff --git a/core/src/lib/utility.c b/core/src/lib/utility.c index 71f554726..9a34d8c58 100644 --- a/core/src/lib/utility.c +++ b/core/src/lib/utility.c @@ -32,10 +32,8 @@ #define getpid _getpid #else -#include #include #include -#include #ifndef O_BINARY #define O_BINARY (0) @@ -47,10 +45,8 @@ #include "impl_/macros.h" #include #include -#include #include #include -#include int omega_util_compute_mode(int mode) { diff --git a/core/src/tests/omega_test.cpp b/core/src/tests/omega_test.cpp index 3eb3fc08a..b00cab0fe 100644 --- a/core/src/tests/omega_test.cpp +++ b/core/src/tests/omega_test.cpp @@ -39,7 +39,7 @@ using Catch::Matchers::EndsWith; using Catch::Matchers::Equals; const auto DATA_DIR = std::filesystem::current_path() / "data"; -#define MAKE_PATH(path) (DATA_DIR / path).string().c_str() +#define MAKE_PATH(path) (DATA_DIR / (path)).string().c_str() /** * Sleep for the given number of seconds. @@ -95,7 +95,7 @@ TEST_CASE("Buffer Shift", "[BufferShift]") { REQUIRE_THAT(fill + 1, Equals((const char *) buffer)); // Reset the buffer - memcpy(buffer, fill, buff_len); + strcpy((char *)buffer, fill); REQUIRE_THAT(fill, Equals((const char *) buffer)); // Shift the buffer 6 bits to the left