Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2004:
[Freeciv-Dev] (PR#10095) handle_game_load() can crash
Home

[Freeciv-Dev] (PR#10095) handle_game_load() can crash

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: use_less@xxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#10095) handle_game_load() can crash
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 14 Sep 2004 14:24:37 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=10095 >

> [use_less - Tue Sep 14 04:35:54 2004]:
> 
> in handle_game_load in gui-gtk-2.0/connectdlg.c, a strrchr is done to
> find the last '/' in the string current_filename, then the title bar is
> changed to the string immediately after that slash.  However if there is
> no slash, strrchr will return a null, and gtk_window_set_title() will
> page fault.
> 
> Bug seen in win32, where file paths don't always have slashes.

But doesn't win32 use \ as it's separator, so we instead want to do a
strrchr for that?

Regardless, this patch should fix the segfault.

jason

Index: client/gui-gtk-2.0/connectdlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/connectdlg.c,v
retrieving revision 1.42
diff -u -r1.42 connectdlg.c
--- client/gui-gtk-2.0/connectdlg.c     13 Sep 2004 08:39:21 -0000      1.42
+++ client/gui-gtk-2.0/connectdlg.c     14 Sep 2004 21:24:22 -0000
@@ -466,7 +466,14 @@
     char *buf = current_filename;
     
     buf = strrchr(current_filename, '/');
-    gtk_window_set_title(GTK_WINDOW(dialog), ++buf);
+    if (buf) {
+      /* First character after separator. */
+      buf++;
+    } else {
+      /* No separator. */
+      buf = current_filename;
+    }
+    gtk_window_set_title(GTK_WINDOW(dialog), buf);
   }
 
   game.nplayers = packet->nplayers;

[Prev in Thread] Current Thread [Next in Thread]