Skip to content

example, tests: address compiler warnings - #861

Closed
vszakats wants to merge 19 commits into
libssh2:masterfrom
vszakats:compiler-warnings-example-tests
Closed

vszakats wants to merge 19 commits into
libssh2:masterfrom
vszakats:compiler-warnings-example-tests

Conversation

@vszakats

@vszakats vszakats commented Mar 20, 2023 •

Copy link
Copy Markdown
Member

Fix or silence all C compiler warnings discovered with (or without)
PICKY_COMPILER=ON (in CMake). This means all warnings showing up in
CI (gcc, clang, MSVS 2013/2015), in local tests on macOS (clang 14) and
Windows cross-builds using gcc (12) and llvm/clang (14/15).

Also fix the expression nread -= nread in sftp_RW_nonblock.c.

Cherry-picked from: #846
Closes #861


Partial list of warnings fixed:

tests/session_fixture.c:97:12: warning: assigning to 'char *' from 'const char[...]' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
tests/session_fixture.c:97:12: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
example/subsystem_netconf.c:63:..: warning C4244: '=': conversion from 'ssize_t' to 'int', possible loss of data
example/subsystem_netconf.c:63:13: warning: implicit conversion loses integer precision: 'ssize_t' (aka 'long long') to 'int' [-Wshorten-64-to-32]
example/subsystem_netconf.c:63:13: warning: implicit conversion loses integer precision: 'ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
example/subsystem_netconf.c:114:..: warning C4267: 'return': conversion from 'size_t' to 'int', possible loss of data
example/subsystem_netconf.c:114:12: warning: conversion from 'size_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
example/subsystem_netconf.c:114:12: warning: conversion from 'size_t' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
example/subsystem_netconf.c:114:12: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long long') to 'int' [-Wshorten-64-to-32]
example/subsystem_netconf.c:114:12: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int' [-Wshorten-64-to-32]
example/sftp_append.c:216:..: warning C4244: '=': conversion from 'ssize_t' to 'int', possible loss of data
example/sftp_append.c:216:18: warning: conversion from 'ssize_t' {aka 'long int'} to 'int' may change value [-Wconversion]
example/sftp_append.c:216:18: warning: conversion from 'ssize_t' {aka 'long long int'} to 'int' may change value [-Wconversion]
example/sftp_append.c:216:18: warning: implicit conversion loses integer precision: 'ssize_t' (aka 'long long') to 'int' [-Wshorten-64-to-32]
example/sftp_append.c:216:18: warning: implicit conversion loses integer precision: 'ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
tests/openssh_fixture.c:116:..: warning C4267: 'function': conversion from 'size_t' to 'int', possible loss of data
tests/openssh_fixture.c:116:42: warning: conversion from 'long long unsigned int' to 'int' may change value [-Wconversion]
tests/openssh_fixture.c:116:42: warning: conversion from 'long unsigned int' to 'int' may change value [-Wconversion]
tests/openssh_fixture.c:116:42: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
tests/openssh_fixture.c:116:42: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
example/scp_write_nonblock.c:262:29: warning: implicit conversion from 'long' to 'double' may lose precision [-Wimplicit-int-float-conversion]
example/scp_write_nonblock.c:262:34: warning: conversion from 'long int' to 'double' may change value [-Wconversion]
example/sftp_write_nonblock.c:272:29: warning: implicit conversion from 'long' to 'double' may lose precision [-Wimplicit-int-float-conversion]
example/sftp_write_nonblock.c:272:34: warning: conversion from 'long int' to 'double' may change value [-Wconversion]
example/sftp_write_sliding.c:282:29: warning: implicit conversion from 'long' to 'double' may lose precision [-Wimplicit-int-float-conversion]
example/sftp_write_sliding.c:282:34: warning: conversion from 'long int' to 'double' may change value [-Wconversion]
example/direct_tcpip.c:264:..: warning C4244: 'function': conversion from 'libssh2_socket_t' to 'int', possible loss of data
example/direct_tcpip.c:264:33: warning: conversion from 'libssh2_socket_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
example/direct_tcpip.c:264:33: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
example/scp_nonblock.c:81:..: warning C4244: 'function': conversion from 'libssh2_socket_t' to 'int', possible loss of data
example/scp_nonblock.c:81:27: warning: conversion from 'libssh2_socket_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
example/scp_nonblock.c:81:27: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
example/scp_write_nonblock.c:68:..: warning C4244: 'function': conversion from 'libssh2_socket_t' to 'int', possible loss of data
example/scp_write_nonblock.c:68:27: warning: conversion from 'libssh2_socket_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
example/scp_write_nonblock.c:68:27: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
example/sftp_RW_nonblock.c:75:..: warning C4244: 'function': conversion from 'libssh2_socket_t' to 'int', possible loss of data
example/sftp_RW_nonblock.c:75:27: warning: conversion from 'libssh2_socket_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
example/sftp_RW_nonblock.c:75:27: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
example/sftp_RW_nonblock.c:268:..: warning C4244: 'function': conversion from 'libssh2_socket_t' to 'int', possible loss of data
example/sftp_RW_nonblock.c:268:26: warning: conversion from 'libssh2_socket_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
example/sftp_RW_nonblock.c:268:26: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
example/sftp_RW_nonblock.c:328:..: warning C4244: 'function': conversion from 'libssh2_socket_t' to 'int', possible loss of data
example/sftp_RW_nonblock.c:328:30: warning: conversion from 'libssh2_socket_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
example/sftp_RW_nonblock.c:328:30: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
example/sftp_nonblock.c:86:..: warning C4244: 'function': conversion from 'libssh2_socket_t' to 'int', possible loss of data
example/sftp_nonblock.c:86:27: warning: conversion from 'libssh2_socket_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
example/sftp_nonblock.c:86:27: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
example/sftp_write_nonblock.c:74:..: warning C4244: 'function': conversion from 'libssh2_socket_t' to 'int', possible loss of data
example/sftp_write_nonblock.c:74:27: warning: conversion from 'libssh2_socket_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
example/sftp_write_nonblock.c:74:27: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
example/sftp_write_sliding.c:74:..: warning C4244: 'function': conversion from 'libssh2_socket_t' to 'int', possible loss of data
example/sftp_write_sliding.c:74:27: warning: conversion from 'libssh2_socket_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
example/sftp_write_sliding.c:74:27: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
example/ssh2_agent_forwarding.c:79:..: warning C4244: 'function': conversion from 'libssh2_socket_t' to 'int', possible loss of data
example/ssh2_agent_forwarding.c:79:27: warning: conversion from 'libssh2_socket_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
example/ssh2_agent_forwarding.c:79:27: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
example/ssh2_echo.c:75:..: warning C4244: 'function': conversion from 'libssh2_socket_t' to 'int', possible loss of data
example/ssh2_echo.c:75:27: warning: conversion from 'libssh2_socket_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
example/ssh2_echo.c:75:27: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
example/ssh2_exec.c:77:..: warning C4244: 'function': conversion from 'libssh2_socket_t' to 'int', possible loss of data
example/ssh2_exec.c:77:27: warning: conversion from 'libssh2_socket_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
example/ssh2_exec.c:77:27: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
example/tcpip-forward.c:254:..: warning C4244: 'function': conversion from 'libssh2_socket_t' to 'int', possible loss of data
example/tcpip-forward.c:254:33: warning: conversion from 'libssh2_socket_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
example/tcpip-forward.c:254:33: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]

