[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] freopen SEGFAULT on win32 with filename == NULL
From: |
Claudio Bley |
Subject: |
Re: [PATCH] freopen SEGFAULT on win32 with filename == NULL |
Date: |
Thu, 01 Sep 2011 19:24:06 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
Bruno Haible <address@hidden> writes:
> Claudio Bley wrote:
>> --------------------
>> --- 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.)
Thank you.
> Claudio Bley wrote:
>> Furthermore, using NULL as filename does not work at all using the MS
>> C runtime library (debug assertion violation).
>>
>> --------------------
>> --- freopen.c.1 2011-08-25 21:05:34 +0200
>> +++ freopen.c 2011-08-25 21:08:52 +0200
>> @@ -38,6 +38,9 @@
>> rpl_freopen (const char *filename, const char *mode, FILE *stream)
>> {
>> #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
>> +# ifdef _MSC_VER
>> + if (!filename) return NULL; /* would trigger a runtime error on MSVC */
>> +# endif
>> if (filename && strcmp (filename, "/dev/null") == 0)
>> filename = "NUL";
>> #endif
>>
>> --------------------
>
> Unfortunately, freopen (NULL, ...) is not something gnulib can support
> portably.
Just to clarify. That patch only tries to avoid a runtime crash when
trying to pass NULL as filename (when using the MSVC compiler). It
simply makes that function fail in this case (maybe errno should be
set too).
>> Using MinGW and trying to change stdout's mode to binary simply fails:
>>
>> if (!isatty(fileno(stdout))
>> freopen(NULL, "wb", stdout); /* <- returns NULL */
>
> You can use the gnulib module 'binary-io' instead of freopen here.
That's perfectly fine for me. I will talk to the diffutils people
(which is the program I'm currently having problems with). Thanks for
the pointer, I didn't realize that module already exists...
Cheers,
Claudio
- Re: [PATCH] freopen SEGFAULT on win32 with filename == NULL,
Claudio Bley <=