All pastes #151774 Raw Edit

Miscellany

public text v1 · immutable
#151774 ·published 2006-08-28 12:13 UTC
rendered paste body
--- seahorse-0.9.3.orig/libseahorse/seahorse-ssh-key.c
+++ seahorse-0.9.3/libseahorse/seahorse-ssh-key.c
@@ -374,28 +374,22 @@
 GQuark
 seahorse_ssh_key_get_cannonical_id (const gchar *id)
 {
-    static guint x = strlen (SKEY_SSH_STR);
-    gchar *p, *hex;
-    guint l, off = 0;
+    gchar *hex, *canonical_id = g_malloc0 (9);
+    gint i, off, len = strlen (id);
     GQuark ret;
 
-    hex = g_strdup_printf ("%s:%s", SKEY_SSH_STR, id);
-    
-    /* Strip out all non alpha numeric chars */
-    for(p = hex + x + 1; *p; p++) {
-        if (g_ascii_isalnum(*p))
-            p[0 - off] = p[0];
-        else
-            off++;
+    g_assert (len >= 8);
+
+    /* Strip out all non alpha numeric chars and limit length to 8 */
+    for (i = 0, off = 0; (i < len && off <= 8); i++) {
+         if (g_ascii_isalnum (id[i]))
+             canonical_id[off++] = id[i];
     }
-    p[0 - off] = 0;
-    
-    /* Shorten where necessary */
-    l = strlen (hex);
-    if (l > (8 + x + 1))
-        hex[8 + x + 1] = 0;
-    
+
+    hex = g_strdup_printf ("%s:%s", SKEY_SSH_STR, canonical_id);
+
     ret = g_quark_from_string (hex);
+    g_free (canonical_id);
     g_free (hex);
     
     return ret;