Compiling gsoap for x64 with Visual Studio: C4302 conversion: truncation from void* to unsigned int
I am trying to compile gsoap with VS 2017 for x64. There's a compiler warning because void*
(64bit address) is casted to unsigned int
(32bit integer). It occurs at h = soap_hash_ptr(p)
where p is the void*
and h is the unsigned int
.
That looks critical - I therefore had a look into stdsoap2.cpp
of the current gsoap version - there however soap_hash_ptr
seems to do the same through PtrToUlong
- I want to keep gsoap which is great - but can I still rely on - possibly yes, because the return value of soap_hash_ptr
is used as an index for an array or vector (either soap->mht
or soap->pht
) - however I am not yet quite shure - can someone give me a hint? Thank you.
- IDE: VS2017
- Target: x64
- gsoap version: Approx year 2005
64bit gsoap
add a comment |
I am trying to compile gsoap with VS 2017 for x64. There's a compiler warning because void*
(64bit address) is casted to unsigned int
(32bit integer). It occurs at h = soap_hash_ptr(p)
where p is the void*
and h is the unsigned int
.
That looks critical - I therefore had a look into stdsoap2.cpp
of the current gsoap version - there however soap_hash_ptr
seems to do the same through PtrToUlong
- I want to keep gsoap which is great - but can I still rely on - possibly yes, because the return value of soap_hash_ptr
is used as an index for an array or vector (either soap->mht
or soap->pht
) - however I am not yet quite shure - can someone give me a hint? Thank you.
- IDE: VS2017
- Target: x64
- gsoap version: Approx year 2005
64bit gsoap
This seems fine to me, sincePtrToUlong
is used to convert a pointer to an int which is then taken moduloSOAP_PTRHASH
(with& (SOAP_PTRHASH-1)
) to index a hash table. This can't possibly go wrong. It's just hashing into a table. I suggest to change the code in stdsoap2.h to#define soap_hash_ptr(p) ((size_t)((PtrToUlong(p) >> 3) & (SOAP_PTRHASH - 1)))
– Dr. Alex RE
Nov 15 '18 at 21:58
add a comment |
I am trying to compile gsoap with VS 2017 for x64. There's a compiler warning because void*
(64bit address) is casted to unsigned int
(32bit integer). It occurs at h = soap_hash_ptr(p)
where p is the void*
and h is the unsigned int
.
That looks critical - I therefore had a look into stdsoap2.cpp
of the current gsoap version - there however soap_hash_ptr
seems to do the same through PtrToUlong
- I want to keep gsoap which is great - but can I still rely on - possibly yes, because the return value of soap_hash_ptr
is used as an index for an array or vector (either soap->mht
or soap->pht
) - however I am not yet quite shure - can someone give me a hint? Thank you.
- IDE: VS2017
- Target: x64
- gsoap version: Approx year 2005
64bit gsoap
I am trying to compile gsoap with VS 2017 for x64. There's a compiler warning because void*
(64bit address) is casted to unsigned int
(32bit integer). It occurs at h = soap_hash_ptr(p)
where p is the void*
and h is the unsigned int
.
That looks critical - I therefore had a look into stdsoap2.cpp
of the current gsoap version - there however soap_hash_ptr
seems to do the same through PtrToUlong
- I want to keep gsoap which is great - but can I still rely on - possibly yes, because the return value of soap_hash_ptr
is used as an index for an array or vector (either soap->mht
or soap->pht
) - however I am not yet quite shure - can someone give me a hint? Thank you.
- IDE: VS2017
- Target: x64
- gsoap version: Approx year 2005
64bit gsoap
64bit gsoap
edited Nov 14 '18 at 9:29
wepo
asked Nov 13 '18 at 16:38
wepowepo
61
61
This seems fine to me, sincePtrToUlong
is used to convert a pointer to an int which is then taken moduloSOAP_PTRHASH
(with& (SOAP_PTRHASH-1)
) to index a hash table. This can't possibly go wrong. It's just hashing into a table. I suggest to change the code in stdsoap2.h to#define soap_hash_ptr(p) ((size_t)((PtrToUlong(p) >> 3) & (SOAP_PTRHASH - 1)))
– Dr. Alex RE
Nov 15 '18 at 21:58
add a comment |
This seems fine to me, sincePtrToUlong
is used to convert a pointer to an int which is then taken moduloSOAP_PTRHASH
(with& (SOAP_PTRHASH-1)
) to index a hash table. This can't possibly go wrong. It's just hashing into a table. I suggest to change the code in stdsoap2.h to#define soap_hash_ptr(p) ((size_t)((PtrToUlong(p) >> 3) & (SOAP_PTRHASH - 1)))
– Dr. Alex RE
Nov 15 '18 at 21:58
This seems fine to me, since
PtrToUlong
is used to convert a pointer to an int which is then taken modulo SOAP_PTRHASH
(with & (SOAP_PTRHASH-1)
) to index a hash table. This can't possibly go wrong. It's just hashing into a table. I suggest to change the code in stdsoap2.h to #define soap_hash_ptr(p) ((size_t)((PtrToUlong(p) >> 3) & (SOAP_PTRHASH - 1)))
– Dr. Alex RE
Nov 15 '18 at 21:58
This seems fine to me, since
PtrToUlong
is used to convert a pointer to an int which is then taken modulo SOAP_PTRHASH
(with & (SOAP_PTRHASH-1)
) to index a hash table. This can't possibly go wrong. It's just hashing into a table. I suggest to change the code in stdsoap2.h to #define soap_hash_ptr(p) ((size_t)((PtrToUlong(p) >> 3) & (SOAP_PTRHASH - 1)))
– Dr. Alex RE
Nov 15 '18 at 21:58
add a comment |
1 Answer
1
active
oldest
votes
The PtrToUlong
is correctly used to truncate the pointer, as this is actually recommended by the Win64 rules for using pointers https://docs.microsoft.com/en-us/windows/desktop/winprog64/rules-for-using-pointers
- Use the PtrToLong or PtrToUlong function to truncate pointers.
If you must truncate a pointer to a 32-bit value, use the PtrToLong or
PtrToUlong function (defined in Basetsd.h). These functions disable
the pointer truncation warning for the duration of the call.
The soap_hash_ptr
macro that you quote is used to compute an index into a hash table:
#if defined(WIN32) && !defined(UNDER_CE)
#define soap_hash_ptr(p) ((PtrToUlong(p) >> 3) & (SOAP_PTRHASH - 1))
#else
#define soap_hash_ptr(p) ((size_t)(((unsigned long)(p) >> 3) & (SOAP_PTRHASH-1)))
#endif
This definition and its use to index a table cannot cause an issues.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53285625%2fcompiling-gsoap-for-x64-with-visual-studio-c4302-conversion-truncation-from-vo%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The PtrToUlong
is correctly used to truncate the pointer, as this is actually recommended by the Win64 rules for using pointers https://docs.microsoft.com/en-us/windows/desktop/winprog64/rules-for-using-pointers
- Use the PtrToLong or PtrToUlong function to truncate pointers.
If you must truncate a pointer to a 32-bit value, use the PtrToLong or
PtrToUlong function (defined in Basetsd.h). These functions disable
the pointer truncation warning for the duration of the call.
The soap_hash_ptr
macro that you quote is used to compute an index into a hash table:
#if defined(WIN32) && !defined(UNDER_CE)
#define soap_hash_ptr(p) ((PtrToUlong(p) >> 3) & (SOAP_PTRHASH - 1))
#else
#define soap_hash_ptr(p) ((size_t)(((unsigned long)(p) >> 3) & (SOAP_PTRHASH-1)))
#endif
This definition and its use to index a table cannot cause an issues.
add a comment |
The PtrToUlong
is correctly used to truncate the pointer, as this is actually recommended by the Win64 rules for using pointers https://docs.microsoft.com/en-us/windows/desktop/winprog64/rules-for-using-pointers
- Use the PtrToLong or PtrToUlong function to truncate pointers.
If you must truncate a pointer to a 32-bit value, use the PtrToLong or
PtrToUlong function (defined in Basetsd.h). These functions disable
the pointer truncation warning for the duration of the call.
The soap_hash_ptr
macro that you quote is used to compute an index into a hash table:
#if defined(WIN32) && !defined(UNDER_CE)
#define soap_hash_ptr(p) ((PtrToUlong(p) >> 3) & (SOAP_PTRHASH - 1))
#else
#define soap_hash_ptr(p) ((size_t)(((unsigned long)(p) >> 3) & (SOAP_PTRHASH-1)))
#endif
This definition and its use to index a table cannot cause an issues.
add a comment |
The PtrToUlong
is correctly used to truncate the pointer, as this is actually recommended by the Win64 rules for using pointers https://docs.microsoft.com/en-us/windows/desktop/winprog64/rules-for-using-pointers
- Use the PtrToLong or PtrToUlong function to truncate pointers.
If you must truncate a pointer to a 32-bit value, use the PtrToLong or
PtrToUlong function (defined in Basetsd.h). These functions disable
the pointer truncation warning for the duration of the call.
The soap_hash_ptr
macro that you quote is used to compute an index into a hash table:
#if defined(WIN32) && !defined(UNDER_CE)
#define soap_hash_ptr(p) ((PtrToUlong(p) >> 3) & (SOAP_PTRHASH - 1))
#else
#define soap_hash_ptr(p) ((size_t)(((unsigned long)(p) >> 3) & (SOAP_PTRHASH-1)))
#endif
This definition and its use to index a table cannot cause an issues.
The PtrToUlong
is correctly used to truncate the pointer, as this is actually recommended by the Win64 rules for using pointers https://docs.microsoft.com/en-us/windows/desktop/winprog64/rules-for-using-pointers
- Use the PtrToLong or PtrToUlong function to truncate pointers.
If you must truncate a pointer to a 32-bit value, use the PtrToLong or
PtrToUlong function (defined in Basetsd.h). These functions disable
the pointer truncation warning for the duration of the call.
The soap_hash_ptr
macro that you quote is used to compute an index into a hash table:
#if defined(WIN32) && !defined(UNDER_CE)
#define soap_hash_ptr(p) ((PtrToUlong(p) >> 3) & (SOAP_PTRHASH - 1))
#else
#define soap_hash_ptr(p) ((size_t)(((unsigned long)(p) >> 3) & (SOAP_PTRHASH-1)))
#endif
This definition and its use to index a table cannot cause an issues.
answered Nov 18 '18 at 14:47
Dr. Alex REDr. Alex RE
733617
733617
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53285625%2fcompiling-gsoap-for-x64-with-visual-studio-c4302-conversion-truncation-from-vo%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
This seems fine to me, since
PtrToUlong
is used to convert a pointer to an int which is then taken moduloSOAP_PTRHASH
(with& (SOAP_PTRHASH-1)
) to index a hash table. This can't possibly go wrong. It's just hashing into a table. I suggest to change the code in stdsoap2.h to#define soap_hash_ptr(p) ((size_t)((PtrToUlong(p) >> 3) & (SOAP_PTRHASH - 1)))
– Dr. Alex RE
Nov 15 '18 at 21:58