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. Nor Linux.

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




>
> Jacek
>
>
> ------------------------------------------------------------------------------
> 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