diff --git a/src/hid/gtk/gtkhid-main.c b/src/hid/gtk/gtkhid-main.c index 779091c6..e5f17842 100644 --- a/src/hid/gtk/gtkhid-main.c +++ b/src/hid/gtk/gtkhid-main.c @@ -1336,6 +1336,7 @@ Load (int argc, char **argv, Coord x, Coord y) { char *function; char *name = NULL; + char *pos = NULL; static gchar *current_element_dir = NULL; static gchar *current_layout_dir = NULL; @@ -1349,9 +1350,11 @@ Load (int argc, char **argv, Coord x, Coord y) if (strcasecmp (function, "Netlist") == 0) { - if (!current_netlist_dir && *PCB->Filename){ + if (!current_netlist_dir && PCB->Filename){ current_netlist_dir = strdup(PCB->Filename); - *strrchr(current_netlist_dir, PCB_DIR_SEPARATOR_C) = 0; + pos = strrchr(current_netlist_dir, PCB_DIR_SEPARATOR_C); + if (pos != NULL) + *pos = 0; } name = ghid_dialog_file_select_open (_("Load netlist file"), ¤t_netlist_dir, @@ -1359,19 +1362,23 @@ Load (int argc, char **argv, Coord x, Coord y) } else if (strcasecmp (function, "ElementToBuffer") == 0) { - if (!current_element_dir && *PCB->Filename){ + if (!current_element_dir && PCB->Filename){ current_element_dir = strdup(PCB->Filename); - *strrchr(current_element_dir, PCB_DIR_SEPARATOR_C) = 0; - } + pos = strrchr(current_element_dir, PCB_DIR_SEPARATOR_C); + if (pos != NULL) + *pos = 0; + } name = ghid_dialog_file_select_open (_("Load element to buffer"), ¤t_element_dir, Settings.LibraryTree); } else if (strcasecmp (function, "LayoutToBuffer") == 0) { - if (!current_layout_dir && *PCB->Filename){ + if (!current_layout_dir && PCB->Filename){ current_layout_dir = strdup(PCB->Filename); - *strrchr(current_layout_dir, PCB_DIR_SEPARATOR_C) = 0; + pos = strrchr(current_layout_dir, PCB_DIR_SEPARATOR_C); + if (pos != NULL) + *pos = 0; } name = ghid_dialog_file_select_open (_("Load layout file to buffer"), ¤t_layout_dir, @@ -1379,9 +1386,11 @@ Load (int argc, char **argv, Coord x, Coord y) } else if (strcasecmp (function, "Layout") == 0) { - if (!current_layout_dir && *PCB->Filename){ + if (!current_layout_dir && PCB->Filename){ current_layout_dir = strdup(PCB->Filename); - *strrchr(current_layout_dir, PCB_DIR_SEPARATOR_C) = 0; + pos = strrchr(current_layout_dir, PCB_DIR_SEPARATOR_C); + if (pos != NULL) + *pos = 0; } name = ghid_dialog_file_select_open (_("Load layout file"), ¤t_layout_dir,