Skip to content

Commit

Permalink
Add some sanity checks
Browse files Browse the repository at this point in the history
  • Loading branch information
techee committed May 21, 2024
1 parent cf1c68e commit 4e6be72
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 22 deletions.
3 changes: 3 additions & 0 deletions lsp/src/lsp-autocomplete.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ static void process_response(LspServer *server, GVariant *response, GeanyDocumen
//"isIncomplete", JSONRPC_MESSAGE_GET_BOOLEAN(&is_incomplete),
"items", JSONRPC_MESSAGE_GET_ITER(&iter));

if (!iter)
return;

symbols = g_ptr_array_new_full(0, NULL); // not freeing symbols here

while (g_variant_iter_loop(iter, "v", &member))
Expand Down
10 changes: 6 additions & 4 deletions lsp/src/lsp-rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,14 @@ static gboolean handle_call(JsonrpcClient *client, gchar* method, GVariant *id,
else if (g_strcmp0(method, "workspace/applyEdit") == 0)
{
GVariant *edit, *msg;
gboolean success = FALSE;
gboolean success;

JSONRPC_MESSAGE_PARSE(params,
success = JSONRPC_MESSAGE_PARSE(params,
"edit", JSONRPC_MESSAGE_GET_VARIANT(&edit)
);

success = lsp_utils_apply_workspace_edit(edit);
if (success)
success = lsp_utils_apply_workspace_edit(edit);

msg = JSONRPC_MESSAGE_NEW(
"applied", JSONRPC_MESSAGE_PUT_BOOLEAN(success)
Expand All @@ -182,7 +183,8 @@ static gboolean handle_call(JsonrpcClient *client, gchar* method, GVariant *id,
jsonrpc_client_reply_async(client, id, msg, NULL, NULL, NULL);

g_variant_unref(msg);
g_variant_unref(edit);
if (edit)
g_variant_unref(edit);
ret = TRUE;
}

Expand Down
40 changes: 24 additions & 16 deletions lsp/src/lsp-semtokens.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,10 @@ static void process_full_result(GeanyDocument *doc, GVariant *result, guint64 to

g_free(data->tokens_str);
data->tokens_str = process_tokens(data->tokens, doc, token_mask);
}

if (iter)
g_variant_iter_free(iter);
}
}


Expand All @@ -305,6 +306,7 @@ static gboolean process_delta_result(GeanyDocument *doc, GVariant *result, guint
GVariantIter *iter = NULL;
const gchar *result_id = NULL;
CachedData *data = NULL;
gboolean ret = FALSE;

JSONRPC_MESSAGE_PARSE(result,
"resultId", JSONRPC_MESSAGE_GET_STRING(&result_id),
Expand Down Expand Up @@ -333,27 +335,31 @@ static gboolean process_delta_result(GeanyDocument *doc, GVariant *result, guint
GVariant *val2 = NULL;
gint64 delete_count = 0;
gint64 start = 0;
gboolean success;

edit = sem_tokens_edit_new();

JSONRPC_MESSAGE_PARSE(val,
success = JSONRPC_MESSAGE_PARSE(val,
"start", JSONRPC_MESSAGE_GET_INT64(&start),
"deleteCount", JSONRPC_MESSAGE_GET_INT64(&delete_count),
"data", JSONRPC_MESSAGE_GET_ITER(&iter2)
);

edit->start = start;
edit->delete_count = delete_count;

while (g_variant_iter_loop(iter2, "v", &val2))
if (success)
{
guint v = g_variant_get_int64(val2);
g_array_append_val(edit->data, v);
}
edit = sem_tokens_edit_new();
edit->start = start;
edit->delete_count = delete_count;

g_ptr_array_add(edits, edit);
while (g_variant_iter_loop(iter2, "v", &val2))
{
guint v = g_variant_get_int64(val2);
g_array_append_val(edit->data, v);
}

g_variant_iter_free(iter2);
g_ptr_array_add(edits, edit);
}

if (iter2)
g_variant_iter_free(iter2);
}

g_ptr_array_sort(edits, sort_edits);
Expand All @@ -367,12 +373,14 @@ static gboolean process_delta_result(GeanyDocument *doc, GVariant *result, guint
data->result_id = g_strdup(result_id);

g_ptr_array_free(edits, TRUE);
g_variant_iter_free(iter);

return TRUE;
ret = TRUE;
}

return FALSE;
if (iter)
g_variant_iter_free(iter);

return ret;
}


Expand Down
3 changes: 2 additions & 1 deletion lsp/src/lsp-signature.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ static void signature_cb(GVariant *return_value, GError *error, gpointer user_da
else
show_signature(current_doc->editor->sci);

g_variant_iter_free(iter);
if (iter)
g_variant_iter_free(iter);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lsp/src/lsp-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,8 @@ void lsp_utils_free_lsp_location(LspLocation *e)
LspLocation *lsp_utils_parse_location(GVariant *variant)
{
LspLocation *ret = NULL;
GVariant *range = NULL;
const gchar *uri;
GVariant *range;

gboolean success = JSONRPC_MESSAGE_PARSE(variant,
"uri", JSONRPC_MESSAGE_GET_STRING(&uri),
Expand Down

0 comments on commit 4e6be72

Please sign in to comment.