linux / clang / x64:

scp_nonblock.c:279:63: error: format specifies type 'long long' but the argument has type 'libssh2_struct_stat_size' (aka 'long') [-Werror,-Wformat]
                    " in %ld ms = %.1f bytes/sec spin: %d\n", total,
                                                              ^~~~~
1 error generated.

Ref: https://github.com/libssh2/libssh2/actions/runs/4436663090/jobs/7785373909

gcc:

sftpdir.c:287:28: warning: unknown conversion type character 'I' in format [-Wformat=]
  287 |                     printf("%8" __FILESIZE " ", attrs.filesize);
      |                            ^~~~
sftpdir.c:50:21: note: format string is defined here
   50 | #define __FILESIZE "I64u"
      |                     ^
sftpdir.c:287:28: warning: too many arguments for format [-Wformat-extra-args]
  287 |                     printf("%8" __FILESIZE " ", attrs.filesize);
      |                            ^~~~
sftpdir_nonblock.c:227:24: warning: unknown conversion type character 'I' in format [-Wformat=]
  227 |                 printf("%8" __FILESIZE " ", attrs.filesize);
      |                        ^~~~
sftpdir_nonblock.c:50:21: note: format string is defined here
   50 | #define __FILESIZE "I64u"
      |                     ^
sftpdir_nonblock.c:227:24: warning: too many arguments for format [-Wformat-extra-args]
  227 |                 printf("%8" __FILESIZE " ", attrs.filesize);
      |                        ^~~~
