Ticket #95 (closed defect)

Opened 8 years ago

Last modified 8 years ago

Warnings when compiling under MSVC2008

Reported by: g00fy Owned by: bagder
Priority: normal Milestone:
Component: misc Version:
Keywords: Cc: g00fy, bagder, roadrunn
Blocked By: Blocks:

Description

..\..\externals\libssh2\src\sftp.c(381) : warning C4244: 'initializing' : conversion from 'time_t' to 'long', possible loss of data
..\..\externals\libssh2\src\sftp.c(1657) : warning C4244: 'return' : conversion from 'libssh2_uint64_t' to 'size_t', possible loss of data

..\..\externals\libssh2\src\scp.c(750) : warning C4244: '=' : conversion from 'long' to 'unsigned short', possible loss of data

..\..\externals\libssh2\src\packet.c(1081) : warning C4244: 'initializing' : conversion from 'time_t' to 'long', possible loss of data
..\..\externals\libssh2\src\packet.c(1190) : warning C4244: 'initializing' : conversion from 'time_t' to 'long', possible loss of data

Attachments

libssh2.patch (5.6 KB) - added by g00fy 8 years ago.

Download all attachments as: .zip

Change History

comment:1 Changed 8 years ago by roadrunn

I am using VS2008 and don't get any warnings. In my pre-build events, I am copying the libssh2_config.h from the win32 directory in the source to the src directory.

comment:2 Changed 8 years ago by g00fy

Probably this is because you use the default projects. I re-create my project via CMake so I could hang it in my current build-tree.

Very probably the error level is higher than the one in the default projects?

comment:3 Changed 8 years ago by bagder

So what "error levels" are you guys using and what do you think we should consider a "sensible" level to be?

comment:4 Changed 8 years ago by g00fy

Hi badger,

I just checked out the provided .dsw (converted it with "MS Visual Studio 2008, version 9.0.30729.1 SP" (VS Studio Express C++))...
What I did:

  • checkout from CVS the latest version
  • open libssh2/win32/libssh2.dsw with my VSStudio
  • press "yes to all" at the conversion question
  • build everything in debug mode

