Page MenuHomePhabricator

Access violation with MinGW-W64
Closed, ResolvedPublic

Description

In the current master branch, the format specifier "%zu" is used in "channels.c".

SSH_LOG(SSH_LOG_PACKET,
          "placing %to bytes into channel buffer (%s)"
          len,
          is_stderr ? "stderr" : "stdout");

"%zu" is supported from Visual Studio 2013 on, but MinGW-W64 uses the msvcrt.dll ( on my system Windows 8.1 this is version 7.0.9600.17415 ) and with this version "%zu" is not supported. This will probably be the old Visual Studio 6 Runtime.

So you get an access violation if you run libssh with the loglevel "SSH_LOG_PACKET or SSH_LOG_DEBUG".

To use the format specifier "%zu" with the MinGW the compiler flag "__USE_MINGW_ANSI_STDIO" must be set.

Use "__USE_MINGW_ANSI_STDIO" :

Use "-Dsnprintf=mingw_snprintf -Dvsnprintf=mingw_vsnprintf "

Use "_POSIX"

Use "_POSIX_SOURCE"

Revisions and Commits

Event Timeline

davidwed created this task.May 5 2020, 2:57 PM
davidwed updated the task description. (Show Details)May 5 2020, 3:02 PM
davidwed renamed this task from Access violation with MinGW to Access violation with MinGW64.May 7 2020, 4:49 PM
davidwed updated the task description. (Show Details)
davidwed renamed this task from Access violation with MinGW64 to Access violation with MinGW-W64.May 7 2020, 4:52 PM
davidwed updated the task description. (Show Details)
davidwed updated the task description. (Show Details)May 11 2020, 12:36 AM
davidwed updated the task description. (Show Details)May 11 2020, 8:32 AM
davidwed updated the task description. (Show Details)May 15 2020, 11:09 AM
chcg added a subscriber: chcg.EditedSep 20 2020, 10:33 AM

From https://github.com/ashkulz/NppFTP/pull/292
Build with https://git.libssh.org/projects/libssh.git/snapshot/libssh-b1bbd20dfa8adc784c03fa74d8c81c30671d011b.tar.gz
-> https://travis-ci.org/github/ashkulz/NppFTP/builds/728703640

before the change with _POSIX_SOURCE and after https://git.libssh.org/projects/libssh.git/snapshot/libssh-dcc0b9d7aa092bd4bc9f50273e40a3777f9f8c5e.tar.gz
->
https://travis-ci.org/github/ashkulz/NppFTP/jobs/728704634

Maybe the issue is arising with usage of the posix variant of the compilers instead of the default win32:

update-alternatives: using /usr/bin/i686-w64-mingw32-g++-posix to provide /usr/bin/i686-w64-mingw32-g++ (i686-w64-mingw32-g++) in manual mode

update-alternatives: using /usr/bin/i686-w64-mingw32-gcc-posix to provide /usr/bin/i686-w64-mingw32-gcc (i686-w64-mingw32-gcc) in manual mode

update-alternatives: using /usr/bin/x86_64-w64-mingw32-g++-posix to provide /usr/bin/x86_64-w64-mingw32-g++ (x86_64-w64-mingw32-g++) in manual mode

update-alternatives: using /usr/bin/x86_64-w64-mingw32-gcc-posix to provide /usr/bin/x86_64-w64-mingw32-gcc (x86_64-w64-mingw32-gcc) in manual mode

See also https://manpages.ubuntu.com/manpages/focal/man7/feature_test_macros.7.html
, so the obsolete macro _POSIX_SOURCE is equivalent to _POSIX_C_SOURCE = 1 and therefore threads are missing.