[vlc-devel] memory breakage at vlc_stat

Rémi Denis-Courmont remi at remlab.net
Sat Jan 28 12:11:29 CET 2012


Le samedi 28 janvier 2012 12:01:41 Naohiro KORIYAMA, vous avez écrit :
> VLC win32 nightly builds (vlc-2.1.0-git-20120128-0411-win32-debug) does not
> run.
> 
> int vlc_stat (const char *filename, struct stat *buf)
>  int ret = _wstati64 (wpath, buf);
> 
> compiler warning appears here because of incompatible pointer type:
> ../../extras/package/win32/../../../src/win32/filesystem.c: In
> function 'vlc_stat':
> ../../extras/package/win32/../../../src/win32/filesystem.c:246:
> warning: passing argument 2 of '_wstati64' from incompatible pointer
> type
> /usr/lib/gcc/i586-mingw32msvc/4.4.4/../../../../i586-mingw32msvc/include/sy
> s/stat.h:182: note: expected 'struct _stati64 *' but argument is of type
> 'struct stat *'
> 
> This cause memory breakage.
> After passing _wstati64(), filename is broken. I confirmed it with gdb.

It works fine here in fact.

On Windows, stat depends on the file offset and time_t size. On Win32, both 
types can occupy either 32 or 64 bits depending on build time parameters.
VLC requires 64-bits file offsets to support large files, and sets 
_FILE_OFFSET_BITS accordingly to 64 in "config.h".

So if we have 32-bits time_t, then 'struct stat' will be 'struct _stat32i64'
and _wstat32i64() should be used. In that case, <sys/stat.h> defines 
_wstat32i64 to _wstati64. So _wstati64 is good.

If we have 64-bits time_t, then 'struct stat' will be 'struct _stat64'
and _wstat64() should be used. In that case, <sys/stat.h> defines _wstati64 to 
_wstat64. So _wstati64 is good.

> Defining stat as _stati64 or using _stati64 explicitly at vlc_stat
> fixed this problem.

As far as I know, _stati64 is ANSI, not Unicode.

-- 
Rémi Denis-Courmont
http://www.remlab.net/
http://fi.linkedin.com/in/remidenis



More information about the vlc-devel mailing list