Skip to content

Commit

Permalink
avoid crashing on bad input with qalc >= 5.0.0
Browse files Browse the repository at this point in the history
Since version 5.0.0, qalc exits with code 1 when the input is invalid.
Reporting such a common problem (inevitable while typing) with g_error
is undesired, as calling g_error is fatal, and even if it weren't, this
would only lead to useless spamming of the standard error.

This commit also fixes related use-after-free in the same function.
  • Loading branch information
tiosgz authored and svenstaro committed Mar 28, 2024
1 parent 12fe2d5 commit cc6cd37
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/calc.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,12 @@ static void process_cb(GObject* source_object, GAsyncResult* res, gpointer user_
g_subprocess_wait_check_finish(process, res, &error);

if (error != NULL) {
g_error("Process errored with: %s", error->message);
// With qalculate >= 5.0.0, exit status 1 can mean bad (or incomplete) input
if (error->domain != G_SPAWN_EXIT_ERROR || error-> code != 1) {
g_error("Process errored with: %s", error->message);
}
g_error_free(error);
error = NULL;
}

unsigned int stdout_bufsize = 4096;
Expand All @@ -542,6 +546,7 @@ static void process_cb(GObject* source_object, GAsyncResult* res, gpointer user_
if (error != NULL) {
g_error("Process errored with: %s", error->message);
g_error_free(error);
error = NULL;
}

unsigned int line_length = strcspn(stdout_buf, "\n");
Expand All @@ -551,6 +556,7 @@ static void process_cb(GObject* source_object, GAsyncResult* res, gpointer user_
if (error != NULL) {
g_error("Process errored with: %s", error->message);
g_error_free(error);
error = NULL;
}

rofi_view_reload();
Expand Down

0 comments on commit cc6cd37

Please sign in to comment.