diff --git a/src/calc.c b/src/calc.c index 952def2..0ab05b7 100644 --- a/src/calc.c +++ b/src/calc.c @@ -539,9 +539,10 @@ static void process_cb(GObject* source_object, GAsyncResult* res, gpointer user_ error = NULL; } + gsize bytes_read = 0; unsigned int stdout_bufsize = 4096; char stdout_buf[stdout_bufsize]; - g_input_stream_read_all(stdout_stream, stdout_buf, stdout_bufsize, NULL, NULL, &error); + g_input_stream_read_all(stdout_stream, stdout_buf, stdout_bufsize, &bytes_read, NULL, &error); if (error != NULL) { g_error("Process errored with: %s", error->message); @@ -549,8 +550,7 @@ static void process_cb(GObject* source_object, GAsyncResult* res, gpointer user_ error = NULL; } - unsigned int line_length = strcspn(stdout_buf, "\n"); - *last_result = g_strndup(stdout_buf, line_length); + *last_result = g_strndup(stdout_buf, bytes_read - 1); g_input_stream_close(stdout_stream, NULL, &error); if (error != NULL) {