summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Balneaves <[email protected]>2017-03-23 09:17:24 -0500
committerScott Balneaves <[email protected]>2017-03-23 09:17:24 -0500
commitd3fbdee1c613db0061b4b076e8925bae57beb639 (patch)
treeddbe75cb98733a0a8653ce585447de782d8971b5
parentea04f0ac6cfbfd330c48da39186696dc5226b9ab (diff)
downloadmate-applets-d3fbdee1c613db0061b4b076e8925bae57beb639.tar.bz2
mate-applets-d3fbdee1c613db0061b4b076e8925bae57beb639.tar.xz
Fix for crasher in Command applet. Closes https://github.com/mate-desktop/mate-applets/issues/235
-rw-r--r--command/command.c20
1 files changed, 7 insertions, 13 deletions
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 <config.h>
+#include <string.h>
#include <glib.h>
#include <glib/gi18n.h>
@@ -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);