Branch: refs/heads/master Author: Dimitar Zhekov dimitar.zhekov@gmail.com Committer: Dimitar Zhekov dimitar.zhekov@gmail.com Date: Sat, 28 Mar 2015 11:13:27 UTC Commit: 44dc8a1c2e850bd0c370bd2ddafc2ed5702c360a https://github.com/geany/geany/commit/44dc8a1c2e850bd0c370bd2ddafc2ed5702c36...
Log Message: ----------- Fix a small leak and the checks for output/errors from the child
In particular, if the child is executed successfully, and did not emit anything to stderr, an empty output is considered valid. The original tried to check, and leave the selection unchanged on empty output, but it did not always work.
Modified Paths: -------------- src/tools.c
Modified: src/tools.c 10 lines changed, 6 insertions(+), 4 deletions(-) =================================================================== @@ -205,8 +205,8 @@ void tools_execute_custom_command(GeanyDocument *doc, const gchar *command) GError *error = NULL; gchar *sel; SpawnWriteData input; - GString *output = g_string_sized_new(256); - GString *errors = g_string_new(NULL); + GString *output; + GString *errors; gint status;
g_return_if_fail(doc != NULL && command != NULL); @@ -217,11 +217,13 @@ void tools_execute_custom_command(GeanyDocument *doc, const gchar *command) sel = sci_get_selection_contents(doc->editor->sci); input.ptr = sel; input.size = strlen(sel); + output = g_string_sized_new(256); + errors = g_string_new(NULL); ui_set_statusbar(TRUE, _("Passing data and executing custom command: %s"), command);
if (spawn_sync(NULL, command, NULL, NULL, &input, output, errors, &status, &error)) { - if (*errors->str) + if (errors->len > 0) { g_warning("%s: %s\n", command, errors->str); ui_set_statusbar(TRUE, @@ -235,7 +237,7 @@ void tools_execute_custom_command(GeanyDocument *doc, const gchar *command) ui_set_statusbar(TRUE, _("The executed custom command exited with an unsuccessful exit code.")); } - else if (output) + else { /* Command completed successfully */ sci_replace_sel(doc->editor->sci, output->str); }
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).