Compiling gsoap for x64 with Visual Studio: C4302 conversion: truncation from void* to unsigned int










0















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









share|improve this question
























  • 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
















0















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









share|improve this question
























  • 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














0












0








0








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









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 9:29







wepo

















asked Nov 13 '18 at 16:38









wepowepo

61




61












  • 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

















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













1 Answer
1






active

oldest

votes


















1














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




  1. 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.






share|improve this answer






















    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
    );



    );













    draft saved

    draft discarded


















    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









    1














    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




    1. 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.






    share|improve this answer



























      1














      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




      1. 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.






      share|improve this answer

























        1












        1








        1







        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




        1. 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.






        share|improve this answer













        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




        1. 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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 18 '18 at 14:47









        Dr. Alex REDr. Alex RE

        733617




        733617





























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Use pre created SQLite database for Android project in kotlin

            Darth Vader #20

            Ondo