[patch] avoid invoking commands with empty argument

Pavel Roskin proski at gnu.org
Tue Feb 11 17:07:50 UTC 2003


Hello, Adam!

On Tue, 11 Feb 2003, Adam Byrtek / alpha wrote:

> mc passes an empty argument ("") to the EDITOR when creating new file
> (with F14). It makes vim to list the current dircetory. The nvi doesn't
> create temporary file, so write command won't work, however if you call
> nvi without any argument it creates a temp file to save the data in. The
> same problem occur with some other editors (jed to name one)

What is passed to my_system() - NULL or empty string?  If it's an empty
string, where does it come from?  It's trivial for me to run it in the
debugger, but I assume you did it already.

What happens if EXECUTE_AS_SHELL is set, but command is NULL?  I
understand that the shell won't be executed at all.  This is how it's
called from view_other_cmd() if output_starts_shell is set.

P.S. Empty string comes from edit_cmd_new().  It should be fine to use
NULL if we take care not to run vfs_file_is_local() on NULL in
execute_with_vfs_arg().

How do you like following patch?  Is there any other reason (apart from
running the editor) for replacing "" with NULL in my_system()?

===============================
--- cmd.c
+++ cmd.c
@@ -97,7 +97,7 @@ execute_with_vfs_arg (const char *comman
     time_t mtime;

     /* Simplest case, this file is local */
-    if (vfs_file_is_local (filename)) {
+    if (!filename || vfs_file_is_local (filename)) {
 	execute_internal (command, filename);
 	return;
     }
@@ -348,7 +348,7 @@ edit_cmd (void)
 void
 edit_cmd_new (void)
 {
-    do_edit ("");
+    do_edit (NULL);
 }

 /* Invoked by F5.  Copy, default to the other panel.  */
===============================

-- 
Regards,
Pavel Roskin



More information about the mc-devel mailing list