public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* fixincl problem
@ 2001-01-21 10:29 Mark Kettenis
  2001-01-21 17:57 ` Fergus Henderson
  2001-01-21 18:06 ` Alexandre Oliva
  0 siblings, 2 replies; 4+ messages in thread
From: Mark Kettenis @ 2001-01-21 10:29 UTC (permalink / raw)
  To: bkorb, gcc

The fixincl program does the equivalent of (in main()):

  /* In load_file_data().  */
  fclose (stdin);

  freopen ("/dev/null", "r", stdin);

Which results in a segmentation fault on the Hurd.

It looks as if this code isn't strictly portable.  The current POSIX
draft says in its description of fclose(FILE *stream):

   After the call to fclose() any use of STREAM results in undefined
   behaviour.

Personally I think load_file_data() shouldn't close the stream that is
passed to it.  If people agree, I can come up with a patch that does
implement that.

Mark

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: fixincl problem
  2001-01-21 10:29 fixincl problem Mark Kettenis
@ 2001-01-21 17:57 ` Fergus Henderson
  2001-01-21 18:06 ` Alexandre Oliva
  1 sibling, 0 replies; 4+ messages in thread
From: Fergus Henderson @ 2001-01-21 17:57 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: bkorb, gcc

On 21-Jan-2001, Mark Kettenis <kettenis@wins.uva.nl> wrote:
> The fixincl program does the equivalent of (in main()):
> 
>   /* In load_file_data().  */
>   fclose (stdin);
> 
>   freopen ("/dev/null", "r", stdin);
> 
> Which results in a segmentation fault on the Hurd.
> 
> It looks as if this code isn't strictly portable.  The current POSIX
> draft says in its description of fclose(FILE *stream):
> 
>    After the call to fclose() any use of STREAM results in undefined
>    behaviour.

The current ISO C standard implies the same:

 | 	The  value  of  a  pointer  to  a  FILE  object   is
 | 	indeterminate after the associated file is closed (including
 | 	the standard text streams).

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: < http://www.cs.mu.oz.au/~fjh >  |     -- the last words of T. S. Garp.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: fixincl problem
  2001-01-21 10:29 fixincl problem Mark Kettenis
  2001-01-21 17:57 ` Fergus Henderson
@ 2001-01-21 18:06 ` Alexandre Oliva
  2001-01-22 12:54   ` Bruce Korb
  1 sibling, 1 reply; 4+ messages in thread
From: Alexandre Oliva @ 2001-01-21 18:06 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: bkorb, gcc

On Jan 21, 2001, Mark Kettenis <kettenis@wins.uva.nl> wrote:

> Personally I think load_file_data() shouldn't close the stream that is
> passed to it.

Agreed.

> If people agree, I can come up with a patch that does implement
> that.

Thanks in advance :-)

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: fixincl problem
  2001-01-21 18:06 ` Alexandre Oliva
@ 2001-01-22 12:54   ` Bruce Korb
  0 siblings, 0 replies; 4+ messages in thread
From: Bruce Korb @ 2001-01-22 12:54 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: Mark Kettenis, bkorb, gcc

*** fixincl.c.ori       Fri Jan  5 08:28:58 2001
--- fixincl.c   Mon Jan 22 12:49:21 2001
***************
*** 364,377 ****
      res = (char*)mmap ((void*)NULL, data_map_size, PROT_READ,
                         MAP_PRIVATE, data_map_fd, 0);
    if (res == (char*)BAD_ADDR)
      {
        curr_data_mapped = BOOL_FALSE;
!       res = load_file_data ( fdopen (data_map_fd, "r"));
      }
- #else
-   curr_data_mapped = BOOL_FALSE;
-   res = load_file_data ( fdopen (data_map_fd, "r"));
- #endif
  
    return res;
  }
--- 364,376 ----
      res = (char*)mmap ((void*)NULL, data_map_size, PROT_READ,
                         MAP_PRIVATE, data_map_fd, 0);
    if (res == (char*)BAD_ADDR)
+ #endif
      {
+       FILE* fp = fdopen (data_map_fd, "r");
        curr_data_mapped = BOOL_FALSE;
!       res = load_file_data (fp);
!       fclose (fp);
      }
  
    return res;
  }
*** fixlib.c.ori        Sat Dec  2 11:46:32 2000
--- fixlib.c    Mon Jan 22 12:49:58 2001
***************
*** 39,44 ****
--- 39,47 ----
    int    space_left = -1;  /* allow for terminating NUL */
    size_t space_used = 0;
  
+   if (fp == (FILE*)NULL)
+     return pz_data;
+ 
    do
      {
        size_t  size_read;
***************
*** 62,68 ****
                  fprintf (stderr, "error %d (%s) reading input\n", err,
                           xstrerror (err));
                free ((void *) pz_data);
-               fclose (fp);
                return (char *) NULL;
              }
          }
--- 62,67 ----
***************
*** 73,79 ****
  
    pz_data = xrealloc ((void*)pz_data, space_used+1 );
    pz_data[ space_used ] = NUL;
-   fclose (fp);
  
    return pz_data;
  }
--- 72,77 ----

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-01-22 12:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-01-21 10:29 fixincl problem Mark Kettenis
2001-01-21 17:57 ` Fergus Henderson
2001-01-21 18:06 ` Alexandre Oliva
2001-01-22 12:54   ` Bruce Korb

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