I get these errors:
1>------ Build started: Project: libssh2_lib, Configuration: Debug Win32 ------
2>------ Build started: Project: libssh2_dll, Configuration: Debug Win32 ------
1>Compiling...
2>Compiling...
1>comp.c
2>channel.c
1>crypt.c
1>hostkey.c
2>libssh2\src\channel.c(1233) : warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
2> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(366) : see declaration of 'sprintf'
2>comp.c
2>crypt.c
2>hostkey.c
2>libssh2\include\libssh2.h(566) : error C2061: syntax error : identifier 'libssh2_channel_read_ex'
2>libssh2\include\libssh2.h(566) : error C2059: syntax error : ';'
2>libssh2\include\libssh2.h(566) : error C2059: syntax error : 'type'
2>libssh2\include\libssh2.h(596) : error C2061: syntax error : identifier 'libssh2_channel_write_ex'
1>libssh2\include\libssh2.h(566) : error C2061: syntax error : identifier 'libssh2_channel_read_ex'
1>libssh2\include\libssh2.h(566) : error C2059: syntax error : ';'
2>libssh2\include\libssh2.h(596) : error C2059: syntax error : ';'
2>libssh2\include\libssh2.h(596) : error C2059: syntax error : 'type'
2>libssh2\src\hostkey.c(445) : error C2491: 'libssh2_hostkey_hash' : definition of dllimport function not allowed
2>libssh2\src\hostkey.c(468) : error C2491: 'libssh2_session_hostkey' : definition of dllimport function not allowed
2>kex.c
1>libssh2\include\libssh2.h(566) : error C2059: syntax error : 'type'
1>libssh2\include\libssh2.h(596) : error C2061: syntax error : identifier 'libssh2_channel_write_ex'
1>libssh2\include\libssh2.h(596) : error C2059: syntax error : ';'
1>libssh2\include\libssh2.h(596) : error C2059: syntax error : 'type'
1>libssh2\src\hostkey.c(445) : error C2491: 'libssh2_hostkey_hash' : definition of dllimport function not allowed
1>libssh2\src\hostkey.c(468) : error C2491: 'libssh2_session_hostkey' : definition of dllimport function not allowed
1>kex.c
2>mac.c
2>misc.c
2>libssh2\src\misc.c(282) : warning C4996: '_snprintf': This function or variable may be unsafe. Consider using _snprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
2> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(358) : see declaration of '_snprintf'
2>libssh2\src\misc.c(288) : warning C4996: '_snprintf': This function or variable may be unsafe. Consider using _snprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
2> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(358) : see declaration of '_snprintf'
2>libssh2\src\misc.c(295) : warning C4996: '_snprintf': This function or variable may be unsafe. Consider using _snprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
2> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(358) : see declaration of '_snprintf'
1>mac.c
2>openssl.c
2>packet.c
1>misc.c
1>libssh2\src\misc.c(282) : warning C4996: '_snprintf': This function or variable may be unsafe. Consider using _snprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
2>libssh2\src\packet.c(1081) : warning C4244: 'initializing' : conversion from 'time_t' to 'long', possible loss of data
1> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(358) : see declaration of '_snprintf'
1>libssh2\src\misc.c(288) : warning C4996: '_snprintf': This function or variable may be unsafe. Consider using _snprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(358) : see declaration of '_snprintf'
2>libssh2\src\packet.c(1190) : warning C4244: 'initializing' : conversion from 'time_t' to 'long', possible loss of data
1>libssh2\src\misc.c(295) : warning C4996: '_snprintf': This function or variable may be unsafe. Consider using _snprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(358) : see declaration of '_snprintf'
2>pem.c
1>openssl.c
1>packet.c
2>publickey.c
1>libssh2\src\packet.c(1081) : warning C4244: 'initializing' : conversion from 'time_t' to 'long', possible loss of data
1>libssh2\src\packet.c(1190) : warning C4244: 'initializing' : conversion from 'time_t' to 'long', possible loss of data
2>scp.c
1>pem.c
2>libssh2\src\scp.c(292) : warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
2> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(366) : see declaration of 'sprintf'
2>libssh2\src\scp.c(750) : warning C4244: '=' : conversion from 'long' to 'unsigned short', possible loss of data
2>libssh2\src\scp.c(792) : warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
2> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(366) : see declaration of 'sprintf'
2>libssh2\src\scp.c(877) : warning C4996: '_snprintf': This function or variable may be unsafe. Consider using _snprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
2> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(358) : see declaration of '_snprintf'
2>libssh2\src\scp.c(939) : warning C4996: '_snprintf': This function or variable may be unsafe. Consider using _snprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
2> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(358) : see declaration of '_snprintf'
2>session.c
1>publickey.c
2>sftp.c
1>scp.c
2>libssh2\src\sftp.c(381) : warning C4244: 'initializing' : conversion from 'time_t' to 'long', possible loss of data
1>libssh2\src\scp.c(292) : warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
2>libssh2\src\sftp.c(1657) : warning C4244: 'return' : conversion from 'libssh2_uint64_t' to 'size_t', possible loss of data
1> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(366) : see declaration of 'sprintf'
1>libssh2\src\scp.c(750) : warning C4244: '=' : conversion from 'long' to 'unsigned short', possible loss of data
1>libssh2\src\scp.c(792) : warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(366) : see declaration of 'sprintf'
1>libssh2\src\scp.c(877) : warning C4996: '_snprintf': This function or variable may be unsafe. Consider using _snprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(358) : see declaration of '_snprintf'
1>libssh2\src\scp.c(939) : warning C4996: '_snprintf': This function or variable may be unsafe. Consider using _snprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(358) : see declaration of '_snprintf'
2>transport.c
1>session.c
1>sftp.c
2>userauth.c
2>libssh2\src\userauth.c(490) : warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
2> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(237) : see declaration of 'fopen'
2>Generating Code...
1>libssh2\src\sftp.c(381) : warning C4244: 'initializing' : conversion from 'time_t' to 'long', possible loss of data
1>libssh2\src\sftp.c(1657) : warning C4244: 'return' : conversion from 'libssh2_uint64_t' to 'size_t', possible loss of data
1>transport.c
2>Build log was saved at "file://libssh2\win32\Debug_dll\BuildLog.htm"
2>libssh2_dll - 8 error(s), 14 warning(s)
1>userauth.c
3>------ Build started: Project: tests, Configuration: Debug Win32 ------
3>Compiling...
1>libssh2\src\userauth.c(490) : warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(237) : see declaration of 'fopen'
3>simple.c
1>channel.c
3>libssh2\include\libssh2.h(566) : error C2061: syntax error : identifier 'libssh2_channel_read_ex'
3>libssh2\include\libssh2.h(566) : error C2059: syntax error : ';'
3>libssh2\include\libssh2.h(566) : error C2059: syntax error : 'type'
3>libssh2\include\libssh2.h(596) : error C2061: syntax error : identifier 'libssh2_channel_write_ex'
3>libssh2\include\libssh2.h(596) : error C2059: syntax error : ';'
3>libssh2\include\libssh2.h(596) : error C2059: syntax error : 'type'
3>Build log was saved at "file://libssh2\win32\Debug\BuildLog.htm"
3>tests - 6 error(s), 0 warning(s)
1>libssh2\src\channel.c(1233) : warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(366) : see declaration of 'sprintf'
1>Generating Code...
1>Build log was saved at "file://libssh2\win32\Debug_lib\BuildLog.htm"
1>libssh2_lib - 8 error(s), 14 warning(s)
========== Build: 0 succeeded, 3 failed, 0 up-to-date, 0 skipped ==========

I think the error level is fine (W3 is good enough), and the warnings it give are all reasonable in fact...

For example a time_t is generally an "unsigned int", but nowadays (as we aproach 2038) this is generally an unsigned long long or so. Converting this to a long might pose problems in the "near" future.

Same goes for the other warnings...

W4 would be way too high, but it might be usefull to have a look at them to see if you might have some very hard to debug errors (like comparing (DWORD)-1==-1 or so):
"conditional expression is constant"
"unreferenced formal parameter"
"'=' : conversion from 'int' to 'char', possible loss of data"
"nonstandard extension, function/data pointer conversion in expression"
"'==' : signed/unsigned mismatch"
"potentially uninitialized local variable 'data' used"

Grtz,
Steven

comment:5 Changed 8 years ago by bagder

any chance you could provide a patch that fixes the warnings?

comment:6 Changed 8 years ago by g00fy

Please find the patch attached. This fixes the warnings on VS2008.
Tested re-compilation on Debian, Mac OSX 10.5, Windows VS 2005 & Windows VS2008.

Grtz,
Steven

Changed 8 years ago by g00fy

comment:7 Changed 8 years ago by bagder

Thanks, parts of your patch have now been applied while parts of it were not (due to me judging those changes to be bad).

Note: See TracTickets for help on using tickets.