example/scp.c:96:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/scp.c:96:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/scp_nonblock.c:150:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/scp_nonblock.c:150:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/scp_write.c:119:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/scp_write.c:119:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/scp_write_nonblock.c:149:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/scp_write_nonblock.c:149:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/sftp.c:160:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/sftp.c:160:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/sftp_append.c:114:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/sftp_append.c:114:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/sftp_mkdir.c:98:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/sftp_mkdir.c:98:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/sftp_mkdir_nonblock.c:98:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/sftp_mkdir_nonblock.c:98:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/sftp_nonblock.c:155:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/sftp_nonblock.c:155:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/sftp_write.c:113:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/sftp_write.c:113:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/sftp_write_nonblock.c:153:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/sftp_write_nonblock.c:153:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/sftp_write_sliding.c:153:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/sftp_write_sliding.c:153:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/sftpdir.c:134:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/sftpdir.c:134:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/sftpdir_nonblock.c:114:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/sftpdir_nonblock.c:114:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/ssh2.c:128:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/ssh2.c:128:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/ssh2_agent.c:100:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/ssh2_agent.c:100:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/ssh2_agent_forwarding.c:133:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/ssh2_agent_forwarding.c:133:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/ssh2_echo.c:139:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/ssh2_echo.c:139:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/ssh2_exec.c:143:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/ssh2_exec.c:143:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
tests/openssh_fixture.c:395:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
tests/openssh_fixture.c:395:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]

vszakats added 19 commits March 20, 2023 13:19
```
tests/session_fixture.c:97:12: warning: assigning to 'char *' from 'const char[...]' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
tests/session_fixture.c:97:12: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
```
```
example/subsystem_netconf.c:63:..: warning C4244: '=': conversion from 'ssize_t' to 'int', possible loss of data
example/subsystem_netconf.c:63:13: warning: implicit conversion loses integer precision: 'ssize_t' (aka 'long long') to 'int' [-Wshorten-64-to-32]
example/subsystem_netconf.c:63:13: warning: implicit conversion loses integer precision: 'ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
example/subsystem_netconf.c:114:..: warning C4267: 'return': conversion from 'size_t' to 'int', possible loss of data
example/subsystem_netconf.c:114:12: warning: conversion from 'size_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
example/subsystem_netconf.c:114:12: warning: conversion from 'size_t' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
example/subsystem_netconf.c:114:12: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long long') to 'int' [-Wshorten-64-to-32]
example/subsystem_netconf.c:114:12: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int' [-Wshorten-64-to-32]
```
```
example/sftp_append.c:216:..: warning C4244: '=': conversion from 'ssize_t' to 'int', possible loss of data
example/sftp_append.c:216:18: warning: conversion from 'ssize_t' {aka 'long int'} to 'int' may change value [-Wconversion]
example/sftp_append.c:216:18: warning: conversion from 'ssize_t' {aka 'long long int'} to 'int' may change value [-Wconversion]
example/sftp_append.c:216:18: warning: implicit conversion loses integer precision: 'ssize_t' (aka 'long long') to 'int' [-Wshorten-64-to-32]
example/sftp_append.c:216:18: warning: implicit conversion loses integer precision: 'ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
```
Also fix `nread -= nread` in `sftp_RW_nonblock.c`.
```
tests/openssh_fixture.c:116:..: warning C4267: 'function': conversion from 'size_t' to 'int', possible loss of data
tests/openssh_fixture.c:116:42: warning: conversion from 'long long unsigned int' to 'int' may change value [-Wconversion]
tests/openssh_fixture.c:116:42: warning: conversion from 'long unsigned int' to 'int' may change value [-Wconversion]
tests/openssh_fixture.c:116:42: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
tests/openssh_fixture.c:116:42: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
```
```
example/scp_write_nonblock.c:262:29: warning: implicit conversion from 'long' to 'double' may lose precision [-Wimplicit-int-float-conversion]
example/scp_write_nonblock.c:262:34: warning: conversion from 'long int' to 'double' may change value [-Wconversion]
example/sftp_write_nonblock.c:272:29: warning: implicit conversion from 'long' to 'double' may lose precision [-Wimplicit-int-float-conversion]
example/sftp_write_nonblock.c:272:34: warning: conversion from 'long int' to 'double' may change value [-Wconversion]
example/sftp_write_sliding.c:282:29: warning: implicit conversion from 'long' to 'double' may lose precision [-Wimplicit-int-float-conversion]
example/sftp_write_sliding.c:282:34: warning: conversion from 'long int' to 'double' may change value [-Wconversion]
```
It's an unused arg on that platform.

