Boost logo

Boost Users :

Subject: Re: [Boost-users] [crc] bug in boost::crc
From: U.Mutlu (for-gmane_at_[hidden])
Date: 2015-07-09 17:18:00


Hurcan Solter wrote on 07/09/2015 10:21 PM:
> So,you are initializing the crc with a different value(result from previous
> loop) and expecting the same result?

I don't think so, but if you know how to use it correctly let me know pls.

I just wonder why the lib author made such a simple thing so complicated.

The program even gives different results with each run; so there must
definitely be a bug in the crc library.

> On Thu, Jul 9, 2015 at 8:27 PM, U.Mutlu <for-gmane_at_[hidden]> wrote:
>
>> /*
>> boost-crc-bug-demo.cpp
>>
>> Written by U.Mutlu on 2015-07-09-Th
>>
>> Compile:
>> g++ -O2 -Wall -std=gnu++11 boost-crc-bug-demo.cpp
>>
>> Run:
>> ./a.out
>>
>> Output:
>> crc("The quick brown fox jumps over the lazy dog")=414fa339
>> crc("The quick brown fox ")=88b075e2
>> crc("The quick brown fox jumps over the lazy dog")=4ac56d0f
>> ERROR
>>
>> See also:
>> http://www.boost.org/doc/libs/1_58_0/libs/crc/crc.html#usage
>>
>> Conclusion:
>> It doesn't do what it should and also advertises; ie. there's a bug
>>
>> */
>>
>> #include <boost/crc.hpp>
>> #include <boost/cstdint.hpp>
>> #include <iostream>
>>
>> int main()
>> {
>> uint32_t expected;
>>
>> {
>> const std::string sTxt = "The quick brown fox jumps over the lazy dog";
>> boost::crc_optimal<32, 0x04C11DB7, 0xFFFFFFFF, 0xFFFFFFFF, true, true>
>> crc;
>> crc.process_bytes(sTxt.data(), sTxt.size());
>> std::cout << "crc(\"" << sTxt << "\")=" << std::hex << crc.checksum()
>> << std::endl;
>>
>> // save the result for the following test
>> expected = crc.checksum();
>> }
>>
>>
>> // test: doing the same as above, but now in 2 steps, ie. chunk- or
>> blockwise:
>> std::string sTxt;
>> uint32_t result = 0xFFFFFFFF;
>> for (size_t i = 0; i <= 1; ++i)
>> {
>> sTxt += !i ? "The quick brown fox "
>> : "jumps over the lazy dog";
>>
>> // using the special ctor for initial remainder stored in "result"
>> boost::crc_optimal<32, 0x04C11DB7, 0xFFFFFFFF, 0xFFFFFFFF, true, true>
>> crc(result);
>> crc.process_bytes(sTxt.data(), sTxt.size());
>> std::cout << "crc(\"" << sTxt << "\")=" << std::hex << crc.checksum()
>> << std::endl;
>>
>> result = crc.checksum();
>> }
>>
>> // eval:
>> const std::string sRes = result == expected ? "SUCCESS" : "ERROR";
>> std::cout << sRes << std::endl;
>>
>> return 0;
>> }
>>
>> _______________________________________________
>> Boost-users mailing list
>> Boost-users_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>>
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net