okdshin / PicoSHA2

a header-file-only, SHA256 hash generator in C++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

warning C4244: 'argument': conversion from '__int64' to 'picosha2::word_t', possible loss of data

tjpalmer opened this issue · comments

commented

Under msvc 2017 on x86_64, I get the following warning:

warning C4244: 'argument': conversion from '__int64' to 'picosha2::word_t', possible loss of data
picosha2.h(291): note: see reference to function template instantiation 'void picosha2::hash256_one_by_one::process<RaIter>(RaIter,RaIter)' being compiled
          with
          [
              RaIter=std::_String_const_iterator<std::_String_val<std::_Simple_types<char>>>
          ]
  picosha2.h(323): note: see reference to function template instantiation 'void picosha2::impl::hash256_impl<InIter,OutIter>(RaIter,RaIter,OutIter,OutIter,int,std::random_access_iterator_tag)' being compiled
          with
          [
              InIter=std::_String_const_iterator<std::_String_val<std::_Simple_types<char>>>,
              OutIter=picosha2::byte_t *,
              RaIter=std::_String_const_iterator<std::_String_val<std::_Simple_types<char>>>
          ]
  picosha2.h(344): note: see reference to function template instantiation 'void picosha2::hash256<InIter,picosha2::byte_t*>(InIter,InIter,OutIter,OutIter,int)' being compiled
          with
          [
              InIter=std::_String_const_iterator<std::_String_val<std::_Simple_types<char>>>,
              OutIter=picosha2::byte_t *
          ]
  picosha2.h(358): note: see reference to function template instantiation 'void picosha2::hash256_hex_string<std::_String_const_iterator<std::_String_val<std::_Simple_types<_Ty>>>>(InIter,InIter,std::string &)' being compiled
          with
          [
              _Ty=char,
              InIter=std::_String_const_iterator<std::_String_val<std::_Simple_types<char>>>
          ]

The same warning doesn't happen on x86. I also don't see any such warnings on gcc.

Hi! @tjpalmer! Thanks for your report. I made modified code but I can't check it working fine because I don't have MSVC environment.
So, could you try this branch? And please tell me the result.

commented

Thanks much! I tried the branch, and the warning is gone. To clarify, I still got correct results before (based on comparing against an online site that does calculations). And I get the same results now (which is good), although I see you updated the logic. I was wondering if perhaps it was a bogus warning that just needed silenced. Like maybe you were already only using portions of an int64 value. (I haven't tried to decode the logic myself much.)

Anyway, if you still pass unit tests and are happy with the changes, I'm good, too, since it makes the warning go away. I just wanted to mention this in case it matters at all.

commented

And I haven't done thorough testing, so maybe there are cases where the old logic fails. Don't know. I'm just referring to the few cases I happen to have tested myself.

commented

And sorry for too many comments, but it also looks like your own unit tests pass both before and after the changes on windows 64-bit, so far as I am interpreting the output correctly.

Thank you very much @tjpalmer!
I designed PicoSHA2 to be available for 32bit OS. So as you know, the maximum size of data to be processed once is limited to 2^32.
In other words, I supposed that users do not put a data over 4GB(<2^32) on memory once (for file, PicoSHA2 automatically splits it into 1MB(default) data set).
PicoSHA2 is very naive implementation of sha256 so the speed is not better than other brilliant hash computation libraries especially for huge data. Yeah, I concentrated the usability (one header file only, STL friendly, hex string conversion...).
So if you are going to hash some huge data, sorry, I recommend you to use some other fast implementation using SIMD rather than PicoSHA2.
Well, anyway, now PicoSHA2 can process over 2^32 bytes data once, test is needed for it even it takes a long time to process.
I will add travis-ci files in a few days.

commented

For my purposes, the speed is fine. Thanks!