diff --git a/src/process_pipeline.c b/src/process_pipeline.c index 50a6334..a913129 100644 --- a/src/process_pipeline.c +++ b/src/process_pipeline.c @@ -1262,21 +1262,27 @@ static void post_process_finished(GSubprocess *proc, GAsyncResult *res, GdkTexture *thumb) { char *stdout; + char *path; g_subprocess_communicate_utf8_finish(proc, res, &stdout, NULL, NULL); // The last line contains the file name int end = strlen(stdout); - // Skip the newline at the end - stdout[--end] = '\0'; - char *path = path = stdout + end - 1; - do { - if (*path == '\n') { - path++; - break; - } - --path; - } while (path > stdout); + if (end > 0) { + // Skip the newline at the end + stdout[--end] = '\0'; + + path = stdout + end - 1; + do { + if (*path == '\n') { + path++; + break; + } + --path; + } while (path > stdout); + } else { + path = stdout; + } mp_main_capture_completed(thumb, path); }