This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Patch,Fortran] PR42996 - fix LENGTH= of get_command_argument
- From: Tobias Burnus <burnus at net-b dot de>
- To: gcc patches <gcc-patches at gcc dot gnu dot org>, gfortran <fortran at gcc dot gnu dot org>
- Date: Tue, 09 Feb 2010 14:27:00 +0100
- Subject: [Patch,Fortran] PR42996 - fix LENGTH= of get_command_argument
Hi,
the patch is obvious: The standard and also the gfortran manual say that
get_command_argument returns the length of the command-line argument in
LENGTH=; however, if VALUE= has been specified and is of shorter "len"
than the command-line argument, the value-length was returned. (See PR;
there is no test case for deja gnu.)
Build and regtested on x86-64-linux. I will commit it this evening as
obvious.
(Anyone interested in a backport to 4.4?)
Tobias
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.
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 ? arglen : value_len);
}
if (length != NULL)