From d3fbdee1c613db0061b4b076e8925bae57beb639 Mon Sep 17 00:00:00 2001 From: Scott Balneaves Date: Thu, 23 Mar 2017 09:17:24 -0500 Subject: Fix for crasher in Command applet. Closes https://github.com/mate-desktop/mate-applets/issues/235 --- command/command.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'command') diff --git a/command/command.c b/command/command.c index 0b1a4c91..601746ba 100644 --- a/command/command.c +++ b/command/command.c @@ -23,6 +23,7 @@ */ #include +#include #include #include @@ -253,7 +254,7 @@ process_command_output (CommandApplet *command_applet, gchar *output) { gtk_widget_set_tooltip_text (GTK_WIDGET (command_applet->label), command_applet->command); - if ((output == NULL) || (output[0] == 0)) + if ((output == NULL) || (output[0] == '\0')) { gtk_label_set_text (command_applet->label, ERROR_OUTPUT); return; @@ -287,20 +288,13 @@ process_command_output (CommandApplet *command_applet, gchar *output) } else { - /* check output length */ - if (strlen(output) > command_applet->width) - { - GString *strip_output; - strip_output = g_string_new_len (output, command_applet->width); - g_free (output); - output = strip_output->str; - g_string_free (strip_output, FALSE); - } + /* Remove leading and trailing whitespace */ + g_strstrip (output); - /* remove last char if it is '\n' to avoid alignment problems */ - if (g_str_has_suffix (output, "\n")) + /* check output length */ + if (strlen (output) > command_applet->width) { - output[strlen(output) - 1] = 0; + output[command_applet->width] = '\0'; } gtk_label_set_text (command_applet->label, output); -- cgit v1.2.1