Skip to content
  • Arne Schwabe's avatar
    Fix multiple problems when compiling with LLVM/Windows (clang-cl) · 45e7d412
    Arne Schwabe authored
    
    
    When using the LLVM clang compiler instead the MSVC cl.exe but with
    the same build environment as MSVC, clang encounters a few errors:
    
    src\openvpn\socket.c(3550,23): warning: assigning to 'CHAR *' (aka 'char
    *') from 'uint8_t *' (aka 'unsigned char *') converts between pointers to
    integer types with different sign [-Wpointer-sign]
            wsabuf[0].buf = BPTR(&sock->reads.buf);
                          ^ ~~~~~~~~~~~~~~~~~~~~~~
    src\openvpn\socket.c(3670,23): warning: assigning to 'CHAR *' (aka 'char
    *') from 'uint8_t *' (aka 'unsigned char *') converts between pointers to
    integer types with different sign [-Wpointer-sign]
            wsabuf[0].buf = BPTR(&sock->writes.buf);
                          ^ ~~~~~~~~~~~~~~~~~~~~~~~
    
    Use BSTR instead of BPTR, which casts to the correct type that is
    expected.
    
    src\compat\compat-gettimeofday.c(105,18): error: assignment to cast is
    illegal, lvalue casts are not supported
        tv->tv_sec = (long)last_sec = (long)sec;
    
    Split into two assignments to avoid the illegal cast
    
    include\stdint.h(18,28): error: typedef redefinition with different types
    ('signed char' vs 'char')
    typedef signed char        int8_t;
                               ^
    openvpn\config-msvc.h(162,16): note: previous definition is here
    typedef __int8 int8_t;
    
    Removes our custom int type typdefs from config-msvc.h and replace it
    with an include of inttypes.h.
    
    C:\Program Files (x86)\Windows
    Kits\10\include\10.0.19041.0\shared\tcpmib.h(56,3): error: typedef
    redefinition with different types ('enum MIB_TCP_STATE' vs 'int')
    } MIB_TCP_STATE;
      ^
    C:\Users\User\source\repos\openvpn\src\openvpn/syshead.h(369,13): note:
    previous definition is here
    typedef int MIB_TCP_STATE;
                ^
    1 error generated.
    
    This seems to be for mingw32 only, so guard this with a mingw32
    compiler guard.
    
    \src\openvpn\tun.c(3727,34): warning: passing 'char [256]' to parameter of
    type 'LPBYTE' (aka 'unsigned char *') converts between pointers to integer
    types with different sign [-Wpointer-sign]
                                     net_cfg_instance_id,
                                     ^~~~~~~~~~~~~~~~~~~
    C:\Program Files (x86)\Windows
    Kits\10\include\10.0.19041.0\um\winreg.h(955,88): note: passing argument
    to parameter 'lpData' here
    
    This is windows specific code, use the Windows LPBTYE in the
    definitions. (long pointer to BYTE (long pointer as far/near pointer
    relict from windows 16 bit times, in moddern words (unsigned char *))
    
    Fix also a few other char vs uint8/unisgned char/BYTE issues in tun.c
    
    Signed-off-by: default avatarArne Schwabe <arne@rfc2549.org>
    Acked-by: default avatarGert Doering <gert@greenie.muc.de>
    Message-Id: <20210319114631.20459-1-arne@rfc2549.org>
    URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg21719.html
    
    
    Signed-off-by: default avatarGert Doering <gert@greenie.muc.de>
    45e7d412