Claudio Bley wrote:
> When calling 
> 
> freopen(NULL, mode, stream);
> 
> on MS Windows using MinGW segfaults because it tries to strcmp(NULL,
> "/dev/null")... *ouch*
> 
> --------------------
> --- freopen.c.orig    2011-08-03 14:22:15 +0200
> +++ freopen.c 2011-08-25 21:01:46 +0200
> @@ -38,7 +38,7 @@
>  rpl_freopen (const char *filename, const char *mode, FILE *stream)
>  {
>  #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
> -  if (strcmp (filename, "/dev/null") == 0)
> +  if (filename && strcmp (filename, "/dev/null") == 0)
>      filename = "NUL";
>  #endif
>  
> --------------------

Yes, thanks for the fix. I'm applying this is your name. (The "tiny change"
mark means that the change does not warrant the exchange of a copyright
assignment.)



2011-08-31  Claudio Bley  <claudio.b...@gmail.com>  (tiny change)

        freopen: Don't crash if the filename argument is NULL.
        * lib/freopen.c (rpl_freopen): Don't compare the filename if it is
        NULL.

--- lib/freopen.c.orig  Wed Aug 31 09:47:57 2011
+++ lib/freopen.c       Wed Aug 31 09:47:25 2011
@@ -41,7 +41,7 @@
 rpl_freopen (const char *filename, const char *mode, FILE *stream)
 {
 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-  if (strcmp (filename, "/dev/null") == 0)
+  if (filename != NULL && strcmp (filename, "/dev/null") == 0)
     filename = "NUL";
 #endif
 

-- 
In memoriam Magomed Yevloyev <http://en.wikipedia.org/wiki/Magomed_Yevloyev>

Reply via email to