From 923423a6d66bcd3c925cd3d0201a45a95d068816 Mon Sep 17 00:00:00 2001 From: Robert Hawdon Date: Sat, 2 Mar 2019 18:10:25 +0000 Subject: [PATCH] Fixing seg fault when deleting a directory from "Run command" * Now `show` will return the user to the last valid directory in the history. * Addresses bug #75 --- src/showmenus.c | 57 ++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/src/showmenus.c b/src/showmenus.c index 26fe012..a6f3846 100644 --- a/src/showmenus.c +++ b/src/showmenus.c @@ -277,36 +277,45 @@ void refreshDirectory(char *sortmode, int origtopfileref, int origselected, int { char currentselectname[512]; int i; - if (invalidstart) { - strcpy(currentselectname, ""); - exitCode = 0; - invalidstart = 0; - } else { - if (destructive == 2){ - strcpy(currentselectname, currentfilename); + handleMissingDir: + if (check_dir(currentpwd)){ + if (invalidstart) { + strcpy(currentselectname, ""); + exitCode = 0; + invalidstart = 0; } else { - strcpy(currentselectname, ob[origselected].name); + if (destructive == 2){ + strcpy(currentselectname, currentfilename); + } else { + strcpy(currentselectname, ob[origselected].name); + } } - } - if (destructive != -1){ - free(ob); - ob = get_dir(currentpwd); - clear_workspace(); - reorder_ob(ob, sortmode); - } - if (destructive > 0){ - i = findResultByName(ob, currentselectname); - if (i != 0){ - selected = i; - } else { - if (selected > totalfilecount - 1){ - selected = totalfilecount - 1; + if (destructive != -1){ + free(ob); + ob = get_dir(currentpwd); + clear_workspace(); + reorder_ob(ob, sortmode); + } + if (destructive > 0){ + i = findResultByName(ob, currentselectname); + if (i != 0){ + selected = i; } else { - selected = origselected; + if (selected > totalfilecount - 1){ + selected = totalfilecount - 1; + } else { + selected = origselected; + } } + } else { + selected = findResultByName(ob, currentselectname); } } else { - selected = findResultByName(ob, currentselectname); + strcpy(currentpwd, hs[historyref - 2].path); + objectWild = hs[historyref - 2].objectWild; + historyref--; + chdir(currentpwd); + goto handleMissingDir; } topfileref = sanitizeTopFileRef(origtopfileref); display_dir(currentpwd, ob, topfileref, selected);