2012/8/17 Ozkan Sezer <[email protected]>

> On 8/17/12, Ruben Van Boxem <[email protected]> wrote:
> > 2012/8/17 Jacek Caban <[email protected]>
> >
> >> On 08/17/12 11:42, Rainer Emrich wrote:
> >> > Am 17.08.2012 11:29, schrieb Kai Tietz:
> >> > > Hallo Rainer,
> >> >
> >> > > well, the issue is that msvcrt's getcwd has as second argument the
> >> > > pointer-length-argument typed as 'int'.  You can check this also by
> >> > > seaching on msdn for getcwd. For 32-bit it is just a sign-difference
> >> > > of
> >> > > this argument, which is pretty unlikely to reach (0x7fffffffu +
> >> > 1u).  For
> >> > > 64-bit is sizeof(size_t) > sizeof(int), which means that we get a
> >> > > value-truncation and a sign-difference.  Not that it is likely that
> >> > > somebody calls getcwd with pointer-length-argument bigger then 2^31
> >> > value.
> >> >
> >> > > So I would like to get first the opinion of Jacek, and Ozkan about
> >> > this. It
> >> > > might be more an issue of the prototype in gcc IMHO.
> >> >
> >> > The prototype conforms to the Linux man pages and POSIX.2001
> >>
> >
> > Windows isn't POSIX.
>
> Right. And the suggested patches aren't acceptable IMO.
>
> >  Nor Linux.
> >
>
> Eh?? Maybe no OS is ever fully 110% POSIX compliant, but
> what you're saying is a bit overkill
>

What I meant was "Windows isn't Linux either". Because he quoted both POSIX
and Linux documentation. Sorry for the confusion.

Ruben

>
> > MinGW-w64 is compatible with the Microsoft CRT, which declares getcwd
> with
> > a second parameter of type int:
> > http://msdn.microsoft.com/en-us/library/sf98bd4y%28v=vs.110%29.aspx
> >
> >
> >>
> >> Although POSIX version seems better, we have to deal with the fact that
> >> it's int on Windows. Why does GCC declare it in its headers in the first
> >> place? It seems like it should use host headers for getcwd declaration.
> >> This way there would be no conflict.
> >>
> >
> > IMO, the GCC header needs an #if _WIN32 for this case. In the worst case,
> > like this:
> >
> > #if _WIN32
> > inline char *getcwd( char *buffer, size_t maxlen ) { return
> _getcwd(buffer,
> > (int)maxlen); }
> > #else
> > char *getcwd( char *buffer, size_t maxlen );
> > #endif
> >
> > The C++ overload mechanism and the cast will take care of all the
> > differences at call sites of this function.
> >
> > I do agree with Jacek that GCC should include the platform headers. This
> > will not fix warnings/errors caused by calling the MS version of getcwd
> > with a second parameter of type size_t (truncation of a value might cause
> > an error, especially with -Werror). There's also the extra underscore.
> Both
> > problems are alleviated with the above snippet of code, assuming maxlen
> > stays within a reasonable range.
> >
> > Ruben
>
>
> gcc/system.h has its declaration guarded by
> #if defined (HAVE_DECL_GETCWD) && !HAVE_DECL_GETCWD
> ... so the question is why doesn't it work and the header
> has to declare a library function by itself?
>
> --
> O.S.
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Mingw-w64-public mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
>
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to