[rtems commit] libmisc/shell/edit: Fix closing the editor

Chris Johns chrisj at rtems.org
Tue Jan 31 05:17:29 UTC 2023


Module:    rtems
Branch:    master
Commit:    3ad2789fc68308a48119d736c89c93f493d18013
Changeset: http://git.rtems.org/rtems/commit/?id=3ad2789fc68308a48119d736c89c93f493d18013

Author:    Chris Johns <chrisj at rtems.org>
Date:      Mon Jan 30 13:59:11 2023 +1100

libmisc/shell/edit: Fix closing the editor

Closes #4834

---

 cpukit/libmisc/shell/main_edit.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/cpukit/libmisc/shell/main_edit.c b/cpukit/libmisc/shell/main_edit.c
index 191eefa19d..b9e377bc23 100644
--- a/cpukit/libmisc/shell/main_edit.c
+++ b/cpukit/libmisc/shell/main_edit.c
@@ -1809,14 +1809,14 @@ static void save_editor(struct editor *ed) {
   ed->refresh = 1;
 }
 
-static void close_editor(struct editor *ed) {
+static struct editor* close_editor(struct editor *ed) {
   struct env *env = ed->env;
 
   if (ed->dirty) {
     display_message(ed, "Close %s without saving changes (y/n)? ", ed->filename);
     if (!ask()) {
       ed->refresh = 1;
-      return;
+      return ed;
     }
   }
 
@@ -1828,6 +1828,7 @@ static void close_editor(struct editor *ed) {
     new_file(ed, "");
   }
   ed->refresh = 1;
+  return ed;
 }
 
 static void pipe_command(struct editor *ed) {
@@ -2151,15 +2152,7 @@ static void edit(struct editor *ed) {
         case ctrl('s'): save_editor(ed); break;
         case ctrl('p'): pipe_command(ed); break;
 #endif
-#if defined(__rtems__)
-        /*
-         * Coverity spotted this as using ed after free() so changing
-         * the order of the statements.
-         */
-        case ctrl('w'): ed = ed->env->current; close_editor(ed); break;
-#else
-        case ctrl('w'): close_editor(ed); ed = ed->env->current; break;
-#endif
+        case ctrl('w'): ed = close_editor(ed); break;
       }
     }
   }



More information about the vc mailing list