------- Comment #2 from burnus at gcc dot gnu dot org  2010-02-08 13:19 -------
Confirm - I get for "./a.out test" the following result.

Current (gfortran):
   With no value, length was:4 and status:0
   With LEN=1 value, length was:1 and status:-1 <<<<< Bad: len = 1
   With LEN=10 value, length was:4 and status:0

Expected (NAG f95, ifort):
   With no value, length was:4 and status:0
   With LEN=1 value, length was:4 and status:-1 <<<<< OK: len = 4
   With LEN=10 value, length was:4 and status:0

By the way, the manual is correct:
http://gcc.gnu.org/onlinedocs/gfortran/GET_005fCOMMAND_005fARGUMENT.html


Draft patch:

diff --git a/libgfortran/intrinsics/args.c b/libgfortran/intrinsics/args.c
index 7187bec..83a0502 100644
--- a/libgfortran/intrinsics/args.c
+++ b/libgfortran/intrinsics/args.c
@@ -147,11 +147,9 @@ get_command_argument_i4 (GFC_INTEGER_4 *number, char
*value,
   if (value != NULL && stat_flag != GFC_GC_FAILURE)
     {
       if (arglen > value_len)
-       {
-        arglen = value_len;
         stat_flag = GFC_GC_VALUE_TOO_SHORT;
-       }
-      memcpy (value, argv[*number], arglen);
+
+      memcpy (value, argv[*number], arglen > value_len ? value_len : arglen);
     }

   if (length != NULL)


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2010-02-08 13:19:24
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42996

Reply via email to