Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiling 'Packet32.cpp' with '-std:c++20' #752

Open
gvanem opened this issue Sep 26, 2024 · 1 comment
Open

Compiling 'Packet32.cpp' with '-std:c++20' #752

gvanem opened this issue Sep 26, 2024 · 1 comment

Comments

@gvanem
Copy link

gvanem commented Sep 26, 2024

The default C++ standard in cl is C++14. And using that for packetWin7/Dll/Packet32.cpp works fine.
But using -std:c++20 or -std:c++latest does not. This is what I did:

cd packetWin7\Dll\Project
set CL=-std:c++20
msbuild -nologo -p:Configuration=Release -p:Platform="x64" Packet.sln

The errors generated by MSVC version 19.42.34321.1 for x64 (the latest):

Packet32.cpp(414): error C2362: initialization of 'nFields' is skipped by 'goto Exit'
Packet32.cpp(422): note: see declaration of 'Exit'
Packet32.cpp(3369): error C2362: initialization of 'numEntries' is skipped by 'goto END_PacketGetNetInfoEx'
Packet32.cpp(3417): note: see declaration of 'END_PacketGetNetInfoEx'
Packet32.cpp(3368): error C2362: initialization of 'pAddr' is skipped by 'goto END_PacketGetNetInfoEx'
Packet32.cpp(3417): note: see declaration of 'END_PacketGetNetInfoEx'
Packet32.cpp(3314): error C2362: initialization of 'RetVal' is skipped by 'goto END_PacketGetNetInfoEx'
Packet32.cpp(3417): note: see declaration of 'END_PacketGetNetInfoEx'
Packet32.cpp(3301): error C2362: initialization of 'AdapterGuid' is skipped by 'goto END_PacketGetNetInfoEx'
Packet32.cpp(3417): note: see declaration of 'END_PacketGetNetInfoEx'

Googling this issue seems to be related to option /Za which is not in use.

And further, using -std:c++20 or -std:c++latest with clang-cl ver. 18.1 works just fine.
So I'm not sure what is the real issue with the Packet32.cpp code.

@gvanem
Copy link
Author

gvanem commented Sep 26, 2024

So I'm not sure what is the real issue with the Packet32.cpp code.

A fix for this was to move some variables to the top:

--- a/Packet32.cpp 2024-08-04 08:43:33
+++ b/Packet32.cpp 2024-09-26 12:30:29
@@ -347,6 +347,7 @@
        BOOL   fSuccess = FALSE;
        DWORD  cbRead, cbToWrite, cbWritten, dwMode;
        HANDLE hPipe = g_hNpcapHelperPipe;
+       int nFields;

        TRACE_ENTER();

@@ -411,7 +412,7 @@
                goto Exit;
        }

-       int nFields = _snscanf_s(chBuf, cbRead, "%p,%lu", &hd, pdwError);
+       nFields = _snscanf_s(chBuf, cbRead, "%p,%lu", &hd, pdwError);
        if (nFields != 2)
        {
                *pdwError = ERROR_OPEN_FAILED;
@@ -3218,6 +3219,10 @@
        PCHAR Tname = NULL;
        BOOLEAN Res = FALSE;
        DWORD err = ERROR_SUCCESS;
+       LONG numEntries;
+       PIP_ADAPTER_UNICAST_ADDRESS pAddr;
+       PCCH AdapterGuid;
+       ULONG RetVal;

        TRACE_ENTER();

@@ -3298,7 +3303,7 @@
                goto END_PacketGetNetInfoEx;
        }

-       PCCH AdapterGuid = strchr(AdapterName, '{');
+       AdapterGuid = strchr(AdapterName, '{');
        if (AdapterGuid == NULL)
        {
                err = ERROR_INVALID_NAME;
@@ -3311,7 +3316,7 @@
                err = ERROR_NOT_ENOUGH_MEMORY;
                goto END_PacketGetNetInfoEx;
        }
-       ULONG RetVal = ERROR_SUCCESS;
+       RetVal = ERROR_SUCCESS;
        for (int i = 0; i < ADAPTERS_ADDRESSES_MAX_TRIES; i++)
        {

@@ -3365,8 +3370,8 @@

        // else found!
        Res = TRUE;
-       PIP_ADAPTER_UNICAST_ADDRESS pAddr = TmpAddr->FirstUnicastAddress;
-       LONG numEntries = 0;
+       pAddr = TmpAddr->FirstUnicastAddress;
+       numEntries = 0;
        while (pAddr != NULL && numEntries < *NEntries)
        {
                ULONG ul = 0;

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

No branches or pull requests

1 participant