/*
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
So,you are initializing the crc with a different value(result from previous
loop) and expecting the same result?
On Thu, Jul 9, 2015 at 8:27 PM, U.Mutlu
/* 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
#include #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@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
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
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
#include #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@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On 07/09/2015 07:27 PM, U.Mutlu wrote:
// 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";
Bug 1: Do not append to the string.
// using the special ctor for initial remainder stored in "result" boost::crc_optimal<32, 0x04C11DB7, 0xFFFFFFFF, 0xFFFFFFFF, true, true> crc(result);
Bug 2: Do not pass checksum() as the initial remainder, but rather get_interrim_remainder().
Bjorn Reese wrote on 07/09/2015 11:45 PM:
On 07/09/2015 07:27 PM, U.Mutlu wrote:
// 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";
Bug 1: Do not append to the string.
// using the special ctor for initial remainder stored in "result" boost::crc_optimal<32, 0x04C11DB7, 0xFFFFFFFF, 0xFFFFFFFF, true, true> crc(result);
Bug 2: Do not pass checksum() as the initial remainder, but rather get_interrim_remainder().
Thx, now it works.
participants (3)
-
Bjorn Reese
-
Hurcan Solter
-
U.Mutlu