[nautilus] Make getting extension more robust



commit 216e50f40e816e7fcc0e1fdaf3a4c8e3e816b990
Author: William Jon McCann <jmccann redhat com>
Date:   Wed Aug 22 12:14:23 2012 -0400

    Make getting extension more robust
    
    Ensure the basename and extension have at least one char each.

 eel/eel-vfs-extensions.c                       |   19 +++++++++++++++----
 libnautilus-private/nautilus-file-operations.c |    2 +-
 2 files changed, 16 insertions(+), 5 deletions(-)
---
diff --git a/eel/eel-vfs-extensions.c b/eel/eel-vfs-extensions.c
index 7532253..84a38a1 100644
--- a/eel/eel-vfs-extensions.c
+++ b/eel/eel-vfs-extensions.c
@@ -106,20 +106,31 @@ char *
 eel_filename_get_extension_offset (const char *filename)
 {
 	char *end, *end2;
+	const char *start;
 
-	end = strrchr (filename, '.');
+	if (filename == NULL || filename[0] == '\0') {
+		return NULL;
+	}
 
-	if (end && end != filename) {
+	/* basename must have at least one char */
+	start = filename + 1;
+
+	end = strrchr (start, '.');
+	if (end == NULL || end[1] == '\0') {
+		return NULL;
+	}
+
+	if (end != start) {
 		if (strcmp (end, ".gz") == 0 ||
 		    strcmp (end, ".bz2") == 0 ||
 		    strcmp (end, ".sit") == 0 ||
 		    strcmp (end, ".Z") == 0) {
 			end2 = end - 1;
-			while (end2 > filename &&
+			while (end2 > start &&
 			       *end2 != '.') {
 				end2--;
 			}
-			if (end2 != filename) {
+			if (end2 != start) {
 				end = end2;
 			}
 		}
diff --git a/libnautilus-private/nautilus-file-operations.c b/libnautilus-private/nautilus-file-operations.c
index 0bc5b0a..bbbb26b 100644
--- a/libnautilus-private/nautilus-file-operations.c
+++ b/libnautilus-private/nautilus-file-operations.c
@@ -543,7 +543,7 @@ parse_previous_duplicate_name (const char *name,
 
 	g_assert (name[0] != '\0');
 
-	*suffix = eel_filename_get_extension_offset (name + 1);
+	*suffix = eel_filename_get_extension_offset (name);
 
 	if (*suffix == NULL || (*suffix)[1] == '\0') {
 		/* no suffix */



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