Hello world,

currently, EXECUTE_COMMAND_LINE aborts the program if the called program
is not found, if cmdstat is present, but cmdmsg isn't. This is a 6/7/8
regression.

This patch fixes the issue by simply removing the erronous call to
runtime_error.

Regression-tested.  OK for all affected branches?

Regards

        Thomas

2017-10-10  Thomas Koenig  <tkoe...@gcc.gnu.org>

        PR libfortran/82233
        * intrinsics/execute_command_line.c (execute_command_line):
        No call to runtime_error if cmdstat is present.

2017-10-10  Thomas Koenig  <tkoe...@gcc.gnu.org>

        PR libfortran/82233
        * gfortran.dg/execute_command_line_3.f90: New test.
Index: intrinsics/execute_command_line.c
===================================================================
--- intrinsics/execute_command_line.c	(Revision 253525)
+++ intrinsics/execute_command_line.c	(Arbeitskopie)
@@ -125,15 +125,9 @@ execute_command_line (const char *command, bool wa
   free (cmd);
 
   /* Now copy back to the Fortran string if needed.  */
-  if (cmdstat && *cmdstat > EXEC_NOERROR)
-    {
-      if (cmdmsg)
-	fstrcpy (cmdmsg, cmdmsg_len, cmdmsg_values[*cmdstat],
+  if (cmdstat && *cmdstat > EXEC_NOERROR && cmdmsg)
+    fstrcpy (cmdmsg, cmdmsg_len, cmdmsg_values[*cmdstat],
 		strlen (cmdmsg_values[*cmdstat]));
-      else
-	runtime_error ("Failure in EXECUTE_COMMAND_LINE: %s",
-		       cmdmsg_values[*cmdstat]);
-    }
 }
 
 
! { dg-do  run }
! PR 82233 - there were program aborts for some of these commands.
! Original test case by Urban Jost.
program boom
implicit none
integer                       :: i,j 
character(len=256)            :: msg
character(len=:), allocatable :: command
   command='notthere'
   msg='' ! seems to only be defined if exitstatus.ne.0
   ! ok -- these work
   call execute_command_line(command , wait=.false., exitstat=i, cmdstat=j, cmdmsg=msg)
   if (j /= 0 .or. msg /= '') call abort
   call execute_command_line(command ,               exitstat=i, cmdstat=j, cmdmsg=msg )
   if (j /= 3 .or. msg /= "Invalid command line" ) call abort
   msg = ''
   call execute_command_line(command , wait=.false., exitstat=i,            cmdmsg=msg )
   print *,msg
   if (msg /= '') call abort
   call execute_command_line(command ,               exitstat=i, cmdstat=j             )
   if (j /= 3) call abort
   call execute_command_line(command , wait=.false., exitstat=i                        )

end program boom

Reply via email to