static void q_condition_barf (QProReadState *state, const char *cond) { corrupted (state); /* Translation is screwed here. */ g_printerr ("Condition \"%s\" failed.\n", cond); }
int HashtableTextDump::scan_prefix() { // Expect /[0-9]+: / int utf8_length = get_num(':'); if (*_p != ' ') { corrupted(_p); } _p++; return utf8_length; }
int HashtableTextDump::scan_string_prefix() { // Expect /[0-9]+: / int utf8_length; get_num(':', &utf8_length); if (*_p != ' ') { corrupted(_p, "Wrong prefix format for string"); } _p++; return utf8_length; }
bool HashtableTextDump::skip_newline() { if (_p[0] == '\r' && _p[1] == '\n') { _p += 2; } else if (_p[0] == '\n') { _p += 1; } else { corrupted(_p); } return true; }
bool HashtableTextDump::skip_newline() { if (_p[0] == '\r' && _p[1] == '\n') { _p += 2; } else if (_p[0] == '\n') { _p += 1; } else { corrupted(_p, "Unexpected character"); } _line_no ++; return true; }
static gboolean qpro_validate_len (QProReadState *state, char const *id, guint16 len, int expected_len) { if (expected_len >= 0 && len != expected_len) { corrupted (state); g_printerr ("Invalid '%s' record of length %hd instead of %d\n", id, len, expected_len); return FALSE; } return TRUE; }
int HashtableTextDump::scan_symbol_prefix() { // Expect /[0-9]+ (-|)[0-9]+: / int utf8_length; get_num(' ', &utf8_length); if (*_p == '-') { _p++; } int ref_num; (void)get_num(':', &ref_num); if (*_p != ' ') { corrupted(_p, "Wrong prefix format for symbol"); } _p++; return utf8_length; }
Chunk* ChunkManager::grabChunk(unsigned int i) { if (i >= chunks.size()) return 0; Chunk* c = chunks[i]; if (c->getStatus() == Chunk::NOT_DOWNLOADED || c->isExcluded()) { return 0; } else if (c->getStatus() == Chunk::ON_DISK) { // load the chunk if it is on disk cache->load(c); loaded.insert(i,bt::GetCurrentTime()); bool check_allowed = (max_chunk_size_for_data_check == 0 || tor.getChunkSize() <= max_chunk_size_for_data_check); // when no corruptions have been found, only check once every 5 chunks if (check_allowed && recheck_counter < 5 && corrupted_count == 0) check_allowed = false; if (c->getData() && check_allowed) { recheck_counter = 0; if (!c->checkHash(tor.getHash(i))) { Out(SYS_DIO|LOG_IMPORTANT) << "Chunk " << i << " has been found invalid, redownloading" << endl; resetChunk(i); tor.updateFilePercentage(i,bitset); saveIndexFile(); recalc_chunks_left = true; corrupted_count++; corrupted(i); return 0; } } else { recheck_counter++; } } loaded.insert(i,bt::GetCurrentTime()); return c; }
int HashtableTextDump::scan_prefix(int* utf8_length) { if (*_p == '@') { scan_prefix_type(); } switch (_prefix_type) { case SymbolPrefix: *utf8_length = scan_symbol_prefix(); break; case StringPrefix: *utf8_length = scan_string_prefix(); break; default: tty->print_cr("Shared input data type: Unknown."); corrupted(_p, "Unknown data type"); } return _prefix_type; }
void HashtableTextDump::get_utf8(char* utf8_buffer, int utf8_length) { // cache in local vars const char* from = _p; const char* end = _end; char* to = utf8_buffer; int n = utf8_length; for (; n > 0 && from < end; n--) { if (*from != '\\') { *to++ = *from++; } else { corrupted_if(from + 2 > end); char c = from[1]; from += 2; switch (c) { case 'x': { jchar value = unescape(from, end, 2); from += 2; assert(value <= 0xff, "sanity"); *to++ = (char)(value & 0xff); } break; case 't': *to++ = '\t'; break; case 'n': *to++ = '\n'; break; case 'r': *to++ = '\r'; break; case '\\': *to++ = '\\'; break; default: corrupted(_p, "Unsupported character"); } } } corrupted_if(n > 0); // expected more chars but file has ended _p = from; skip_newline(); }
int main() { // Allocate a BCH codec Galois order 8 (w/ 2^8-1 == 255 bit codeword size), and 2 bits of // correction capacity. This results in a BCH( 255, 239, 2) codec: 255-bit codeword, 239-bit // data payload capacity, hence 255-239 == 16 bits of parity. Define EZPWD_BCH_CLASSIC to use // classic Djelic Linux Kernel API. Otherwise, uses <ezpwd/bch> 'bch<..>' or 'BCH<...>' classes. ezpwd::asserter assert; try { #if defined( EZPWD_BCH_CLASSIC ) ezpwd::bch_control *bch = ezpwd::init_bch( 8, 2, 0 ); if ( ! bch ) throw std::logic_error( "Failed to allocate valid BCH codec" ); ezpwd::bch_control &bch_codec( *bch ); // By Galois order, Correction capacity #else //ezpwd::bch_base bch_codec( 8, 2 ); // By Galois order, Correction capacity, flexibly ezpwd::BCH<255,239,2> bch_codec; // By Codeword, Payload and Correction capacities, exactly #endif #if defined( EZPWD_BCH_FIXED ) typedef std::array<uint8_t,10> codeword_t; // Fixed (parity initialized to 0) #else typedef std::vector<uint8_t> codeword_t; // Variable (parity added by encode) #endif codeword_t codeword= { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF // 8 data }; // 2 ECC parity #if defined( EZPWD_BCH_CLASSIC ) // A BCH codeword's ECC must be zero-initialized for classic Djelic API, and // must be added to variable containers # if ! defined( EZPWD_BCH_FIXED ) codeword.resize( 10 ); # endif codeword[8] = 0; codeword[9] = 0; ezpwd::encode_bch( &bch_codec, &codeword[0], 8, &codeword[8] ); #else // A codeword in a fixed container will not be resized by API; assumes ECC on end. Will // initialize to 0. A variable container will have parity appended by the API. bch_codec.encode( codeword ); #endif // Place random errors in the codeword and correct, up to the capacity of the BCH codec. for ( size_t t = 0; t < 5; ++t ) { for ( size_t e = 0 #if defined( EZPWD_BCH_CLASSIC ) ; e < bch_codec.t #else ; e < bch_codec.t() #endif ; ++e ) { codeword_t corrupted( codeword ); // Randomly corrupt from 0 to bch->t bits for ( size_t be = 0; be < e; ++be ) { unsigned int bl = random_80( randomizer ); corrupted[bl/8] ^= uint8_t( 1 ) << ( bl % 8 ); } codeword_t corrected( corrupted ); #if defined( EZPWD_BCH_CLASSIC ) int corrections = correct_bch( &bch_codec, &corrected[0], 8, &corrected[8] ); #else int corrections = bch_codec.decode( corrected ); #endif if ( assert.ISEQUAL( corrections, int( e ), std::string( "Failed decode of " ) << bch_codec << " codeword w/ " << e << " bit errrors" )) { std::cout << assert << std::endl; continue; } // Success; If differences were found, they better be in the parity data! for ( size_t i = 0; i < 8; ++i ) if ( assert.ISEQUAL( corrected[i], codeword[i], std::string( "Failed recovery of " ) << bch_codec << " codeword w/ " << e << " bit errors" )) std::cout << assert << std::endl; } #if ! defined( EZPWD_BCH_CLASSIC ) // Try the inline versions (only available in C++ API) std::string raw( "abc" ); std::string enc = bch_codec.encoded( raw ); std::string err = enc; err[0] ^= 0x40; err[2] ^= 0x08; std::string dec = bch_codec.decoded( err ); if ( assert.ISEQUAL( dec.substr( 0, 3 ), raw, std::string( "decoded/encoded of " ) << bch_codec << " codeword failed, encoded '0x" << ezpwd::hexstr( raw ) << "' to '0x" << ezpwd::hexstr( enc ) << "', decoded '0x" << ezpwd::hexstr( err ) << "' to '0x" << ezpwd::hexstr( dec ) << "'" )) std::cout << assert << std::endl; #endif } std::cout << bch_codec << ": "; } catch( std::exception &exc ) { assert.FAILURE( "Exception", exc.what() ); std::cout << assert << std::endl; } if ( assert.failures ) std::cout << assert.failures << " tests failed." << std::endl; else std::cout << "All tests passed." << std::endl; return assert.failures ? 1 : 0; }
Item::Item(const rapidjson::Value &json) : location_(ItemLocation(json)), name_(correct_name(json["name"].GetString())), typeLine_(correct_name(json["typeLine"].GetString())), corrupted_(json["corrupted"].GetBool()), w_(json["w"].GetInt()), h_(json["h"].GetInt()), frameType_(json["frameType"].GetInt()), icon_(json["icon"].GetString()), sockets_cnt_(0), links_cnt_(0), sockets_({ 0, 0, 0, 0 }), has_mtx_(false) { for (auto &mod_type : ITEM_MOD_TYPES) { text_mods_[mod_type] = std::vector<std::string>(); if (json.HasMember(mod_type.c_str())) { auto &mods = text_mods_[mod_type]; for (auto &mod : json[mod_type.c_str()]) mods.push_back(mod.GetString()); } } if (json.HasMember("properties")) { for (auto prop_it = json["properties"].Begin(); prop_it != json["properties"].End(); ++prop_it) { auto &prop = *prop_it; std::string name = prop["name"].GetString(); if (name == "Уровень карты") name = "Уровень"; if (name == "Урон от стихий") { for (auto value_it = prop["values"].Begin(); value_it != prop["values"].End(); ++value_it) elemental_damage_.push_back(std::make_pair((*value_it)[0].GetString(), (*value_it)[1].GetInt())); } else { if (prop["values"].Size()) properties_[name] = prop["values"][0][0].GetString(); } ItemProperty property; property.name = name; property.display_mode = prop["displayMode"].GetInt(); for (auto &value : prop["values"]) property.values.push_back(value[0].GetString()); text_properties_.push_back(property); } } if (json.HasMember("requirements")) { for (auto &req : json["requirements"]) { std::string name = req["name"].GetString(); std::string value = req["values"][0][0].GetString(); requirements_[name] = std::atoi(value.c_str()); text_requirements_.push_back({ name, value }); } } if (json.HasMember("sockets")) { ItemSocketGroup current_group = { 0, 0, 0, 0 }; sockets_cnt_ = json["sockets"].Size(); int counter = 0, prev_group = -1; for (auto &socket : json["sockets"]) { ItemSocket current_socket = { static_cast<unsigned char>(socket["group"].GetInt()), socket["attr"].GetString()[0] }; text_sockets_.push_back(current_socket); if (prev_group != current_socket.group) { counter = 0; socket_groups_.push_back(current_group); current_group = { 0, 0, 0, 0 }; } prev_group = current_socket.group; ++counter; links_cnt_ = std::max(links_cnt_, counter); switch (current_socket.attr) { case 'S': sockets_.r++; current_group.r++; break; case 'D': sockets_.g++; current_group.g++; break; case 'I': sockets_.b++; current_group.b++; break; case 'G': sockets_.w++; current_group.w++; break; } } socket_groups_.push_back(current_group); } std::string hashes[3]; for (int i = 0; i < 3; i++) { std::string unique(name_ + "~" + typeLine_ + "~"); if (i == 2) { // Strip off last "~" (a mistake from 0.3) unique = unique.substr(0, unique.length() - 1); } if (json.HasMember("explicitMods")) for (auto mod_it = json["explicitMods"].Begin(); mod_it != json["explicitMods"].End(); ++mod_it) unique += std::string(mod_it->GetString()) + "~"; if (json.HasMember("implicitMods")) for (auto mod_it = json["implicitMods"].Begin(); mod_it != json["implicitMods"].End(); ++mod_it) unique += std::string(mod_it->GetString()) + "~"; unique += item_unique_properties(json, "properties") + "~"; unique += item_unique_properties(json, "additionalProperties") + "~"; if (json.HasMember("sockets")) for (auto socket_it = json["sockets"].Begin(); socket_it != json["sockets"].End(); ++socket_it) unique += std::to_string((*socket_it)["group"].GetInt()) + "~" + (*socket_it)["attr"].GetString() + "~"; // This will only effect corrupted item's new hashes... if (i == 1 && corrupted()) unique += "corrupted"; hashes[i] = Util::Md5(unique); } old_hash_ = hashes[0]; hash_ = hashes[1]; broken_hash_ = hashes[2]; count_ = 1; if (properties_.find("Размер стопки") != properties_.end()) { std::string size = properties_["Размер стопки"]; if (size.find("/") != std::string::npos) { size = size.substr(0, size.find("/")); count_ = std::stoi(size); } } has_mtx_ = json.HasMember("cosmeticMods"); GenerateMods(json); }
void ViBenchMarker3::process2() { int time = mTime.elapsed(); QObject::disconnect(mCurrentObject.data(), SIGNAL(noiseGenerated()), this, SLOT(process2())); /*QObject::connect(mCurrentObject.data(), SIGNAL(encoded()), this, SLOT(quit())); mCurrentObject->encode(ViAudio::Noise); return;*/ qreal maxMAT = 0; qint64 maxTP = 0, maxTN = 0, maxFP = 0, maxFN = 0; qint64 i, lengthIndex, offset1 = 0, offset2 = 0; int noChange = 0; ViAudioReadData corrupted(mCurrentObject->buffer(ViAudio::Noise)); ViAudioReadData realMask(mCurrentObject->buffer(ViAudio::CustomMask)); ViAudioReadData length(mCurrentObject->buffer(ViAudio::Custom)); corrupted.setSampleCount(WINDOW_SIZE); realMask.setSampleCount(WINDOW_SIZE); length.setSampleCount(WINDOW_SIZE); ViSampleChunk *nData1 = new ViSampleChunk(corrupted.bufferSamples() / 2); ViSampleChunk *nData2 = new ViSampleChunk(corrupted.bufferSamples() / 2); ViSampleChunk *nMask1 = new ViSampleChunk(corrupted.bufferSamples() / 2); ViSampleChunk *nMask2 = new ViSampleChunk(corrupted.bufferSamples() / 2); ViSampleChunk *nRealMask1 = new ViSampleChunk(realMask.bufferSamples() / 2); ViSampleChunk *nRealMask2 = new ViSampleChunk(realMask.bufferSamples() / 2); ViSampleChunk *nLength1 = new ViSampleChunk(corrupted.bufferSamples() / 2); ViSampleChunk *nLength2 = new ViSampleChunk(corrupted.bufferSamples() / 2); while(corrupted.hasData() && realMask.hasData()) { corrupted.read(); ViSampleChunk &corrupted1 = corrupted.splitSamples(0); ViSampleChunk &corrupted2 = corrupted.splitSamples(1); realMask.read(); ViSampleChunk &realMask1 = realMask.splitSamples(0); ViSampleChunk &realMask2 = realMask.splitSamples(1); length.read(); ViSampleChunk &length1 = length.splitSamples(0); ViSampleChunk &length2 = length.splitSamples(1); for(i = 0; i < corrupted1.size(); ++i) { (*nData1)[i + offset1] = corrupted1[i]; (*nRealMask1)[i + offset1] = realMask1[i]; (*nLength1)[i + offset1] = length1[i]; } offset1 += corrupted1.size(); for(i = 0; i < corrupted2.size(); ++i) { (*nData2)[i + offset2] = corrupted2[i]; (*nRealMask2)[i + offset2] = realMask2[i]; (*nLength2)[i + offset2] = length2[i]; } offset2 += corrupted2.size(); } mCurrentObject->clearBuffer(ViAudio::Target); mCurrentObject->clearBuffer(ViAudio::Noise); mCurrentObject->clearBuffer(ViAudio::NoiseMask); ViNoise noise1(nData1, nMask1, mCurrentThreshold); ViNoise noise2(nData2, nMask2, mCurrentThreshold); QVector<qreal> lengthTP(ViNoiseCreator::noiseSizeCount()); QVector<qreal> lengthFN(ViNoiseCreator::noiseSizeCount()); lengthTP.fill(0); lengthFN.fill(0); QVector<qreal> maxLengthTP, maxLengthFN; for(mCurrentThreshold = MASK_START; mCurrentThreshold <= MASK_END; mCurrentThreshold += MASK_INTERVAL) { noise1.setThreshold(mCurrentThreshold); noise1.generateMask(ViNoise::NOISE_TYPE); noise2.setThreshold(mCurrentThreshold); noise2.generateMask(ViNoise::NOISE_TYPE); qint64 truePositives = 0, falsePositives = 0, trueNegatives = 0, falseNegatives = 0; for(i = 0; i < nRealMask1->size(); ++i) { if((*nRealMask1)[i] == 1) { lengthIndex = ViNoiseCreator::fromSizeMask((*nLength1)[i]) - 1; if((*nMask1)[i] == 1) { ++truePositives; lengthTP[lengthIndex] += 1; } else { ++falseNegatives; lengthFN[lengthIndex] += 1; } } else if((*nRealMask1)[i] == 0) { if((*nMask1)[i] == 1) ++falsePositives; else ++trueNegatives; } } for(i = 0; i < nRealMask2->size(); ++i) { if((*nRealMask2)[i] == 1) { lengthIndex = ViNoiseCreator::fromSizeMask((*nLength2)[i]) - 1; if((*nMask2)[i] == 1) { ++truePositives; lengthTP[lengthIndex] += 1; } else { ++falseNegatives; lengthFN[lengthIndex] += 1; } } else if((*nRealMask2)[i] == 0) { if((*nMask2)[i] == 1) ++falsePositives; else ++trueNegatives; } } qreal math = matthews(truePositives, trueNegatives, falsePositives, falseNegatives); if(math > maxMAT) { maxMAT = math; maxTP = truePositives; maxTN = trueNegatives; maxFP = falsePositives; maxFN = falseNegatives; maxLengthTP = lengthTP; maxLengthFN = lengthFN; noChange = 0; } ++noChange; if(noChange > NO_CHANGE) break; } delete nRealMask1; delete nRealMask2; delete nLength1; delete nLength2; ++mDoneParamIterations; if(maxMAT > mBestMatthews) mBestMatthews = maxMAT; printFileData(time, maxTP, maxTN, maxFP, maxFN, maxLengthTP, maxLengthFN); printTerminal(time, maxTP, maxTN, maxFP, maxFN, mBestMatthews); if(nextParam()) process1(false); else nextFile(); }