According to the F2003 standard, the LENGTH argument does "not consider any possible truncation or padding in assigning the command argument value to the VALUE argument" (13.7.42). However, gfortran appears to use the minimum of the length of the VALUE argument (if present) and the length of the command argument. (svn revision 156557)
Created attachment 19819 [details] Simple test case Call the resulting program with an argument longer than one character.
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)
Subject: Bug 42996 Author: burnus Date: Tue Feb 9 17:04:57 2010 New Revision: 156630 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=156630 Log: 2010-02-09 Tobias Burnus <burnus@net-b.de> PR fortran/42996 * intrinsics/args.c (get_command_argument_i4): Always return commandline-argument length for length parameter. Modified: trunk/libgfortran/ChangeLog trunk/libgfortran/intrinsics/args.c
FIXED on the trunk (4.5). Thanks for the bug report!