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 <for-gmane@mutluit.com> 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@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users