public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "burnus at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libfortran/42996] Incorrect length returned from get_command_argument intrinsic
Date: Mon, 08 Feb 2010 13:19:00 -0000	[thread overview]
Message-ID: <20100208131924.14799.qmail@sourceware.org> (raw)
In-Reply-To: <bug-42996-17837@http.gcc.gnu.org/bugzilla/>



------- 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


  parent reply	other threads:[~2010-02-08 13:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-08 10:44 [Bug libfortran/42996] New: " ian_harvey at bigpond dot com
2010-02-08 10:48 ` [Bug libfortran/42996] " ian_harvey at bigpond dot com
2010-02-08 13:19 ` burnus at gcc dot gnu dot org [this message]
2010-02-09 17:05 ` burnus at gcc dot gnu dot org
2010-02-09 17:07 ` burnus at gcc dot gnu dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100208131924.14799.qmail@sourceware.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).