summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2024-06-10 06:30:38 +0200
committerMitya Selivanov <automainint@guattari.tech>2024-06-10 06:30:38 +0200
commita505fe156ba508d200731bc0e8f54d87dc7c4a8c (patch)
tree20baafd2a668782c5b8b746bb429506b2dec0a68
parent01a97804ad06fc38800ec5520c715f4f6af3892c (diff)
downloadkit-a505fe156ba508d200731bc0e8f54d87dc7c4a8c.zip
Cleanup
-rwxr-xr-xbuild.c4
-rw-r--r--source/kit/async_function.h8
-rw-r--r--source/kit/bigint.h30
-rw-r--r--source/kit/http1.h8
-rw-r--r--source/kit/process.posix.c4
-rw-r--r--source/kit/test.h19
-rw-r--r--source/kit/xml.c2
-rw-r--r--source/tests/array_ref.test.c10
-rw-r--r--source/tests/secure_random.test.c6
-rw-r--r--source/tests/test_interprocess.c16
10 files changed, 69 insertions, 38 deletions
diff --git a/build.c b/build.c
index ea04495..3c1cf79 100755
--- a/build.c
+++ b/build.c
@@ -341,9 +341,9 @@ i32 main(i32 argc, c8 **argv) {
if (str_eq_lower(build_type, "release"))
flags = "-O3 -DNDEBUG";
else if (OS != WINDOWS && str_eq(compiler_c, "gcc") && !STATIC_RUNTIME)
- flags = "-O0 -fsanitize=undefined,address,leak";
+ flags = "-Wall -Wextra -Wno-missing-field-initializers -Werror -pedantic -O0 -fsanitize=undefined,address,leak -mshstk";
else
- flags = "-O0";
+ flags = "-Wall -Wextra -Wno-missing-field-initializers -Werror -pedantic -O0";
}
if (OS == WINDOWS) {
diff --git a/source/kit/async_function.h b/source/kit/async_function.h
index 70a81cd..5460fd6 100644
--- a/source/kit/async_function.h
+++ b/source/kit/async_function.h
@@ -5,6 +5,12 @@
#include <string.h>
+#ifdef __GNUC__
+#define KIT_FALLTHROUGH __attribute__((fallthrough));
+#else
+#define KIT_FALLTHROUGH
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -133,6 +139,7 @@ static void kit_async_function_dispatch(void *promise) {
#define KIT_AF_AWAIT(promise_) \
do { \
+ KIT_FALLTHROUGH \
case KIT_AF_LINE_(): \
if ((promise_)._index != -1) { \
self->_index = KIT_AF_LINE_(); \
@@ -144,6 +151,7 @@ static void kit_async_function_dispatch(void *promise) {
#define KIT_AF_YIELD_AWAIT(promise_) \
do { \
+ KIT_FALLTHROUGH \
case KIT_AF_LINE_(): \
if ((promise_)._index != -1) { \
self->_index = KIT_AF_LINE_(); \
diff --git a/source/kit/bigint.h b/source/kit/bigint.h
index 159996a..41d19e6 100644
--- a/source/kit/bigint.h
+++ b/source/kit/bigint.h
@@ -190,7 +190,7 @@ static kit_bigint_t kit_bi_shr_uint(kit_bigint_t x, u32 y) {
return z;
}
-static i8 kit_bi_carry(u32 x, u32 y, i8 carry) {
+static i8 kit_bi_carry(u32 x, u32 y, u8 carry) {
assert(carry == 0 || carry == 1);
return 0xffffffffu - x < y || 0xffffffffu - x - y < carry ? 1 : 0;
}
@@ -199,7 +199,7 @@ static i8 kit_bi_carry(u32 x, u32 y, i8 carry) {
*/
static kit_bigint_t kit_bi_inc(kit_bigint_t x) {
kit_bigint_t z;
- i8 carry = 1;
+ u8 carry = 1;
i64 i;
for (i = 0; i < KIT_BIGINT_SIZE / 4; i++) {
@@ -214,7 +214,7 @@ static kit_bigint_t kit_bi_inc(kit_bigint_t x) {
*/
static kit_bigint_t kit_bi_dec(kit_bigint_t x) {
kit_bigint_t z;
- i8 carry = 0;
+ u8 carry = 0;
i64 i;
for (i = 0; i < KIT_BIGINT_SIZE / 4; i++) {
@@ -229,7 +229,7 @@ static kit_bigint_t kit_bi_dec(kit_bigint_t x) {
*/
static kit_bigint_t kit_bi_add(kit_bigint_t x, kit_bigint_t y) {
kit_bigint_t z;
- i8 carry = 0;
+ u8 carry = 0;
i64 i;
for (i = 0; i < KIT_BIGINT_SIZE / 4; i++) {
@@ -244,7 +244,7 @@ static kit_bigint_t kit_bi_add(kit_bigint_t x, kit_bigint_t y) {
*/
static kit_bigint_t kit_bi_neg(kit_bigint_t x) {
kit_bigint_t y;
- i8 carry = 1;
+ u8 carry = 1;
i64 i;
for (i = 0; i < KIT_BIGINT_SIZE / 4; i++) {
@@ -259,7 +259,7 @@ static kit_bigint_t kit_bi_neg(kit_bigint_t x) {
*/
static kit_bigint_t kit_bi_sub(kit_bigint_t x, kit_bigint_t y) {
kit_bigint_t z;
- i8 carry = 1;
+ u8 carry = 1;
i64 i;
for (i = 0; i < KIT_BIGINT_SIZE / 4; i++) {
@@ -414,7 +414,7 @@ static kit_bigint_t kit_bi_deserialize(u8 *in) {
return out;
}
-static u8 kit_bin_digit(char hex) {
+static u8 kit_bin_digit(c8 hex) {
assert(hex == '0' || hex == '1');
return hex == '1' ? 1 : 0;
}
@@ -433,7 +433,7 @@ static kit_bigint_t kit_bi_from_bin(kit_str_t bin) {
return z;
}
-static u8 kit_dec_digit(char c) {
+static u8 kit_dec_digit(c8 c) {
assert('c' >= '0' && c <= '9');
return c >= '0' && c <= '9' ? (u8) (c - '0') : 0;
}
@@ -452,7 +452,7 @@ static kit_bigint_t kit_bi_from_dec(kit_str_t dec) {
return z;
}
-static u8 kit_hex_digit(char hex) {
+static u8 kit_hex_digit(c8 hex) {
assert((hex >= '0' && hex <= '9') || (hex >= 'a' && hex <= 'f') ||
(hex >= 'A' && hex <= 'F'));
@@ -490,11 +490,11 @@ static u8 KIT_BASE32_DIGITS[] = {
['y'] = 30, ['z'] = 31
};
-static u8 kit_base32_digit(char c) {
- assert(c >= '\0' && c < sizeof KIT_BASE32_DIGITS);
+static u8 kit_base32_digit(c8 c) {
+ assert(c >= '\0' && c < (c8) sizeof KIT_BASE32_DIGITS);
assert(c == '1' || KIT_BASE32_DIGITS[(size_t) (u8) c] != 0);
- return c >= '\0' && c < sizeof KIT_BASE32_DIGITS
+ return c >= '\0' && c < (c8) sizeof KIT_BASE32_DIGITS
? KIT_BASE32_DIGITS[(size_t) (u8) c]
: 0;
}
@@ -528,11 +528,11 @@ static u8 KIT_BASE58_DIGITS[] = {
['x'] = 55, ['y'] = 56, ['z'] = 57
};
-static u8 kit_base58_digit(char c) {
- assert(c >= '\0' && c < sizeof KIT_BASE58_DIGITS);
+static u8 kit_base58_digit(c8 c) {
+ assert(c >= '\0' && c < (c8) sizeof KIT_BASE58_DIGITS);
assert(c == '1' || KIT_BASE58_DIGITS[(size_t) (u8) c] != 0);
- return c >= '\0' && c < sizeof KIT_BASE58_DIGITS
+ return c >= '\0' && c < (c8) sizeof KIT_BASE58_DIGITS
? KIT_BASE58_DIGITS[(size_t) (u8) c]
: 0;
}
diff --git a/source/kit/http1.h b/source/kit/http1.h
index 98190ea..0a58f96 100644
--- a/source/kit/http1.h
+++ b/source/kit/http1.h
@@ -211,8 +211,8 @@ static kit_str_t kit_http1_method_to_str(i32 method) {
{ .size = 5, .values = "TRACE" },
{ .size = 7, .values = "CONNECT" } };
- assert(method >= 0 && method < sizeof methods / sizeof *methods);
- if (method < 0 || method >= sizeof methods / sizeof *methods)
+ assert(method >= 0 && method < (i32) (sizeof methods / sizeof *methods));
+ if (method < 0 || method >= (i32) (sizeof methods / sizeof *methods))
return (kit_str_t) { .size = 0, .values = NULL };
return methods[method];
@@ -235,11 +235,11 @@ static socket_t kit_http1_connect_to_uri(kit_http1_uri_t *uri) {
char host_str[128];
char port_str[128];
- assert(uri->host.size < sizeof host_str);
+ assert(uri->host.size < (i64) sizeof host_str);
memcpy(host_str, uri->host.values, uri->host.size);
host_str[uri->host.size] = '\0';
- assert(uri->port.size < sizeof port_str);
+ assert(uri->port.size < (i64) sizeof port_str);
memcpy(port_str, uri->port.values, uri->port.size);
port_str[uri->port.size] = '\0';
diff --git a/source/kit/process.posix.c b/source/kit/process.posix.c
index 961f058..d9bec1f 100644
--- a/source/kit/process.posix.c
+++ b/source/kit/process.posix.c
@@ -25,6 +25,8 @@ static char **kit_init_argv_(kit_process_args_t args, u32 flags) {
if ((flags & KIT_PROCESS_NO_ARGUMENTS) != 0)
return kit_process_argv_null_;
+ (void) args;
+
return NULL;
}
@@ -35,6 +37,8 @@ static char **kit_init_envp_(kit_process_env_t env, u32 flags) {
if ((flags & KIT_PROCESS_NO_ENVIRONMENT) != 0)
return kit_process_env_null_;
+ (void) env;
+
return NULL;
}
diff --git a/source/kit/test.h b/source/kit/test.h
index 3563abc..243111e 100644
--- a/source/kit/test.h
+++ b/source/kit/test.h
@@ -46,6 +46,11 @@
#ifndef KIT_TEST_H
#define KIT_TEST_H
+#ifdef __GNUC__
+# pragma GCC diagnostic ignored "-Wunused-value"
+# pragma GCC diagnostic ignored "-Wunused-parameter"
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -267,6 +272,12 @@ int kit_run_benchmarks(int argc, char **argv);
#endif
+// ================================================================
+//
+// Implementation
+//
+// ================================================================
+
#if defined(KIT_TEST_IMPLEMENTATION) && !defined(KIT_TEST_H_IMPL)
#define KIT_TEST_H_IMPL
@@ -394,7 +405,7 @@ static void kit_test_handle_signal(int signum) {
}
static void kit_test_setup_signals() {
- for (int i = 0; i < sizeof kit_signums_ / sizeof *kit_signums_; i++)
+ for (unsigned i = 0; i < sizeof kit_signums_ / sizeof *kit_signums_; i++)
signal(kit_signums_[i], kit_test_handle_signal);
}
@@ -582,7 +593,7 @@ int kit_run_tests(int argc, char **argv) {
if (kit_tests_list.v[i].signal != 0) {
int signum = kit_tests_list.v[i].signal;
if (signum >= 0 &&
- signum < sizeof kit_signames_ / sizeof *kit_signames_ &&
+ signum < (int) (sizeof kit_signames_ / sizeof *kit_signames_) &&
kit_signames_[signum] != NULL) {
no_color || kit_print_color_(kit_light_);
printf("Signal \"%s\" (%d) for \"", kit_signames_[signum],
@@ -767,7 +778,7 @@ void kit_bench_register(char const *name, char const *file,
}
static void kit_bench_setup_signals() {
- for (int i = 0; i < sizeof kit_signums_ / sizeof *kit_signums_; i++)
+ for (unsigned i = 0; i < sizeof kit_signums_ / sizeof *kit_signums_; i++)
signal(kit_signums_[i], kit_test_handle_signal);
}
@@ -1028,7 +1039,7 @@ int kit_run_benchmarks(int argc, char **argv) {
if (bench->signal != 0) {
int signum = bench->signal;
if (signum >= 0 &&
- signum < sizeof kit_signames_ / sizeof *kit_signames_ &&
+ signum < (int) (sizeof kit_signames_ / sizeof *kit_signames_) &&
kit_signames_[signum] != NULL) {
no_color || kit_print_color_(kit_light_);
printf("Signal \"%s\" (%d) for \"", kit_signames_[signum],
diff --git a/source/kit/xml.c b/source/kit/xml.c
index f3cd18f..f61bfc1 100644
--- a/source/kit/xml.c
+++ b/source/kit/xml.c
@@ -378,6 +378,8 @@ kit_xml_text_t kit_xml_print(kit_xml_t *xml, kit_allocator_t *alloc) {
xml_text_t result;
memset(&result, 0, sizeof result);
+ (void) alloc;
+
result.status = KIT_ERROR_NOT_IMPLEMENTED;
return result;
}
diff --git a/source/tests/array_ref.test.c b/source/tests/array_ref.test.c
index 921e9fd..036e802 100644
--- a/source/tests/array_ref.test.c
+++ b/source/tests/array_ref.test.c
@@ -26,8 +26,14 @@ TEST("array ref equal") {
REQUIRE(AR_EQUAL(foo_ref, bar_ref));
}
-static int compare(int *left, int *right) {
- return *left - *right;
+static i8 compare(void *left_, void *right_) {
+ int *left = (int *) left_;
+ int *right = (int *) right_;
+ if (*left < *right)
+ return -1;
+ if (*left > *right)
+ return 1;
+ return 0;
}
TEST("array ref compare") {
diff --git a/source/tests/secure_random.test.c b/source/tests/secure_random.test.c
index 3452521..b397ff9 100644
--- a/source/tests/secure_random.test.c
+++ b/source/tests/secure_random.test.c
@@ -5,7 +5,7 @@
#include "../kit/test.h"
TEST("secure random") {
- int v[20];
+ i32 v[20];
memset(v, 0, sizeof v);
REQUIRE_EQ(secure_random(40, v), KIT_OK);
@@ -13,8 +13,8 @@ TEST("secure random") {
int repeats = 0;
- for (int i = 1; i < sizeof v / sizeof *v; i++)
- for (int j = 0; j < i; j++)
+ for (i32 i = 1; i < (i32) (sizeof v / sizeof *v); i++)
+ for (i32 j = 0; j < i; j++)
if (v[i] == v[j])
repeats++;
diff --git a/source/tests/test_interprocess.c b/source/tests/test_interprocess.c
index 7655192..027f4ae 100644
--- a/source/tests/test_interprocess.c
+++ b/source/tests/test_interprocess.c
@@ -21,7 +21,7 @@ int run_writer() {
SZ(NAME), sizeof(shared_data_t), SHARED_MEMORY_CREATE);
if (mem.status != KIT_OK) {
- printf("%s: kit_shared_memory_open failed.\n", __FUNCTION__);
+ printf("Writer: kit_shared_memory_open failed.\n");
fflush(stdout);
return 1;
}
@@ -52,7 +52,7 @@ int run_writer() {
timespec_get(&t1, TIME_UTC);
if (t1.tv_sec - t0.tv_sec > TIMEOUT) {
- printf("%s: timeout.\n", __FUNCTION__);
+ printf("Writer: Timeout.\n");
shared_memory_close(&mem);
return 1;
}
@@ -63,7 +63,7 @@ int run_writer() {
shared_unlock(&p->m);
if (shared_memory_close(&mem) != KIT_OK) {
- printf("%s: kit_shared_memory_close failed.\n", __FUNCTION__);
+ printf("Writer: kit_shared_memory_close failed.\n");
fflush(stdout);
return 1;
}
@@ -86,7 +86,7 @@ int run_reader() {
timespec_get(&t1, TIME_UTC);
if (t1.tv_sec - t0.tv_sec > TIMEOUT) {
- printf("%s: timeout.\n", __FUNCTION__);
+ printf("Reader: Timeout.\n");
return 1;
}
@@ -104,7 +104,7 @@ int run_reader() {
timespec_get(&t1, TIME_UTC);
if (t1.tv_sec - t0.tv_sec > TIMEOUT) {
- printf("%s: timeout.\n", __FUNCTION__);
+ printf("Reader: Timeout.\n");
return 1;
}
@@ -116,7 +116,7 @@ int run_reader() {
for (i32 i = 0; i < DATA_SIZE; i++)
if (p->bytes[i] != i) {
- printf("%s: wrong byte %d\n", __FUNCTION__, i);
+ printf("Reader: Wrong byte %d\n", i);
fflush(stdout);
status = 1;
}
@@ -128,7 +128,7 @@ int run_reader() {
unique_unlock(&p->m);
if (shared_memory_close(&mem) != KIT_OK) {
- printf("%s: kit_shared_memory_close failed.\n", __FUNCTION__);
+ printf("Reader: kit_shared_memory_close failed.\n");
fflush(stdout);
status = 1;
}
@@ -154,7 +154,7 @@ int main(int argc, char **argv) {
i64 sec = t1.tv_sec - t0.tv_sec;
i64 nsec = t1.tv_nsec - t0.tv_nsec;
- printf("Done in %.2lf msec\n",
+ printf("Writer: Done in %.2lf msec\n",
(sec * 1000000000 + nsec) * 0.000001);
fflush(stdout);