summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autocomplete.c2
-rw-r--r--ds.c1
-rw-r--r--gl.c5
-rw-r--r--json.c2
-rw-r--r--lsp-parse.c4
-rw-r--r--lsp.c14
-rw-r--r--util.c13
7 files changed, 29 insertions, 12 deletions
diff --git a/autocomplete.c b/autocomplete.c
index 1d03c75..f1c3c13 100644
--- a/autocomplete.c
+++ b/autocomplete.c
@@ -332,6 +332,8 @@ static char symbol_kind_icon(SymbolKind k) {
case SYMBOL_OTHER:
return ' ';
}
+ assert(0);
+ return ' ';
}
static void autocomplete_frame(Ted *ted) {
diff --git a/ds.c b/ds.c
index eb235d6..99ad4d3 100644
--- a/ds.c
+++ b/ds.c
@@ -169,7 +169,6 @@ static void *arr_remove_(void *arr, size_t member_size, size_t index) {
#define arr__join2(a,b) a##b
#define arr__join(a,b) arr__join2(a,b) // macro used internally
-
// if the array is not NULL, free it and set it to NULL
#define arr_free(a) do { if (a) { free(arr_hdr_(a)); (a) = NULL; } } while (0)
// a nice alias
diff --git a/gl.c b/gl.c
index 31cbe96..2cf6a43 100644
--- a/gl.c
+++ b/gl.c
@@ -161,10 +161,11 @@ static GLuint gl_compile_shader(char error_buf[256], char const *code, GLenum sh
if (status == GL_FALSE) {
char log[1024] = {0};
glGetShaderInfoLog(shader, sizeof log - 1, NULL, log);
- if (error_buf)
+ if (error_buf) {
str_printf(error_buf, 256, "Error compiling shader: %s", log);
- else
+ } else {
debug_println("Error compiling shader: %s", log);
+ }
return 0;
}
return shader;
diff --git a/json.c b/json.c
index da52efa..242eb1f 100644
--- a/json.c
+++ b/json.c
@@ -78,6 +78,8 @@ const char *json_type_to_str(JSONValueType type) {
case JSON_OBJECT:
return "object";
}
+ assert(0);
+ return "???";
}
static bool json_parse_value(JSON *json, u32 *p_index, JSONValue *val);
diff --git a/lsp-parse.c b/lsp-parse.c
index 4b05f29..07837b5 100644
--- a/lsp-parse.c
+++ b/lsp-parse.c
@@ -208,7 +208,7 @@ static bool parse_completion(LSP *lsp, const JSON *json, LSPResponse *response)
item->text_edit = (LSPTextEdit) {
.type = LSP_TEXT_EDIT_PLAIN,
.at_cursor = true,
- .range = {0},
+ .range = {{0}},
.new_text = item->label
};
@@ -611,7 +611,7 @@ static void process_message(LSP *lsp, JSON *json) {
LSPRequest initialized = {
.type = LSP_REQUEST_INITIALIZED,
- .data = {0},
+ .data = {{0}},
};
write_request(lsp, &initialized);
// we can now send requests which have nothing to do with initialization
diff --git a/lsp.c b/lsp.c
index 678c638..50947ce 100644
--- a/lsp.c
+++ b/lsp.c
@@ -253,7 +253,17 @@ static bool lsp_send(LSP *lsp) {
size_t n_messages = arr_len(lsp->messages_client2server);
messages = calloc(n_messages, sizeof *messages);
memcpy(messages, lsp->messages_client2server, n_messages * sizeof *messages);
+
+ #if __GNUC__ && !__clang__
+ #pragma GCC diagnostic push
+ // i don't know why GCC is giving me this. some compiler bug.
+ #pragma GCC diagnostic ignored "-Wfree-nonheap-object"
+ #endif
arr_clear(lsp->messages_client2server);
+ #if __GNUC__ && !__clang__
+ #pragma GCC diagnostic pop
+ #endif
+
SDL_UnlockMutex(lsp->messages_mutex);
bool quit = false;
@@ -291,11 +301,11 @@ static int lsp_communication_thread(void *data) {
if (lsp->initialized) {
LSPRequest shutdown = {
.type = LSP_REQUEST_SHUTDOWN,
- .data = {0}
+ .data = {{0}}
};
LSPRequest exit = {
.type = LSP_REQUEST_EXIT,
- .data = {0}
+ .data = {{0}}
};
write_request(lsp, &shutdown);
// i give you ONE MILLISECOND to send your fucking shutdown response
diff --git a/util.c b/util.c
index 93a7f2c..3962069 100644
--- a/util.c
+++ b/util.c
@@ -119,11 +119,14 @@ static bool streq(char const *a, char const *b) {
}
static size_t strn_len(const char *src, size_t n) {
- const char *p = memchr(src, '\0', n);
- if (p)
- return (size_t)(p - src);
- else
- return n;
+ const char *p = src;
+ // in C99 and C++11/14, calling memchr with a size larger than
+ // the size of the object is undefined behaviour.
+ // i don't think there's any way of doing this (efficiently) with standard C functions.
+ for (size_t i = 0 ; i < n; ++i, ++p)
+ if (*p == '\0')
+ break;
+ return (size_t)(p - src);
}
// duplicates at most n characters from src