[libgsystem] fileutils: Avoid crash if g_set_prgname() has not been called



commit 34fc4d48819574345d87ba3005211091250f4369
Author: Colin Walters <walters verbum org>
Date:   Fri Sep 13 16:40:07 2013 -0400

    fileutils: Avoid crash if g_set_prgname() has not been called
    
    While we're here, also squash spaces in the filename to '_'.

 gsystem-file-utils.c |   20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)
---
diff --git a/gsystem-file-utils.c b/gsystem-file-utils.c
index e23f17e..6c70594 100644
--- a/gsystem-file-utils.c
+++ b/gsystem-file-utils.c
@@ -444,12 +444,24 @@ get_default_tmp_prefix (void)
       const char *prgname = g_get_prgname ();
       const char *p;
       char *prefix;
+      char *iter;
 
-      p = strrchr (prgname, '/');
-      if (p)
-        prgname = p + 1;
-
+      if (prgname)
+        {
+          p = strrchr (prgname, '/');
+          if (p)
+            prgname = p + 1;
+        }
+      else
+        prgname = "";
+          
       prefix = g_strdup_printf ("tmp-%s%u-", prgname, getuid ());
+      for (iter = prefix; *iter; iter++)
+        {
+          char c = *iter;
+          if (c == ' ')
+            *iter = '_';
+        }
       
       g_once_init_leave (&tmpprefix, prefix);
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]