```
example/direct_tcpip.c:264:..: warning C4244: 'function': conversion from 'libssh2_socket_t' to 'int', possible loss of data
example/direct_tcpip.c:264:33: warning: conversion from 'libssh2_socket_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
example/direct_tcpip.c:264:33: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
example/scp_nonblock.c:81:..: warning C4244: 'function': conversion from 'libssh2_socket_t' to 'int', possible loss of data
example/scp_nonblock.c:81:27: warning: conversion from 'libssh2_socket_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
example/scp_nonblock.c:81:27: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
example/scp_write_nonblock.c:68:..: warning C4244: 'function': conversion from 'libssh2_socket_t' to 'int', possible loss of data
example/scp_write_nonblock.c:68:27: warning: conversion from 'libssh2_socket_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
example/scp_write_nonblock.c:68:27: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
example/sftp_RW_nonblock.c:75:..: warning C4244: 'function': conversion from 'libssh2_socket_t' to 'int', possible loss of data
example/sftp_RW_nonblock.c:75:27: warning: conversion from 'libssh2_socket_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
example/sftp_RW_nonblock.c:75:27: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
example/sftp_RW_nonblock.c:268:..: warning C4244: 'function': conversion from 'libssh2_socket_t' to 'int', possible loss of data
example/sftp_RW_nonblock.c:268:26: warning: conversion from 'libssh2_socket_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
example/sftp_RW_nonblock.c:268:26: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
example/sftp_RW_nonblock.c:328:..: warning C4244: 'function': conversion from 'libssh2_socket_t' to 'int', possible loss of data
example/sftp_RW_nonblock.c:328:30: warning: conversion from 'libssh2_socket_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
example/sftp_RW_nonblock.c:328:30: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
example/sftp_nonblock.c:86:..: warning C4244: 'function': conversion from 'libssh2_socket_t' to 'int', possible loss of data
example/sftp_nonblock.c:86:27: warning: conversion from 'libssh2_socket_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
example/sftp_nonblock.c:86:27: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
example/sftp_write_nonblock.c:74:..: warning C4244: 'function': conversion from 'libssh2_socket_t' to 'int', possible loss of data
example/sftp_write_nonblock.c:74:27: warning: conversion from 'libssh2_socket_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
example/sftp_write_nonblock.c:74:27: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
example/sftp_write_sliding.c:74:..: warning C4244: 'function': conversion from 'libssh2_socket_t' to 'int', possible loss of data
example/sftp_write_sliding.c:74:27: warning: conversion from 'libssh2_socket_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
example/sftp_write_sliding.c:74:27: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
example/ssh2_agent_forwarding.c:79:..: warning C4244: 'function': conversion from 'libssh2_socket_t' to 'int', possible loss of data
example/ssh2_agent_forwarding.c:79:27: warning: conversion from 'libssh2_socket_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
example/ssh2_agent_forwarding.c:79:27: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
example/ssh2_echo.c:75:..: warning C4244: 'function': conversion from 'libssh2_socket_t' to 'int', possible loss of data
example/ssh2_echo.c:75:27: warning: conversion from 'libssh2_socket_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
example/ssh2_echo.c:75:27: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
example/ssh2_exec.c:77:..: warning C4244: 'function': conversion from 'libssh2_socket_t' to 'int', possible loss of data
example/ssh2_exec.c:77:27: warning: conversion from 'libssh2_socket_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
example/ssh2_exec.c:77:27: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
example/tcpip-forward.c:254:..: warning C4244: 'function': conversion from 'libssh2_socket_t' to 'int', possible loss of data
example/tcpip-forward.c:254:33: warning: conversion from 'libssh2_socket_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
example/tcpip-forward.c:254:33: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
```
cast to long instead. LIBSSH2_STRUCT_STAT_SIZE_FORMAT generates
warnings and/or errors depending on platform.

