mkulke / ftplibpp

Platform independent c++ library providing ftp client functionality.
GNU Lesser General Public License v2.1
291 stars 108 forks source link

Stack around the variable 'v' was corrupted in MSVC 2012 #1

Closed debug064 closed 10 years ago

debug064 commented 11 years ago

It happens in this line: sscanf(cp,"%hhu,%hhu,%hhu,%hhu,%hhu,%hhu",&v[2],&v[3],&v[4],&v[5],&v[0],&v[1]); If change unsigned char v[6]; to unsigned int v[6]; then it works.

In GCC 4.8.1.it works fine.

mkulke commented 11 years ago

I guess this has something to do with MSVC++ not implementing the C99 standard, in which the %hh length modifier was introduced. i created a new branch with a workaround for that, but i have no access to said msvc compiler to actually test it. Maybe you like to test it and tell me, whether it works or not.

debug064 commented 11 years ago

It works.

Just in case here are the changes I also made in local version. in header file: ordered windows header

if defined(_WIN32)

include

include

if BUILDING_DLL

define DLLIMPORT __declspec (dllexport)

else /* Not BUILDINGDLL /

define DLLIMPORT __declspec (dllimport)

endif /_ Not BUILDING_DLL */

else

include <sys/time.h>

include

endif

Removed using namespace std;

In cpp file Removed defines windows.h and winsock.h

in ftplib::readline added

ifdef _WIN32

end = static_cast<char*>(_memccpy(bp, ctl->cget, '\n', x));

else

end = static_cast<char*>(memccpy(bp,ctl->cget,'\n',x));

endif

in ftplib::Connect added

ifdef _WIN32

lhost = _strdup(host);

else

lhost = strdup(host);

endif

mkulke commented 10 years ago

Thank you, i could reproduce the problem on an msvc 2012 environment, too (plus the _memccpy & _strdup issues). i will merge the fix to master.