[Xfce4-commits] [apps/xfce4-terminal] 01/01: Safer usage of strncmp() function

noreply at xfce.org noreply at xfce.org
Tue Jul 19 16:20:36 CEST 2016


This is an automated email from the git hooks/post-receive script.

f2404 pushed a commit to branch master
in repository apps/xfce4-terminal.

commit 4d1675746671642f6d0efa59953d6828953ea535
Author: Igor <f2404 at yandex.ru>
Date:   Tue Jul 19 17:20:28 2016 +0300

    Safer usage of strncmp() function
---
 terminal/terminal-options.c |  5 +++--
 terminal/terminal-screen.c  |  8 ++++----
 terminal/terminal-widget.c  | 20 +++++++++-----------
 3 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/terminal/terminal-options.c b/terminal/terminal-options.c
index 68b4ffa..8c70970 100644
--- a/terminal/terminal-options.c
+++ b/terminal/terminal-options.c
@@ -104,12 +104,13 @@ terminal_option_show_hide_cmp (const gchar         *long_name,
                                TerminalVisibility  *return_visibility)
 {
   gchar *arg = argv[*argv_offset];
+  const size_t pref_len = strlen ("--show-");
 
   terminal_return_val_if_fail (long_name != NULL, FALSE);
   terminal_return_val_if_fail (return_visibility != NULL, FALSE);
 
-  if ((strncmp (arg, "--show-", 7) == 0 || strncmp (arg, "--hide-", 7) == 0)
-      && strcmp (arg + 7, long_name) == 0)
+  if ((strncmp (arg, "--show-", pref_len) == 0 || strncmp (arg, "--hide-", pref_len) == 0)
+      && strcmp (arg + pref_len, long_name) == 0)
     {
       if (*(arg + 2) == 's')
         *return_visibility = TERMINAL_VISIBILITY_SHOW;
diff --git a/terminal/terminal-screen.c b/terminal/terminal-screen.c
index db9ef69..93db784 100644
--- a/terminal/terminal-screen.c
+++ b/terminal/terminal-screen.c
@@ -485,15 +485,15 @@ terminal_screen_preferences_changed (TerminalPreferences *preferences,
   name = g_param_spec_get_name (pspec);
   terminal_assert (name != NULL);
 
-  if (strncmp ("background-", name, 11) == 0)
+  if (strncmp ("background-", name, strlen ("background-")) == 0)
     terminal_screen_update_background (screen);
   else if (strcmp ("binding-backspace", name) == 0)
     terminal_screen_update_binding_backspace (screen);
   else if (strcmp ("binding-delete", name) == 0)
     terminal_screen_update_binding_delete (screen);
-  else if (strncmp ("color-", name, 6) == 0)
+  else if (strncmp ("color-", name, strlen ("color-")) == 0)
     terminal_screen_update_colors (screen);
-  else if (strncmp ("font-", name, 5) == 0)
+  else if (strncmp ("font-", name, strlen ("font-")) == 0)
     terminal_screen_update_font (screen);
   else if (strcmp ("misc-bell", name) == 0)
     terminal_screen_update_misc_bell (screen);
@@ -511,7 +511,7 @@ terminal_screen_preferences_changed (TerminalPreferences *preferences,
     terminal_screen_update_scrolling_on_output (screen);
   else if (strcmp ("scrolling-on-keystroke", name) == 0)
     terminal_screen_update_scrolling_on_keystroke (screen);
-  else if (strncmp ("title-", name, 6) == 0)
+  else if (strncmp ("title-", name, strlen ("title-")) == 0)
     terminal_screen_update_title (screen);
   else if (strcmp ("word-chars", name) == 0)
     terminal_screen_update_word_chars (screen);
diff --git a/terminal/terminal-widget.c b/terminal/terminal-widget.c
index 5645d49..13a6678 100644
--- a/terminal/terminal-widget.c
+++ b/terminal/terminal-widget.c
@@ -39,6 +39,7 @@
 
 
 
+#define MAILTO          "mailto:"
 #define USERCHARS       "-[:alnum:]\\Q_.+\\E"
 #define USERCHARS_CLASS "[" USERCHARS "]"
 #define PASSCHARS_CLASS "[-[:alnum:]\\Q,?;.:/!%$^*&~\"#'\\E]"
@@ -80,7 +81,7 @@ static const TerminalRegexPattern regex_patterns[] =
 {
   { SCHEME "//(?:" USERPASS "\\@)?" HOST PORT URLPATH, PATTERN_TYPE_FULL_HTTP },
   { "(?:www[[:digit:]]{0,3}|ftp)" HOSTCHARS_CLASS "*\\." HOST PORT URLPATH, PATTERN_TYPE_HTTP },
-  { "(?:mailto:)?" USERCHARS_CLASS "[" USERCHARS ".]*\\@" HOSTCHARS_CLASS "+\\." HOST, PATTERN_TYPE_EMAIL },
+  { "(?:" MAILTO ")?" USERCHARS_CLASS "[" USERCHARS ".]*\\@" HOSTCHARS_CLASS "+\\." HOST, PATTERN_TYPE_EMAIL },
   { "news:[[:alnum:]\\Q^_{|}~!\"#$%&'()*+,./;:=?`\\E]+", PATTERN_TYPE_FULL_HTTP }
 };
 
@@ -233,9 +234,9 @@ terminal_widget_context_menu_copy (TerminalWidget *widget,
       display = gtk_widget_get_display (GTK_WIDGET (widget));
 
       /* strip mailto from links, bug #7909 */
-      if (g_str_has_prefix (wlink, "mailto:"))
+      if (g_str_has_prefix (wlink, MAILTO))
         {
-          modified_wlink = g_strdup (wlink + 7);
+          modified_wlink = g_strdup (wlink + strlen (MAILTO));
           wlink = modified_wlink;
         }
 
@@ -680,14 +681,15 @@ terminal_widget_open_uri (TerminalWidget *widget,
             break;
 
           case PATTERN_TYPE_EMAIL:
-            if (strncmp (wlink, "mailto:", 7) == 0)
+            if (strncmp (wlink, MAILTO, strlen (MAILTO)) == 0)
               uri = g_strdup (wlink);
             else
-              uri = g_strconcat ("mailto:", wlink, NULL);
+              uri = g_strconcat (MAILTO, wlink, NULL);
             break;
 
           default:
-            goto invalid_tag;
+            g_warning ("Invalid tag specified while trying to open link \"%s\".", wlink);
+            return;
         }
 
       /* try to open the URI with the responsible application */
@@ -696,7 +698,7 @@ terminal_widget_open_uri (TerminalWidget *widget,
         {
           /* tell the user that we were unable to open the responsible application */
           xfce_dialog_show_error (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (widget))),
-                                  error, _("Failed to open the URL `%s'"), uri);
+                                  error, _("Failed to open the URL '%s'"), uri);
           g_error_free (error);
         }
 
@@ -705,10 +707,6 @@ terminal_widget_open_uri (TerminalWidget *widget,
       /* done */
       return;
     }
-
-invalid_tag:
-
-  g_warning ("Invalid tag specified while trying to open link \"%s\".", wlink);
 }
 
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list