linux / clang / x64:
```
scp_nonblock.c:279:63: error: format specifies type 'long long' but the argument has type 'libssh2_struct_stat_size' (aka 'long') [-Werror,-Wformat]
                    " in %ld ms = %.1f bytes/sec spin: %d\n", total,
                                                              ^~~~~
1 error generated.
```
Ref: https://github.com/libssh2/libssh2/actions/runs/4436663090/jobs/7785373909
gcc: (clang was OK)
```
sftpdir.c:287:28: warning: unknown conversion type character 'I' in format [-Wformat=]
  287 |                     printf("%8" __FILESIZE " ", attrs.filesize);
      |                            ^~~~
sftpdir.c:50:21: note: format string is defined here
   50 | #define __FILESIZE "I64u"
      |                     ^
sftpdir.c:287:28: warning: too many arguments for format [-Wformat-extra-args]
  287 |                     printf("%8" __FILESIZE " ", attrs.filesize);
      |                            ^~~~
sftpdir_nonblock.c:227:24: warning: unknown conversion type character 'I' in format [-Wformat=]
  227 |                 printf("%8" __FILESIZE " ", attrs.filesize);
      |                        ^~~~
sftpdir_nonblock.c:50:21: note: format string is defined here
   50 | #define __FILESIZE "I64u"
      |                     ^
sftpdir_nonblock.c:227:24: warning: too many arguments for format [-Wformat-extra-args]
  227 |                 printf("%8" __FILESIZE " ", attrs.filesize);
      |                        ^~~~
```
Fixes:
```
example/scp.c:96:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/scp.c:96:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/scp_nonblock.c:150:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/scp_nonblock.c:150:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/scp_write.c:119:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/scp_write.c:119:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/scp_write_nonblock.c:149:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/scp_write_nonblock.c:149:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/sftp.c:160:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/sftp.c:160:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/sftp_append.c:114:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/sftp_append.c:114:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/sftp_mkdir.c:98:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/sftp_mkdir.c:98:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/sftp_mkdir_nonblock.c:98:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/sftp_mkdir_nonblock.c:98:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/sftp_nonblock.c:155:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/sftp_nonblock.c:155:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/sftp_write.c:113:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/sftp_write.c:113:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/sftp_write_nonblock.c:153:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/sftp_write_nonblock.c:153:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/sftp_write_sliding.c:153:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/sftp_write_sliding.c:153:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/sftpdir.c:134:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/sftpdir.c:134:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/sftpdir_nonblock.c:114:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/sftpdir_nonblock.c:114:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/ssh2.c:128:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/ssh2.c:128:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/ssh2_agent.c:100:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/ssh2_agent.c:100:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/ssh2_agent_forwarding.c:133:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/ssh2_agent_forwarding.c:133:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/ssh2_echo.c:139:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/ssh2_echo.c:139:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
example/ssh2_exec.c:143:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
example/ssh2_exec.c:143:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
tests/openssh_fixture.c:395:27: warning: conversion from 'long unsigned int' to 'in_addr_t' {aka 'unsigned int'} may change value [-Wconversion]
tests/openssh_fixture.c:395:27: warning: implicit conversion loses integer precision: 'unsigned long' to 'in_addr_t' (aka 'unsigned int') [-Wshorten-64-to-32]
```
@vszakats vszakats mentioned this pull request Mar 20, 2023
6 tasks done
@vszakats vszakats closed this in b13936b Mar 20, 2023
@vszakats
vszakats deleted the compiler-warnings-example-tests branch March 20, 2023 15:55
vszakats added a commit to vszakats/libssh2 that referenced this pull request Jun 25, 2023
Regression from b13936b libssh2#861 libssh2#846.
Update a variable name missed in above.

Reported-by: PewPewPew
Fixes libssh2#1105
Closes libssh2#1106
vszakats added a commit that referenced this pull request Jun 25, 2023
Regression from b13936b #861 #846.
Update a variable name missed above.

Reported-by: PewPewPew
Fixes #1105
Closes #1106
lampmanyao pushed a commit to lampmanyao/libssh2 that referenced this pull request Jul 16, 2023
Regression from b13936b libssh2#861 libssh2#846.
Update a variable name missed above.

Reported-by: PewPewPew
Fixes libssh2#1105
Closes libssh2#1106
agreppin pushed a commit to agreppin/libssh2 that referenced this pull request Jul 14, 2024
Fix or silence all C compiler warnings discovered with (or without)
`PICKY_COMPILER=ON` (in CMake). This means all warnings showing up in
CI (gcc, clang, MSVS 2013/2015), in local tests on macOS (clang 14) and
Windows cross-builds using gcc (12) and llvm/clang (14/15).

Also fix the expression `nread -= nread` in `sftp_RW_nonblock.c`.

Cherry-picked from: libssh2#846
Closes libssh2#861
agreppin pushed a commit to agreppin/libssh2 that referenced this pull request Jul 14, 2024
Regression from b13936b libssh2#861 libssh2#846.
Update a variable name missed above.

Reported-by: PewPewPew
Fixes libssh2#1105
Closes libssh2#1106
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant