Patchwork [libfortran,2nd,version] PR 48618 - Negative unit number in OPEN(...) is sometimes allowed

login
register
mail settings
Submitter Tobias Burnus
Date March 7, 2013, 11:46 a.m.
Message ID <51387E02.60403@net-b.de>
Download mbox | patch
Permalink /patch/225822/
State New
Headers show

Comments

Tobias Burnus - March 7, 2013, 11:46 a.m.
Hi,

Tilo Schwarz wrote:
> this patch fixes PR 48618.
> Built and regtested on Linux 3.2.0-4-686-pae.

Thanks for the patch, which mostly looks okay.

A few remarks:

* Do not create a diff of the ChangeLog but include it separately at the 
top of the patch. Reason: It's easier to read and if another patch has 
been applied before, your patch won't apply.

* A ChangeLog for the testcase is missing.


* Coding style: If 8 spaces have accumulated, replace them by one tab, i.e.
-      u = find_or_create_unit (opp->common.unit);
+      if (u == NULL)
+        u = find_or_create_unit (opp->common.unit);

Here, the last line should use a "tab". (The other important rule is to 
have maximally 80 character per source line.)

See also http://gcc.gnu.org/wiki/FormattingCodeForGCC

(Consistent coding styles makes it easier to read the code. The style 
might not always the best or to the personal taste, but still 
consistency helps. For instance, function names always start in column 1 
and have a " " before the "(". Hence, one can do "grep '^funcname ' *.c 
to find the function.)



* Comment style:
+      if (u == NULL) /* negative unit and no unit found */
+        generate_error (&opp->common, LIBERROR_BAD_OPTION,
+                        "Bad unit number in OPEN statement");
+      /* check for previous error, otherwise unit won't be unlocked 
later */

To quote the comment style from 
http://www.gnu.org/prep/standards/html_node/Comments.html:

"Please put two spaces after the end of a sentence in your comments, so 
that the Emacs sentence commands will work. Also, please write complete 
sentences and capitalize the first word. If a lower-case identifier 
comes at the beginning of a sentence, don’t capitalize it! Changing the 
spelling makes it a different identifier. If you don’t like starting a 
sentence with a lower case letter, write the sentence differently (e.g., 
“The identifier lower-case is …”)."

(The existing code does not always follow the style, but one should at 
least try, even if there is some leeway ;-)


* Regarding your patch itself. I think it is easier to read if one moves 
the code a bit further down as I did in the attachment. What do you think?


* Copyright assignment: You mentioned that you have emailed(§) the form 
back to the FSF. Was this the actual copyright-assignment form which the 
FSF sent to you by mail? Or was it 'only' request form? Can you tell us, 
when the FSF has acknowledged the arrival of the copyright assignment?


Tobias


(§) Side note: The FSF now also allows to send the copyright form back 
by FAX or (scanned) by email, but only if you are residing in the USA or 
in Germany. Residents of other countries still have to return it by 
(air,surface) mail. Cf. 
http://www.gnu.org/prep/maintain/html_node/Copyright-Papers.html
Tilo Schwarz - March 7, 2013, 4:35 p.m.
On Thu, 07 Mar 2013 12:46:10 +0100, Tobias Burnus <burnus@net-b.de> wrote:

> Hi,
>
> Tilo Schwarz wrote:
>> this patch fixes PR 48618.
>> Built and regtested on Linux 3.2.0-4-686-pae.
>
> Thanks for the patch, which mostly looks okay.
>
> A few remarks:

Thank you for the feedback.

I incorporated all remarks into the new attached patch.

> * Copyright assignment: You mentioned that you have emailed(§) the form
> back to the FSF. Was this the actual copyright-assignment form which the
> FSF sent to you by mail? Or was it 'only' request form?

It was the actual copyright-assignment form.

> Can you tell us,
> when the FSF has acknowledged the arrival of the copyright assignment?

Yes, I'll do.


Regards,
	Tilo
Tobias Burnus - March 19, 2013, 11:01 a.m.
Am 07.03.2013 17:35, schrieb Tilo Schwarz:
> On Thu, 07 Mar 2013 12:46:10 +0100, Tobias Burnus <burnus@net-b.de> 
> wrote:
>> Tilo Schwarz wrote:
>>> this patch fixes PR 48618.
>>> Built and regtested on Linux 3.2.0-4-686-pae.
>>
>> Thanks for the patch, which mostly looks okay.
>> A few remarks:
>
> Thank you for the feedback.
> I incorporated all remarks into the new attached patch.

The patch looks good and is okay for the 4.9 trunk. Thanks for your efforts!

If you commit yourself, you need to recall to split the ChangeLog into 
the parts which go into libgfortran/ChangeLog and 
gcc/testsuite/ChangeLog. For the commit log, use "svn log|less" to see 
what others do for the commit log.

If you want me to commit this (and the other) patch instead, please tell me.

Tobias
Tilo Schwarz - March 19, 2013, 9:16 p.m.
On Tue, 19 Mar 2013 12:01:12 +0100, Tobias Burnus <burnus@net-b.de> wrote:

> Am 07.03.2013 17:35, schrieb Tilo Schwarz:
>> On Thu, 07 Mar 2013 12:46:10 +0100, Tobias Burnus <burnus@net-b.de>  
>> wrote:
>>> Tilo Schwarz wrote:
>>>> this patch fixes PR 48618.
>>>> Built and regtested on Linux 3.2.0-4-686-pae.
>>>
>>> Thanks for the patch, which mostly looks okay.
>>> A few remarks:
>>
>> Thank you for the feedback.
>> I incorporated all remarks into the new attached patch.
>
> The patch looks good and is okay for the 4.9 trunk. Thanks for your  
> efforts!
>
> If you commit yourself, you need to recall to split the ChangeLog into  
> the parts which go into libgfortran/ChangeLog and  
> gcc/testsuite/ChangeLog. For the commit log, use "svn log|less" to see  
> what others do for the commit log.
>
> If you want me to commit this (and the other) patch instead, please tell  
> me.

Yes, I'm glad if you commit the two patches. I'll set up the svn for  
future patches.

Regards,

	Tilo

Patch

diff --git a/libgfortran/io/open.c b/libgfortran/io/open.c
index d9cfde8..19fab1d 100644
--- a/libgfortran/io/open.c
+++ b/libgfortran/io/open.c
@@ -817,12 +817,8 @@  st_open (st_parameter_open *opp)
     }
 
   flags.convert = conv;
 
-  if (!(opp->common.flags & IOPARM_OPEN_HAS_NEWUNIT) && opp->common.unit < 0)
-    generate_error (&opp->common, LIBERROR_BAD_OPTION,
-		    "Bad unit number in OPEN statement");
-
   if (flags.position != POSITION_UNSPECIFIED
       && flags.access == ACCESS_DIRECT)
     generate_error (&opp->common, LIBERROR_BAD_OPTION,
 		    "Cannot use POSITION with direct access files");
@@ -847,10 +843,18 @@  st_open (st_parameter_open *opp)
   if ((opp->common.flags & IOPARM_LIBRETURN_MASK) == IOPARM_LIBRETURN_OK)
     {
       if ((opp->common.flags & IOPARM_OPEN_HAS_NEWUNIT))
 	opp->common.unit = get_unique_unit_number(opp);
+      else if (opp->common.unit < 0)
+	{
+	  u = find_unit (opp->common.unit);
+	  if (u == NULL) /* Negative unit and no NEWUNIT-created unit found.  */
+	    generate_error (&opp->common, LIBERROR_BAD_OPTION,
+			    "Bad unit number in OPEN statement");
+	}
 
-      u = find_or_create_unit (opp->common.unit);
+      if (u == NULL)
+	u = find_or_create_unit (opp->common.unit);
       if (u->s == NULL)
 	{
 	  u = new_unit (opp, u, &flags);
 	  if (u != NULL)