diff --git a/src/nfagraph/ng_lbr.cpp b/src/nfagraph/ng_lbr.cpp index a6630a95..209afc05 100644 --- a/src/nfagraph/ng_lbr.cpp +++ b/src/nfagraph/ng_lbr.cpp @@ -72,7 +72,7 @@ u32 depth_to_u32(const depth &d) { template static u64a* getTable(NFA *nfa) { - char *ptr = (char *)nfa + sizeof(struct NFA) + sizeof(LbrStruct) + + char *ptr = reinterpret_cast(nfa) + sizeof(struct NFA) + sizeof(LbrStruct) + sizeof(RepeatInfo); ptr = ROUNDUP_PTR(ptr, alignof(u64a)); return (u64a *)ptr; @@ -95,7 +95,7 @@ void fillNfa(NFA *nfa, lbr_common *c, ReportID report, const depth &repeatMin, c->repeatInfoOffset = info_offset; c->report = report; - RepeatInfo *info = (RepeatInfo *)((char *)c + info_offset); + RepeatInfo *info = reinterpret_cast(reinterpret_cast(c) + info_offset); info->type = verify_u8(rtype); info->repeatMin = depth_to_u32(repeatMin); info->repeatMax = depth_to_u32(repeatMax); @@ -160,8 +160,8 @@ bytecode_ptr buildLbrDot(const CharReach &cr, const depth &repeatMin, enum RepeatType rtype = chooseRepeatType(repeatMin, repeatMax, minPeriod, is_reset); auto nfa = makeLbrNfa(LBR_NFA_DOT, rtype, repeatMax); - struct lbr_dot *ld = (struct lbr_dot *)getMutableImplNfa(nfa.get()); - + struct lbr_dot *ld = reinterpret_castgetMutableImplNfa(nfa.get()); + fillNfa(nfa.get(), &ld->common, report, repeatMin, repeatMax, minPeriod, rtype); @@ -205,7 +205,8 @@ bytecode_ptr buildLbrNVerm(const CharReach &cr, const depth &repeatMin, enum RepeatType rtype = chooseRepeatType(repeatMin, repeatMax, minPeriod, is_reset); auto nfa = makeLbrNfa(LBR_NFA_NVERM, rtype, repeatMax); - struct lbr_verm *lv = (struct lbr_verm *)getMutableImplNfa(nfa.get()); + struct lbr_verm *lv = reinterpret_castgetMutableImplNfa(nfa.get()); + lv->c = escapes.find_first(); fillNfa(nfa.get(), &lv->common, report, repeatMin, repeatMax, @@ -222,12 +223,12 @@ bytecode_ptr buildLbrShuf(const CharReach &cr, const depth &repeatMin, enum RepeatType rtype = chooseRepeatType(repeatMin, repeatMax, minPeriod, is_reset); auto nfa = makeLbrNfa(LBR_NFA_SHUF, rtype, repeatMax); - struct lbr_shuf *ls = (struct lbr_shuf *)getMutableImplNfa(nfa.get()); + struct lbr_shuf *ls = reinterpret_castgetMutableImplNfa(nfa.get()); fillNfa(nfa.get(), &ls->common, report, repeatMin, repeatMax, minPeriod, rtype); - if (shuftiBuildMasks(~cr, (u8 *)&ls->mask_lo, (u8 *)&ls->mask_hi) == -1) { + if (shuftiBuildMasks(~cr, reinterpret_cast(&ls->mask_lo), reinterpret_cast(&ls->mask_hi)) == -1) { return bytecode_ptr(nullptr); } @@ -242,12 +243,12 @@ bytecode_ptr buildLbrTruf(const CharReach &cr, const depth &repeatMin, enum RepeatType rtype = chooseRepeatType(repeatMin, repeatMax, minPeriod, is_reset); auto nfa = makeLbrNfa(LBR_NFA_TRUF, rtype, repeatMax); - struct lbr_truf *lc = (struct lbr_truf *)getMutableImplNfa(nfa.get()); - + struct lbr_truf *lc = reinterpret_castgetMutableImplNfa(nfa.get()); + fillNfa(nfa.get(), &lc->common, report, repeatMin, repeatMax, minPeriod, rtype); - truffleBuildMasks(~cr, (u8 *)&lc->mask1, (u8 *)&lc->mask2); + truffleBuildMasks(~cr, reinterpret_cast(&lc->mask1), reinterpret_cast(&lc->mask2)); DEBUG_PRINTF("built truffle lbr\n"); return nfa; diff --git a/src/rose/rose_build_anchored.cpp b/src/rose/rose_build_anchored.cpp index 08d464ed..0e2f4eff 100644 --- a/src/rose/rose_build_anchored.cpp +++ b/src/rose/rose_build_anchored.cpp @@ -264,11 +264,11 @@ u32 anchoredStateSize(const anchored_matcher_info &atable) { // Walk the list until we find the last element; total state size will be // that engine's state offset plus its state requirement. while (curr->next_offset) { - curr = (const anchored_matcher_info *) - ((const char *)curr + curr->next_offset); + curr = reinterpret_cast + (reinterpret_cast(curr) + curr->next_offset); } - const NFA *nfa = (const NFA *)((const char *)curr + sizeof(*curr)); + const NFA *nfa = reinterpret_cast(reinterpret_cast(curr) + sizeof(*curr)); return curr->state_offset + nfa->streamStateSize; } @@ -890,12 +890,12 @@ buildAnchoredMatcher(const RoseBuildImpl &build, const vector &frag auto atable = make_zeroed_bytecode_ptr(total_size, 64); - char *curr = (char *)atable.get(); + char *curr = reinterpret_cast(atable.get()); u32 state_offset = 0; for (size_t i = 0; i < nfas.size(); i++) { const NFA *nfa = nfas[i].get(); - anchored_matcher_info *ami = (anchored_matcher_info *)curr; + anchored_matcher_info *ami = reinterpret_cast(curr); const char *prev_curr = curr; curr += sizeof(anchored_matcher_info); diff --git a/src/rose/rose_build_bytecode.cpp b/src/rose/rose_build_bytecode.cpp index f7981729..69628319 100644 --- a/src/rose/rose_build_bytecode.cpp +++ b/src/rose/rose_build_bytecode.cpp @@ -2019,7 +2019,7 @@ void buildCountingMiracles(build_context &bc) { rcm.c = cr.find_first(); } else { rcm.shufti = 1; - int rv = shuftiBuildMasks(cr, (u8 *)&rcm.lo, (u8 *)&rcm.hi); + int rv = shuftiBuildMasks(cr, reinterpret_cast(&rcm.lo), reinterpret_cast(&rcm.hi)); if (rv == -1) { DEBUG_PRINTF("failed to build shufti\n"); lbi.countingMiracleCount = 0; /* remove counting miracle */ @@ -3504,7 +3504,7 @@ bytecode_ptr addSmallWriteEngine(const RoseBuildImpl &build, const size_t newSize = smwrOffset + smallWriteSize; auto rose2 = make_zeroed_bytecode_ptr(newSize, 64); - char *ptr = (char *)rose2.get(); + char *ptr = reinterpret_cast(rose2.get()); memcpy(ptr, rose.get(), mainSize); memcpy(ptr + smwrOffset, smwr_engine.get(), smallWriteSize); @@ -3869,7 +3869,7 @@ bytecode_ptr RoseBuildImpl::buildFinalEngine(u32 minWidth) { // Copy in our prototype engine data. memcpy(engine.get(), &proto, sizeof(proto)); - write_out(&engine->state_init, (char *)engine.get(), state_scatter, + write_out(&engine->state_init, reinterpret_cast(engine.get()), state_scatter, state_scatter_aux_offset); // Copy in the engine blob. diff --git a/src/rose/rose_build_dump.cpp b/src/rose/rose_build_dump.cpp index e63d4103..7112910b 100644 --- a/src/rose/rose_build_dump.cpp +++ b/src/rose/rose_build_dump.cpp @@ -566,7 +566,7 @@ const void *loadFromByteCodeOffset(const RoseEngine *t, u32 offset) { return nullptr; } - const char *lt = (const char *)t + offset; + const char *lt = reinterpret_cast(t) + offset; return lt; } @@ -623,9 +623,9 @@ void dumpLookaround(ofstream &os, const RoseEngine *t, const ROSE_STRUCT_CHECK_LOOKAROUND *ri) { assert(ri); - const u8 *base = (const u8 *)t; + const u8 *base = reinterpret_cast(t); - const s8 *look = (const s8 *)base + ri->look_index; + const s8 *look = reinterpret_cast(base) + ri->look_index; const s8 *look_end = look + ri->count; const u8 *reach = base + ri->reach_index; @@ -644,9 +644,9 @@ void dumpMultipathLookaround(ofstream &os, const RoseEngine *t, const ROSE_STRUCT_MULTIPATH_LOOKAROUND *ri) { assert(ri); - const u8 *base = (const u8 *)t; + const u8 *base = reinterpret_cast(t); - const s8 *look_begin = (const s8 *)base + ri->look_index; + const s8 *look_begin = reinterpret_cast(base) + ri->look_index; const s8 *look_end = look_begin + ri->count; const u8 *reach_begin = base + ri->reach_index; @@ -706,9 +706,9 @@ vector sparseIterValues(const mmbit_sparse_iter *it, u32 num_bits) { static void dumpJumpTable(ofstream &os, const RoseEngine *t, const ROSE_STRUCT_SPARSE_ITER_BEGIN *ri) { - auto *it = - (const mmbit_sparse_iter *)loadFromByteCodeOffset(t, ri->iter_offset); - auto *jumps = (const u32 *)loadFromByteCodeOffset(t, ri->jump_table); + auto *it = + reinterpret_cast(loadFromByteCodeOffset(t, ri->iter_offset)); + auto *jumps = reinterpret_cast(loadFromByteCodeOffset(t, ri->jump_table)); for (const auto &key : sparseIterValues(it, t->rolesWithStateCount)) { os << " " << std::setw(4) << std::setfill(' ') << key << " : +" @@ -865,7 +865,7 @@ void dumpMultipathShufti(ofstream &os, u32 len, const u8 *lo, const u8 *hi, case ROSE_INSTR_##name: { \ os << " " << std::setw(4) << std::setfill('0') << (pc - pc_base) \ << ": " #name "\n"; \ - const auto *ri = (const struct ROSE_STRUCT_##name *)pc; + const auto *ri = reinterpret_cast(pc); #define PROGRAM_NEXT_INSTRUCTION \ pc += ROUNDUP_N(sizeof(*ri), ROSE_INSTR_MIN_ALIGN); \ @@ -877,7 +877,7 @@ static void dumpProgram(ofstream &os, const RoseEngine *t, const char *pc) { const char *pc_base = pc; for (;;) { - u8 code = *(const u8 *)pc; + u8 code = *(reinterpret_cast(pc)); assert(code <= LAST_ROSE_INSTRUCTION); const size_t offset = pc - pc_base; switch (code) { @@ -926,7 +926,7 @@ void dumpProgram(ofstream &os, const RoseEngine *t, const char *pc) { os << " offset " << int{ri->offset} << endl; os << " reach_index " << ri->reach_index << endl; os << " fail_jump " << offset + ri->fail_jump << endl; - const u8 *reach = (const u8 *)t + ri->reach_index; + const u8 *reach = reinterpret_cast(t) + ri->reach_index; os << " contents "; describeClass(os, bitvectorToReach(reach), 1000, CC_OUT_TEXT); os << endl; @@ -1347,7 +1347,7 @@ void dumpProgram(ofstream &os, const RoseEngine *t, const char *pc) { PROGRAM_CASE(CHECK_LONG_LIT) { os << " lit_offset " << ri->lit_offset << endl; os << " lit_length " << ri->lit_length << endl; - const char *lit = (const char *)t + ri->lit_offset; + const char *lit = reinterpret_cast(t) + ri->lit_offset; os << " literal: \"" << escapeString(string(lit, ri->lit_length)) << "\"" << endl; os << " fail_jump " << offset + ri->fail_jump << endl; @@ -1357,7 +1357,7 @@ void dumpProgram(ofstream &os, const RoseEngine *t, const char *pc) { PROGRAM_CASE(CHECK_LONG_LIT_NOCASE) { os << " lit_offset " << ri->lit_offset << endl; os << " lit_length " << ri->lit_length << endl; - const char *lit = (const char *)t + ri->lit_offset; + const char *lit = reinterpret_cast(t) + ri->lit_offset; os << " literal: \"" << escapeString(string(lit, ri->lit_length)) << "\"" << endl; os << " fail_jump " << offset + ri->fail_jump << endl; @@ -1367,7 +1367,7 @@ void dumpProgram(ofstream &os, const RoseEngine *t, const char *pc) { PROGRAM_CASE(CHECK_MED_LIT) { os << " lit_offset " << ri->lit_offset << endl; os << " lit_length " << ri->lit_length << endl; - const char *lit = (const char *)t + ri->lit_offset; + const char *lit = reinterpret_cast(t) + ri->lit_offset; os << " literal: \"" << escapeString(string(lit, ri->lit_length)) << "\"" << endl; os << " fail_jump " << offset + ri->fail_jump << endl; @@ -1377,7 +1377,7 @@ void dumpProgram(ofstream &os, const RoseEngine *t, const char *pc) { PROGRAM_CASE(CHECK_MED_LIT_NOCASE) { os << " lit_offset " << ri->lit_offset << endl; os << " lit_length " << ri->lit_length << endl; - const char *lit = (const char *)t + ri->lit_offset; + const char *lit = reinterpret_cast(t) + ri->lit_offset; os << " literal: \"" << escapeString(string(lit, ri->lit_length)) << "\"" << endl; os << " fail_jump " << offset + ri->fail_jump << endl; @@ -1585,7 +1585,7 @@ void dumpRoseLitPrograms(const vector &fragments, for (u32 prog_offset : programs) { os << "Program @ " << prog_offset << ":" << endl; - const char *prog = (const char *)loadFromByteCodeOffset(t, prog_offset); + const char *prog = reinterpret_cast(loadFromByteCodeOffset(t, prog_offset)); dumpProgram(os, t, prog); os << endl; } @@ -1596,7 +1596,7 @@ void dumpRoseLitPrograms(const vector &fragments, static void dumpRoseEodPrograms(const RoseEngine *t, const string &filename) { ofstream os(filename); - const char *base = (const char *)t; + const char *base = reinterpret_cast(t); if (t->eodProgramOffset) { os << "EOD Program @ " << t->eodProgramOffset << ":" << endl; @@ -1612,7 +1612,7 @@ void dumpRoseEodPrograms(const RoseEngine *t, const string &filename) { static void dumpRoseFlushCombPrograms(const RoseEngine *t, const string &filename) { ofstream os(filename); - const char *base = (const char *)t; + const char *base = reinterpret_cast(t); if (t->flushCombProgramOffset) { os << "Flush Combination Program @ " << t->flushCombProgramOffset @@ -1630,7 +1630,7 @@ static void dumpRoseLastFlushCombPrograms(const RoseEngine *t, const string &filename) { ofstream os(filename); - const char *base = (const char *)t; + const char *base = reinterpret_cast(t); if (t->lastFlushCombProgramOffset) { os << "Last Flush Combination Program @ " @@ -1649,8 +1649,8 @@ static void dumpRoseReportPrograms(const RoseEngine *t, const string &filename) { ofstream os(filename); - const u32 *programs = - (const u32 *)loadFromByteCodeOffset(t, t->reportProgramOffset); + const u32 *programs = reinterpret_cast + (loadFromByteCodeOffset(t, t->reportProgramOffset)); for (u32 i = 0; i < t->reportProgramCount; i++) { os << "Report " << i << endl; @@ -1658,8 +1658,8 @@ void dumpRoseReportPrograms(const RoseEngine *t, const string &filename) { if (programs[i]) { os << "Program @ " << programs[i] << ":" << endl; - const char *prog = - (const char *)loadFromByteCodeOffset(t, programs[i]); + const char *prog = + reinterpret_cast(loadFromByteCodeOffset(t, programs[i])); dumpProgram(os, t, prog); } else { os << "" << endl; @@ -1674,7 +1674,7 @@ void dumpRoseAnchoredPrograms(const RoseEngine *t, const string &filename) { ofstream os(filename); const u32 *programs = - (const u32 *)loadFromByteCodeOffset(t, t->anchoredProgramOffset); + reinterpret_cast(loadFromByteCodeOffset(t, t->anchoredProgramOffset)); for (u32 i = 0; i < t->anchored_count; i++) { os << "Anchored entry " << i << endl; @@ -1683,7 +1683,7 @@ void dumpRoseAnchoredPrograms(const RoseEngine *t, const string &filename) { if (programs[i]) { os << "Program @ " << programs[i] << ":" << endl; const char *prog = - (const char *)loadFromByteCodeOffset(t, programs[i]); + reinterpret_cast(loadFromByteCodeOffset(t, programs[i])); dumpProgram(os, t, prog); } else { os << "" << endl; @@ -1699,7 +1699,7 @@ void dumpRoseDelayPrograms(const RoseEngine *t, const string &filename) { ofstream os(filename); const u32 *programs = - (const u32 *)loadFromByteCodeOffset(t, t->delayProgramOffset); + reinterpret_cast(loadFromByteCodeOffset(t, t->delayProgramOffset)); for (u32 i = 0; i < t->delay_count; i++) { os << "Delay entry " << i << endl; @@ -1708,7 +1708,7 @@ void dumpRoseDelayPrograms(const RoseEngine *t, const string &filename) { if (programs[i]) { os << "Program @ " << programs[i] << ":" << endl; const char *prog = - (const char *)loadFromByteCodeOffset(t, programs[i]); + reinterpret_cast(loadFromByteCodeOffset(t, programs[i])); dumpProgram(os, t, prog); } else { os << "" << endl; @@ -1767,7 +1767,7 @@ void dumpNfaNotes(ofstream &fout, const RoseEngine *t, const NFA *n) { } if (left->countingMiracleOffset) { const RoseCountingMiracle *cm - = (const RoseCountingMiracle *)((const char *)t + = reinterpret_cast(reinterpret_cast(t) + left->countingMiracleOffset); fout << " counting_miracle:" << (int)cm->count << (cm->shufti ? "s" : "v"); @@ -1794,7 +1794,7 @@ void dumpComponentInfo(const RoseEngine *t, const string &base) { fout << left << setw(6) << i << " "; - fout << left << ((const char *)n - (const char *)t) << "\t"; /* offset */ + fout << left << (reinterpret_cast(n) - reinterpret_cast(t)) << "\t"; /* offset */ fout << left << setw(16) << describe(*n) << "\t"; @@ -1855,8 +1855,8 @@ void dumpComponentInfoCsv(const RoseEngine *t, const string &base) { notes << "miracles;"; } if (left->countingMiracleOffset) { - auto cm = (const RoseCountingMiracle *) - ((const char *)t + left->countingMiracleOffset); + auto cm = reinterpret_cast + (reinterpret_cast(t) + left->countingMiracleOffset); notes << "counting_miracle:" << (int)cm->count << (cm->shufti ? "s" : "v") << ";"; } @@ -1869,7 +1869,7 @@ void dumpComponentInfoCsv(const RoseEngine *t, const string &base) { } fprintf(f, "%u,%zd,\"%s\",%u,%u,%u,%s,%s\n", i, - (const char *)n - (const char *)t, describe(*n).c_str(), + (reinterpret_cast(n) - reinterpret_cast(t)), describe(*n).c_str(), n->nPositions, n->streamStateSize, n->length, to_string(kind).c_str(), notes.str().c_str()); } @@ -1880,7 +1880,7 @@ void dumpExhaust(const RoseEngine *t, const string &base) { StdioFile f(base + "/rose_exhaust.csv", "w"); const NfaInfo *infos - = (const NfaInfo *)((const char *)t + t->nfaInfoOffset); + = reinterpret_cast(reinterpret_cast(t) + t->nfaInfoOffset); u32 queue_count = t->activeArrayCount; @@ -1890,7 +1890,7 @@ void dumpExhaust(const RoseEngine *t, const string &base) { fprintf(f, "%u (%u):", i, ekey_offset); if (ekey_offset) { - const u32 *ekeys = (const u32 *)((const char *)t + ekey_offset); + const u32 *ekeys = reinterpret_cast(reinterpret_cast(t) + ekey_offset); while (1) { u32 e = *ekeys; ++ekeys; @@ -1934,12 +1934,12 @@ void dumpRevComponentInfo(const RoseEngine *t, const string &base) { fout << "Index Offset\tEngine \tStates S.State Bytes\n"; - const char *tp = (const char *)t; - const u32 *rev_offsets = (const u32 *)(tp + t->somRevOffsetOffset); + const char *tp = reinterpret_cast(t); + const u32 *rev_offsets = reinterpret_cast(tp + t->somRevOffsetOffset); for (u32 i = 0; i < t->somRevCount; i++) { u32 offset = rev_offsets[i]; - const NFA *n = (const NFA *)(tp + offset); + const NFA *n = reinterpret_cast(tp + offset); fout << left << setw(6) << i << " "; @@ -1956,11 +1956,11 @@ void dumpRevComponentInfo(const RoseEngine *t, const string &base) { static void dumpRevNfas(const RoseEngine *t, bool dump_raw, const string &base) { - const char *tp = (const char *)t; - const u32 *rev_offsets = (const u32 *)(tp + t->somRevOffsetOffset); + const char *tp = reinterpret_cast(t); + const u32 *rev_offsets = reinterpret_cast(tp + t->somRevOffsetOffset); for (u32 i = 0; i < t->somRevCount; i++) { - const NFA *n = (const NFA *)(tp + rev_offsets[i]); + const NFA *n = reinterpret_cast(tp + rev_offsets[i]); stringstream ssbase; ssbase << base << "som_rev_nfa_" << i; @@ -1979,17 +1979,17 @@ static void dumpAnchored(const RoseEngine *t, const string &base) { u32 i = 0; const anchored_matcher_info *curr - = (const anchored_matcher_info *)getALiteralMatcher(t); + = reinterpret_cast(getALiteralMatcher(t)); while (curr) { - const NFA *n = (const NFA *)((const char *)curr + sizeof(*curr)); + const NFA *n = reinterpret_cast(reinterpret_cast(curr) + sizeof(*curr)); stringstream ssbase; ssbase << base << "anchored_" << i; nfaGenerateDumpFiles(n, ssbase.str()); - curr = curr->next_offset ? (const anchored_matcher_info *) - ((const char *)curr + curr->next_offset) : nullptr; + curr = curr->next_offset ? reinterpret_cast + (reinterpret_cast(curr) + curr->next_offset) : nullptr; i++; }; } @@ -1999,16 +1999,16 @@ void dumpAnchoredStats(const void *atable, FILE *f) { assert(atable); u32 i = 0; - const anchored_matcher_info *curr = (const anchored_matcher_info *)atable; + const anchored_matcher_info *curr = reinterpret_cast(atable); while (curr) { - const NFA *n = (const NFA *)((const char *)curr + sizeof(*curr)); + const NFA *n = reinterpret_cast(reinterpret_cast(curr) + sizeof(*curr)); fprintf(f, " NFA %u: %s, %u states (%u bytes)\n", i, describe(*n).c_str(), n->nPositions, n->length); - curr = curr->next_offset ? (const anchored_matcher_info *) - ((const char *)curr + curr->next_offset) : nullptr; + curr = curr->next_offset ? reinterpret_cast + (reinterpret_cast(curr) + curr->next_offset) : nullptr; i++; }; @@ -2022,11 +2022,11 @@ void dumpLongLiteralSubtable(const RoseLongLitTable *ll_table, return; } - const char *base = (const char *)ll_table; + const char *base = reinterpret_cast(ll_table); u32 nbits = ll_sub->hashBits; u32 num_entries = 1U << nbits; - const auto *tab = (const RoseLongLitHashEntry *)(base + ll_sub->hashOffset); + const auto *tab = reinterpret_cast(base + ll_sub->hashOffset); u32 hash_occ = count_if(tab, tab + num_entries, [](const RoseLongLitHashEntry &ent) { return ent.str_offset != 0; @@ -2038,7 +2038,7 @@ void dumpLongLiteralSubtable(const RoseLongLitTable *ll_table, u32 bloom_bits = ll_sub->bloomBits; u32 bloom_size = 1U << bloom_bits; - const u8 *bloom = (const u8 *)base + ll_sub->bloomOffset; + const u8 *bloom = reinterpret_cast(base) + ll_sub->bloomOffset; u32 bloom_occ = accumulate(bloom, bloom + bloom_size / 8, 0, [](const u32 &sum, const u8 &elem) { return sum + popcount32(elem); }); float bloom_occ_percent = ((float)bloom_occ / (float)(bloom_size)) * 100; @@ -2057,8 +2057,8 @@ void dumpLongLiteralTable(const RoseEngine *t, FILE *f) { fprintf(f, "Long literal table (streaming):\n"); const auto *ll_table = - (const struct RoseLongLitTable *)loadFromByteCodeOffset( - t, t->longLitTableOffset); + reinterpret_cast(loadFromByteCodeOffset( + t, t->longLitTableOffset)); fprintf(f, " total size : %u bytes\n", ll_table->size); fprintf(f, " longest len : %u\n", ll_table->maxLen); diff --git a/src/rose/rose_build_lit_accel.cpp b/src/rose/rose_build_lit_accel.cpp index 7286fddb..53968a3b 100644 --- a/src/rose/rose_build_lit_accel.cpp +++ b/src/rose/rose_build_lit_accel.cpp @@ -454,7 +454,7 @@ void findForwardAccelScheme(const vector &lits, #endif // HAVE_SVE2 if (-1 != - shuftiBuildMasks(cr, (u8 *)&aux->shufti.lo, (u8 *)&aux->shufti.hi)) { + shuftiBuildMasks(cr, reinterpret_cast(&aux->shufti.lo), reinterpret_cast(&aux->shufti.hi))) { DEBUG_PRINTF("built shufti for %s (%zu chars, offset %u)\n", describeClass(cr).c_str(), cr.count(), min_offset); aux->shufti.accel_type = ACCEL_SHUFTI; @@ -462,7 +462,7 @@ void findForwardAccelScheme(const vector &lits, return; } - truffleBuildMasks(cr, (u8 *)&aux->truffle.mask1, (u8 *)&aux->truffle.mask2); + truffleBuildMasks(cr, reinterpret_cast(&aux->truffle.mask1), reinterpret_cast(&aux->truffle.mask2)); DEBUG_PRINTF("built truffle for %s (%zu chars, offset %u)\n", describeClass(cr).c_str(), cr.count(), min_offset); aux->truffle.accel_type = ACCEL_TRUFFLE; diff --git a/src/rose/rose_build_long_lit.cpp b/src/rose/rose_build_long_lit.cpp index 943c5b29..2329a7c2 100644 --- a/src/rose/rose_build_long_lit.cpp +++ b/src/rose/rose_build_long_lit.cpp @@ -134,7 +134,7 @@ vector buildBloomFilter(const vector &lits, size_t max_len, continue; } for (u32 offset = 1; offset < lit.s.size() - max_len + 1; offset++) { - const u8 *substr = (const u8 *)lit.s.c_str() + offset; + const u8 *substr = reinterpret_cast(lit.s.c_str()) + offset; addToBloomFilter(bloom, substr, nocase); } } @@ -234,7 +234,7 @@ map computeLitHashes(const vector &lits, continue; } for (u32 offset = 1; offset < lit.s.size() - max_len + 1; offset++) { - const u8 *substr = (const u8 *)lit.s.c_str() + offset; + const u8 *substr = reinterpret_cast(lit.s.c_str()) + offset; u32 hash = hashLongLiteral(substr, max_len, lit.nocase); hashToLitOffPairs[hash].emplace_back(lit_id, offset); } @@ -413,7 +413,7 @@ u32 buildLongLiteralTable(const RoseBuildImpl &build, RoseEngineBlob &blob, assert(table); // otherwise would have thrown std::bad_alloc // Fill in the RoseLongLitTable header structure. - RoseLongLitTable *header = (RoseLongLitTable *)(table.get()); + RoseLongLitTable *header = reinterpret_cast(table.get()); header->size = verify_u32(tabSize); header->maxLen = verify_u8(max_len); // u8 so doesn't matter; won't go > 255 header->caseful.hashOffset = verify_u32(htOffsetCase); diff --git a/unit/hyperscan/allocators.cpp b/unit/hyperscan/allocators.cpp index a30a3702..fa85fdfc 100644 --- a/unit/hyperscan/allocators.cpp +++ b/unit/hyperscan/allocators.cpp @@ -68,7 +68,7 @@ void two_aligned_free(void *mem) { return; } // Allocated with two_aligned_malloc above. - free((char *)mem - 2); + free(static_cast(mem) - 2); } TEST(CustomAllocator, TwoAlignedCompile) { diff --git a/unit/hyperscan/extparam.cpp b/unit/hyperscan/extparam.cpp index e9919be6..8839f6b0 100644 --- a/unit/hyperscan/extparam.cpp +++ b/unit/hyperscan/extparam.cpp @@ -58,14 +58,14 @@ TEST(ExtParam, LargeMinOffset) { // ensure it doesn't match. string corpus = "hatstand" + string(80000, '_') + "teakettle"; err = hs_scan(db, corpus.c_str(), corpus.length(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); ASSERT_EQ(0U, c.matches.size()); // Try exactly at the min_offset. corpus = "hatstand" + string(99983, '_') + "teakettle"; err = hs_scan(db, corpus.c_str(), corpus.length(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); ASSERT_EQ(1U, c.matches.size()); ASSERT_EQ(MatchRecord(100000, 0), c.matches[0]); @@ -97,7 +97,7 @@ TEST(ExtParam, LargeExactOffset) { // ensure it doesn't match. string corpus = "hatstand" + string(199982, '_') + "teakettle"; err = hs_scan(db, corpus.c_str(), corpus.length(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); ASSERT_EQ(0U, c.matches.size()); @@ -113,7 +113,7 @@ TEST(ExtParam, LargeExactOffset) { c.clear(); corpus = "hatstand" + string(199984, '_') + "teakettle"; err = hs_scan(db, corpus.c_str(), corpus.length(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); ASSERT_EQ(0U, c.matches.size()); @@ -143,14 +143,14 @@ TEST(ExtParam, LargeMinLength) { // short. string corpus = string(10000, '_') + "hatstand" + string(80000, '_') + "teakettle"; err = hs_scan(db, corpus.c_str(), corpus.length(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); ASSERT_EQ(0U, c.matches.size()); // Now, a match of the right length. corpus = string(10000, '_') + "hatstand" + string(99983, '_') + "teakettle"; err = hs_scan(db, corpus.c_str(), corpus.length(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); ASSERT_EQ(1U, c.matches.size()); ASSERT_EQ(MatchRecord(110000, 0), c.matches[0]); diff --git a/unit/hyperscan/literals.cpp b/unit/hyperscan/literals.cpp index 6ff3aa43..d7e7a4ca 100644 --- a/unit/hyperscan/literals.cpp +++ b/unit/hyperscan/literals.cpp @@ -87,7 +87,7 @@ protected: static int count_cb(unsigned, unsigned long long, unsigned long long, unsigned, void *ctxt) { - size_t *count = (size_t *)ctxt; + size_t *count = static_cast(ctxt); (*count)++; return 0; } diff --git a/unit/hyperscan/logical_combination.cpp b/unit/hyperscan/logical_combination.cpp index 20b6e5a1..bdc187ce 100644 --- a/unit/hyperscan/logical_combination.cpp +++ b/unit/hyperscan/logical_combination.cpp @@ -60,7 +60,7 @@ TEST(LogicalCombination, SingleComb1) { c.halt = 0; err = hs_scan(db, data.c_str(), data.size(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); ASSERT_EQ(16U, c.matches.size()); ASSERT_EQ(MatchRecord(3, 101), c.matches[0]); @@ -108,7 +108,7 @@ TEST(LogicalCombination, SingleCombQuietSub1) { c.halt = 0; err = hs_scan(db, data.c_str(), data.size(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); ASSERT_EQ(8U, c.matches.size()); ASSERT_EQ(MatchRecord(18, 1001), c.matches[0]); @@ -151,7 +151,7 @@ TEST(LogicalCombination, MultiCombQuietSub1) { c.halt = 0; err = hs_scan(db, data.c_str(), data.size(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); ASSERT_EQ(10U, c.matches.size()); ASSERT_EQ(MatchRecord(3, 1003), c.matches[0]); @@ -198,7 +198,7 @@ TEST(LogicalCombination, MultiHighlanderCombQuietSub1) { c.halt = 0; err = hs_scan(db, data.c_str(), data.size(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); ASSERT_EQ(4U, c.matches.size()); ASSERT_EQ(MatchRecord(3, 1003), c.matches[0]); @@ -237,7 +237,7 @@ TEST(LogicalCombination, MultiQuietCombQuietSub1) { c.halt = 0; err = hs_scan(db, data.c_str(), data.size(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); ASSERT_EQ(2U, c.matches.size()); ASSERT_EQ(MatchRecord(3, 1003), c.matches[0]); @@ -270,7 +270,7 @@ TEST(LogicalCombination, SingleComb2) { c.halt = 0; err = hs_scan(db, data.c_str(), data.size(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); ASSERT_EQ(13U, c.matches.size()); ASSERT_EQ(MatchRecord(6, 202), c.matches[0]); @@ -315,7 +315,7 @@ TEST(LogicalCombination, SingleCombQuietSub2) { c.halt = 0; err = hs_scan(db, data.c_str(), data.size(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); ASSERT_EQ(8U, c.matches.size()); ASSERT_EQ(MatchRecord(18, 1002), c.matches[0]); @@ -354,7 +354,7 @@ TEST(LogicalCombination, SingleComb3) { c.halt = 0; err = hs_scan(db, data.c_str(), data.size(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); ASSERT_EQ(17U, c.matches.size()); ASSERT_EQ(MatchRecord(3, 301), c.matches[0]); @@ -403,7 +403,7 @@ TEST(LogicalCombination, SingleCombQuietSub3) { c.halt = 0; err = hs_scan(db, data.c_str(), data.size(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); ASSERT_EQ(8U, c.matches.size()); ASSERT_EQ(MatchRecord(23, 303), c.matches[0]); @@ -445,7 +445,7 @@ TEST(LogicalCombination, MultiCombDupSub4) { c.halt = 0; err = hs_scan(db, data.c_str(), data.size(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); ASSERT_EQ(23U, c.matches.size()); ASSERT_EQ(MatchRecord(6, 202), c.matches[0]); @@ -503,7 +503,7 @@ TEST(LogicalCombination, MultiCombQuietDupSub4) { c.halt = 0; err = hs_scan(db, data.c_str(), data.size(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); ASSERT_EQ(17U, c.matches.size()); ASSERT_EQ(MatchRecord(18, 1002), c.matches[0]); @@ -564,7 +564,7 @@ TEST(LogicalCombination, MultiCombUniSub5) { c.halt = 0; err = hs_scan(db, data.c_str(), data.size(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); ASSERT_EQ(46U, c.matches.size()); ASSERT_EQ(MatchRecord(3, 101), c.matches[0]); @@ -656,7 +656,7 @@ TEST(LogicalCombination, MultiCombQuietUniSub5) { c.halt = 0; err = hs_scan(db, data.c_str(), data.size(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); ASSERT_EQ(30U, c.matches.size()); ASSERT_EQ(MatchRecord(3, 101), c.matches[0]); @@ -717,7 +717,7 @@ TEST(LogicalCombination, SingleCombPurelyNegative6) { c.halt = 0; err = hs_scan(db, data.c_str(), data.size(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); ASSERT_EQ(1U, c.matches.size()); ASSERT_EQ(MatchRecord(53, 1002), c.matches[0]); @@ -749,7 +749,7 @@ TEST(LogicalCombination, SingleCombQuietPurelyNegative6) { c.halt = 0; err = hs_scan(db, data.c_str(), data.size(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); ASSERT_EQ(0U, c.matches.size()); @@ -793,7 +793,7 @@ TEST(LogicalCombination, MultiCombPurelyNegativeUniSub6) { c.halt = 0; err = hs_scan(db, data.c_str(), data.size(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); ASSERT_EQ(3U, c.matches.size()); ASSERT_EQ(MatchRecord(106, 202), c.matches[0]); @@ -841,7 +841,7 @@ TEST(LogicalCombination, MultiCombPurelyNegativeUniSubEOD6) { c.halt = 0; err = hs_scan(db, data.c_str(), data.size(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); ASSERT_EQ(8U, c.matches.size()); ASSERT_EQ(MatchRecord(106, 102), c.matches[0]); @@ -897,7 +897,7 @@ TEST(LogicalCombination, MultiCombStream1) { int i; for (i = 0; i < 11; i++) { err = hs_scan_stream(stream, data[i].c_str(), data[i].size(), 0, - scratch, record_cb, (void *)&c); + scratch, record_cb, reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); } err = hs_close_stream(stream, scratch, dummy_cb, nullptr); diff --git a/unit/hyperscan/multi.cpp b/unit/hyperscan/multi.cpp index 3a344fe5..c7b62225 100644 --- a/unit/hyperscan/multi.cpp +++ b/unit/hyperscan/multi.cpp @@ -59,7 +59,7 @@ TEST(MMAdaptor, norm_cont1) { // UE-901 c.halt = 0; err = hs_scan(db, data.c_str(), data.size(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); ASSERT_EQ(3U, c.matches.size()); ASSERT_EQ(MatchRecord(4, 30), c.matches[0]); @@ -92,7 +92,7 @@ TEST(MMAdaptor, norm_cont2) { c.halt = 0; err = hs_scan(db, data.c_str(), data.size(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); ASSERT_EQ(3U, c.matches.size()); ASSERT_TRUE(c.matches.end() != find(c.matches.begin(), c.matches.end(), MatchRecord(20, 30))); @@ -125,7 +125,7 @@ TEST(MMAdaptor, norm_halt1) { c.halt = 1; err = hs_scan(db, data.c_str(), data.size(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SCAN_TERMINATED, err); ASSERT_EQ(1U, c.matches.size()); ASSERT_EQ(MatchRecord(4, 30), c.matches[0]); @@ -156,7 +156,7 @@ TEST(MMAdaptor, norm_halt2) { // UE-901 c.halt = 1; err = hs_scan(db, data.c_str(), data.size(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SCAN_TERMINATED, err); ASSERT_EQ(1U, c.matches.size()); ASSERT_EQ(MatchRecord(20, 30), c.matches[0]); @@ -187,7 +187,7 @@ TEST(MMAdaptor, high_cont1) { // UE-901 c.halt = 0; err = hs_scan(db, data.c_str(), data.size(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); ASSERT_EQ(2U, c.matches.size()); ASSERT_TRUE(c.matches.end() != find(c.matches.begin(), c.matches.end(), MatchRecord(4, 30))); @@ -219,7 +219,7 @@ TEST(MMAdaptor, high_cont2) { c.halt = 0; err = hs_scan(db, data.c_str(), data.size(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); ASSERT_EQ(2U, c.matches.size()); ASSERT_TRUE(c.matches.end() != find(c.matches.begin(), c.matches.end(), MatchRecord(20, 30))); @@ -251,7 +251,7 @@ TEST(MMAdaptor, high_halt1) { c.halt = 1; err = hs_scan(db, data.c_str(), data.size(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SCAN_TERMINATED, err); ASSERT_EQ(1U, c.matches.size()); ASSERT_EQ(MatchRecord(4, 30), c.matches[0]); @@ -282,7 +282,7 @@ TEST(MMAdaptor, high_halt2) { c.halt = 1; err = hs_scan(db, data.c_str(), data.size(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SCAN_TERMINATED, err); ASSERT_EQ(1U, c.matches.size()); ASSERT_TRUE(MatchRecord(20, 30) == c.matches[0] @@ -311,7 +311,7 @@ TEST(MPV, UE_2395) { CallBackContext c; err = hs_scan(db, data.data(), data.size(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); unsigned seen = 39; @@ -358,7 +358,7 @@ TEST(MMRoseLiteralPath, issue_141) { c.halt = 0; err = hs_scan(db, data.c_str(), data.size(), 0, scratch, record_cb, - (void *)&c); + reinterpret_cast(&c)); ASSERT_EQ(HS_SUCCESS, err); ASSERT_EQ(1U, c.matches.size()); ASSERT_EQ(MatchRecord(19, 0), c.matches[0]); diff --git a/unit/hyperscan/scratch_in_use.cpp b/unit/hyperscan/scratch_in_use.cpp index a9e8c800..cdae9496 100644 --- a/unit/hyperscan/scratch_in_use.cpp +++ b/unit/hyperscan/scratch_in_use.cpp @@ -148,7 +148,7 @@ void runVectoredTest(match_event_handler cb_func) { static int rescan_block_cb(unsigned, unsigned long long, unsigned long long, unsigned, void *ctx) { - RescanContext *rctx = (RescanContext *)ctx; + RescanContext *rctx = reinterpret_cast(ctx); rctx->matches++; const string data = "___foo___bar_"; @@ -168,7 +168,7 @@ TEST(ScratchInUse, Block) { static int rescan_stream_cb(unsigned, unsigned long long, unsigned long long, unsigned, void *ctx) { - RescanContext *rctx = (RescanContext *)ctx; + RescanContext *rctx = reinterpret_cast(ctx); rctx->matches++; const string data = "___foo___bar_"; @@ -197,7 +197,7 @@ TEST(ScratchInUse, Streaming) { static int rescan_vector_cb(unsigned, unsigned long long, unsigned long long, unsigned, void *ctx) { - RescanContext *rctx = (RescanContext *)ctx; + RescanContext *rctx = reinterpret_cast(ctx); rctx->matches++; const string data1 = "___foo_"; @@ -221,7 +221,7 @@ TEST(ScratchInUse, Vectored) { static int rescan_realloc_cb(unsigned, unsigned long long, unsigned long long, unsigned, void *ctx) { - RescanContext *rctx = (RescanContext *)ctx; + RescanContext *rctx = reinterpret_cast(ctx); rctx->matches++; auto db = makeDatabase("another db", 0, HS_MODE_BLOCK); @@ -251,7 +251,7 @@ TEST(ScratchInUse, ReallocScratchVector) { static int rescan_free_cb(unsigned, unsigned long long, unsigned long long, unsigned, void *ctx) { - RescanContext *rctx = (RescanContext *)ctx; + RescanContext *rctx = reinterpret_cast(ctx); rctx->matches++; hs_error_t err = hs_free_scratch(rctx->scratch); diff --git a/unit/hyperscan/test_util.cpp b/unit/hyperscan/test_util.cpp index 10d23962..09040bf9 100644 --- a/unit/hyperscan/test_util.cpp +++ b/unit/hyperscan/test_util.cpp @@ -41,7 +41,7 @@ using namespace std; int record_cb(unsigned id, unsigned long long, unsigned long long to, unsigned, void *ctxt) { - CallBackContext *c = (CallBackContext *)ctxt; + CallBackContext *c = reinterpret_cast(ctxt); c->matches.emplace_back(to, id); @@ -189,8 +189,8 @@ void *count_malloc(size_t n) { } allocated_count += n; - *(size_t *)pp = n; - void *p = (char *)pp + 16; + *(reinterpret_cast(pp)) = n; + void *p = static_cast(pp) + 16; return p; } @@ -200,8 +200,8 @@ void count_free(void *p) { return; } - void *pp = (char *)p - 16; - size_t n = *(size_t *)pp; + void *pp = static_cast(p) - 16; + size_t n = *(reinterpret_cast(pp)); allocated_count -= n; @@ -215,8 +215,8 @@ void *count_malloc_b(size_t n) { } allocated_count_b += n; - *(size_t *)pp = n; - void *p = (char *)pp + 32; + *(reinterpret_cast(pp)) = n; + void *p = static_cast(pp) + 32; return p; } @@ -226,8 +226,8 @@ void count_free_b(void *p) { return; } - void *pp = (char *)p - 32; - size_t n = *(size_t *)pp; + void *pp = static_cast(p) - 32; + size_t n = *(reinterpret_cast(pp)); allocated_count_b -= n; diff --git a/unit/internal/database.cpp b/unit/internal/database.cpp index 0070fbc9..7964bb93 100644 --- a/unit/internal/database.cpp +++ b/unit/internal/database.cpp @@ -70,7 +70,7 @@ TEST(CRC, alignments) { // test the crc32c function at different alignments for (u8 i = 0; i < 32; i++) { - u32 crc = Crc32c_ComputeBuf(0, (u8 *)a.data() + i, 4000); + u32 crc = Crc32c_ComputeBuf(0, reinterpret_cast(a.data()) + i, 4000); ASSERT_EQ(crc, 0x94f04377U); } } diff --git a/unit/internal/lbr.cpp b/unit/internal/lbr.cpp index 0b782569..fafe31ea 100644 --- a/unit/internal/lbr.cpp +++ b/unit/internal/lbr.cpp @@ -73,7 +73,7 @@ struct LbrTestParams { static int onMatch(u64a, u64a, ReportID, void *ctx) { - unsigned *matches = (unsigned *)ctx; + unsigned *matches = reinterpret_cast(ctx); (*matches)++; return MO_CONTINUE_MATCHING; } @@ -191,7 +191,7 @@ TEST_P(LbrTest, MatchMin) { const string corpus = matchingCorpus(params.min); initQueue(); - q.buffer = (const u8 *)corpus.c_str(); + q.buffer = reinterpret_cast(corpus.c_str()); q.length = corpus.length(); u64a end = corpus.length(); @@ -238,7 +238,7 @@ TEST_P(LbrTest, QueueExecToMatch) { const string corpus = matchingCorpus(params.min); initQueue(); - q.buffer = (const u8 *)corpus.c_str(); + q.buffer = reinterpret_cast(corpus.c_str()); q.length = corpus.length(); u64a end = corpus.length(); diff --git a/unit/internal/multi_bit.cpp b/unit/internal/multi_bit.cpp index 7bb4a1a8..d017f8a5 100644 --- a/unit/internal/multi_bit.cpp +++ b/unit/internal/multi_bit.cpp @@ -305,7 +305,7 @@ TEST(MultiBit, It3) { const size_t test_size = 60; mmbit_holder ba(test_size, 4); - fill_n((u8 *)ba, mmbit_size(test_size) + 4, 0xff); + fill_n(static_cast(ba), mmbit_size(test_size) + 4, 0xff); mmbit_clear(ba, test_size); diff --git a/unit/internal/pack_bits.cpp b/unit/internal/pack_bits.cpp index 453dccfd..37dfff3b 100644 --- a/unit/internal/pack_bits.cpp +++ b/unit/internal/pack_bits.cpp @@ -66,13 +66,13 @@ void pack_bits(char *out, const u64a *v, const u32 *bits, template <> void unpack_bits(u32 *v, const char *in, const u32 *bits, unsigned elements) { - return unpack_bits_32(v, (const u8 *)in, bits, elements); + return unpack_bits_32(v, reinterpret_cast(in), bits, elements); } template <> void unpack_bits(u64a *v, const char *in, const u32 *bits, unsigned elements) { - return unpack_bits_64(v, (const u8 *)in, bits, elements); + return unpack_bits_64(v, reinterpret_cast(in), bits, elements); } template diff --git a/unit/internal/repeat.cpp b/unit/internal/repeat.cpp index 41a54c5f..b1792e1c 100644 --- a/unit/internal/repeat.cpp +++ b/unit/internal/repeat.cpp @@ -738,7 +738,7 @@ protected: ptr = new char[sizeof(RepeatInfo) + sizeof(u64a) * (rsi.patchSize + 2)]; - info = (struct RepeatInfo *)ptr; + info = reinterpret_cast(ptr); info->type = REPEAT_SPARSE_OPTIMAL_P; info->repeatMin = test_info.repeatMin; @@ -756,7 +756,7 @@ protected: info->patchesOffset = rsi.patchesOffset; u32 repeatMax = info->patchSize; - u64a *table = (u64a *)(ROUNDUP_PTR((ptr + sizeof(RepeatInfo)), + u64a *table = reinterpret_cast(ROUNDUP_PTR((ptr + sizeof(RepeatInfo)), alignof(u64a))); for (u32 i = 0; i < repeatMax + 1; i++) { table[i] = rsi.table[i]; @@ -859,8 +859,8 @@ TEST_P(SparseOptimalTest, TwoTopsNeg) { } } - const struct RepeatRingControl *xs = (const struct RepeatRingControl *) - ctrl; + const struct RepeatRingControl *xs = reinterpret_cast + (ctrl); ASSERT_EQ(exit2, repeatNextMatch(info, ctrl, state, MAX(xs->offset, exit))); ASSERT_EQ(exit2, repeatNextMatch(info, ctrl, state, diff --git a/unit/internal/rvermicelli.cpp b/unit/internal/rvermicelli.cpp index 5cd52e4d..f5bf302c 100644 --- a/unit/internal/rvermicelli.cpp +++ b/unit/internal/rvermicelli.cpp @@ -39,8 +39,8 @@ TEST(RVermicelli, ExecNoMatch1) { for (size_t i = 0; i < 16; i++) { for (size_t j = 0; j < 16; j++) { - const u8 *begin = (const u8 *)t1 + i; - const u8 *end = (const u8 *)t1 + strlen(t1) - j; + const u8 *begin = reinterpret_cast(t1) + i; + const u8 *end = reinterpret_cast(t1) + strlen(t1) - j; const u8 *rv = rvermicelliExec('a', 0, begin, end); ASSERT_EQ(begin - 1, rv); @@ -58,12 +58,12 @@ TEST(RVermicelli, Exec1) { char t1[] = "bbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbb"; for (size_t i = 0; i < 16; i++) { - const u8 *rv = rvermicelliExec('a', 0, (u8 *)t1, - (u8 *)t1 + strlen(t1) - i); + const u8 *rv = rvermicelliExec('a', 0, reinterpret_cast(t1), + reinterpret_cast(t1) + strlen(t1) - i); ASSERT_EQ((size_t)t1 + 48, (size_t)rv); - rv = rvermicelliExec('A', 1, (u8 *)t1 + i, (u8 *)t1 + strlen(t1)); + rv = rvermicelliExec('A', 1, reinterpret_cast(t1) + i, reinterpret_cast(t1) + strlen(t1)); ASSERT_EQ((size_t)t1 + 48, (size_t)rv); } @@ -73,12 +73,12 @@ TEST(RVermicelli, Exec2) { char t1[] = "bbbbbbbbbbbbbbbbbabbbbbbbbaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbb"; for (size_t i = 0; i < 16; i++) { - const u8 *rv = rvermicelliExec('a', 0, (u8 *)t1, - (u8 *)t1 + strlen(t1) - i); + const u8 *rv = rvermicelliExec('a', 0, reinterpret_cast(t1), + reinterpret_cast(t1) + strlen(t1) - i); ASSERT_EQ((size_t)t1 + 48, (size_t)rv); - rv = rvermicelliExec('A', 1, (u8 *)t1, (u8 *)t1 + strlen(t1) - i); + rv = rvermicelliExec('A', 1, reinterpret_cast(t1), reinterpret_cast(t1) + strlen(t1) - i); ASSERT_EQ((size_t)t1 + 48, (size_t)rv); } @@ -88,12 +88,12 @@ TEST(RVermicelli, Exec3) { char t1[] = "bbbbbbbbbbbbbbbbbabbbbbbbbaaaaaaaaaaaaaaaaaaaaaaAbbbbbbbbbbbbbbbbbbbbbb"; for (size_t i = 0; i < 16; i++) { - const u8 *rv = rvermicelliExec('a', 0, (u8 *)t1, - (u8 *)t1 + strlen(t1) - i); + const u8 *rv = rvermicelliExec('a', 0, reinterpret_cast(t1), + reinterpret_cast(t1)+ strlen(t1) - i); ASSERT_EQ((size_t)t1 + 47, (size_t)rv); - rv = rvermicelliExec('A', 1, (u8 *)t1, (u8 *)t1 + strlen(t1) - i); + rv = rvermicelliExec('A', 1, reinterpret_cast(t1), reinterpret_cast(t1) + strlen(t1) - i); ASSERT_EQ((size_t)t1 + 48, (size_t)rv); } @@ -104,11 +104,11 @@ TEST(RVermicelli, Exec4) { for (size_t i = 0; i < 31; i++) { t1[16 + i] = 'a'; - const u8 *rv = rvermicelliExec('a', 0, (u8 *)t1, (u8 *)t1 + strlen(t1)); + const u8 *rv = rvermicelliExec('a', 0, reinterpret_cast(t1), reinterpret_cast(t1) + strlen(t1)); ASSERT_EQ((size_t)&t1[16 + i], (size_t)rv); - rv = rvermicelliExec('A', 1, (u8 *)t1, (u8 *)t1 + strlen(t1)); + rv = rvermicelliExec('A', 1, reinterpret_cast(t1), reinterpret_cast(t1) + strlen(t1)); ASSERT_EQ((size_t)&t1[16 + i], (size_t)rv); } @@ -116,7 +116,7 @@ TEST(RVermicelli, Exec4) { TEST(RNVermicelli, ExecNoMatch1) { char t1[] = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; - const u8 *buf = (const u8 *)t1; + const u8 *buf = reinterpret_cast(t1); for (size_t i = 0; i < 16; i++) { SCOPED_TRACE(i); @@ -136,7 +136,7 @@ TEST(RNVermicelli, ExecNoMatch1) { TEST(RNVermicelli, Exec1) { char t1[] = "bbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbb"; - const u8 *buf = (const u8 *)t1; + const u8 *buf = reinterpret_cast(t1); for (size_t i = 0; i < 16; i++) { SCOPED_TRACE(i); @@ -152,7 +152,7 @@ TEST(RNVermicelli, Exec1) { TEST(RNVermicelli, Exec2) { char t1[] = "bbbbbbbbbbbbbbbbbabbbbbbbbaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbb"; - const u8 *buf = (const u8 *)t1; + const u8 *buf = reinterpret_cast(t1); for (size_t i = 0; i < 16; i++) { SCOPED_TRACE(i); @@ -168,7 +168,7 @@ TEST(RNVermicelli, Exec2) { TEST(RNVermicelli, Exec3) { char t1[] = "bbbbbbbbbbbbbbbbbabbbbbbbbaaaaaaaaaaaaaaaaaaaaaaAbbbbbbbbbbbbbbbbbbbbbb"; - const u8 *buf = (const u8 *)t1; + const u8 *buf = reinterpret_cast(t1); for (size_t i = 0; i < 16; i++) { SCOPED_TRACE(i); @@ -184,7 +184,7 @@ TEST(RNVermicelli, Exec3) { TEST(RNVermicelli, Exec4) { char t1[] = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; - const u8 *buf = (const u8 *)t1; + const u8 *buf = reinterpret_cast(t1); for (size_t i = 0; i < 31; i++) { SCOPED_TRACE(i); @@ -204,23 +204,23 @@ TEST(RDoubleVermicelli, Exec1) { char t1[] = "bbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbb"; for (size_t i = 0; i < 16; i++) { - const u8 *rv = rvermicelliDoubleExec('a', 'b', 0, (u8 *)t1, - (u8 *)t1 + strlen(t1) - i); + const u8 *rv = rvermicelliDoubleExec('a', 'b', 0, reinterpret_cast(t1), + reinterpret_cast(t1) + strlen(t1) - i); ASSERT_EQ((size_t)t1 + 50, (size_t)rv); - rv = rvermicelliDoubleExec('A', 'B', 1, (u8 *)t1 + i, - (u8 *)t1 + strlen(t1)); + rv = rvermicelliDoubleExec('A', 'B', 1, reinterpret_cast(t1)+ i, + reinterpret_cast(t1) + strlen(t1)); ASSERT_EQ((size_t)t1 + 50, (size_t)rv); - rv = rvermicelliDoubleExec('b', 'a', 0, (u8 *)t1 + i, - (u8 *)t1 + strlen(t1)); + rv = rvermicelliDoubleExec('b', 'a', 0, reinterpret_cast(t1) + i, + reinterpret_cast(t1) + strlen(t1)); ASSERT_EQ((size_t)t1 + 49, (size_t)rv); - rv = rvermicelliDoubleExec('B', 'A', 1, (u8 *)t1 + i, - (u8 *)t1 + strlen(t1)); + rv = rvermicelliDoubleExec('B', 'A', 1, reinterpret_cast(t1) + i, + reinterpret_cast(t1) + strlen(t1)); ASSERT_EQ((size_t)t1 + 49, (size_t)rv); } @@ -230,13 +230,13 @@ TEST(RDoubleVermicelli, Exec2) { char t1[] = "bbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbaaaaabbbbbbbbbbbbbbbbbb"; for (size_t i = 0; i < 16; i++) { - const u8 *rv = rvermicelliDoubleExec('a', 'a', 0, (u8 *)t1, - (u8 *)t1 + strlen(t1) - i); + const u8 *rv = rvermicelliDoubleExec('a', 'a', 0, reinterpret_cast(t1), + reinterpret_cast(t1) + strlen(t1) - i); ASSERT_EQ((size_t)t1 + 52, (size_t)rv); - rv = rvermicelliDoubleExec('A', 'A', 1, (u8 *)t1, - (u8 *)t1 + strlen(t1) - i); + rv = rvermicelliDoubleExec('A', 'A', 1, reinterpret_cast(t1), + reinterpret_cast(t1) + strlen(t1) - i); ASSERT_EQ((size_t)t1 + 52, (size_t)rv); } @@ -247,23 +247,23 @@ TEST(RDoubleVermicelli, Exec3) { char t1[] = "bbbbbbbbbbbbbbbbbaAaaAAaaaaaaaaaaaaaaaaaabbbbbbbaaaaabbbbbbbbbbbbbbbbbb"; for (size_t i = 0; i < 16; i++) { - const u8 *rv = rvermicelliDoubleExec('A', 'a', 0, (u8 *)t1, - (u8 *)t1 + strlen(t1) - i ); + const u8 *rv = rvermicelliDoubleExec('A', 'a', 0, reinterpret_cast(t1), + reinterpret_cast(t1) + strlen(t1) - i ); ASSERT_EQ((size_t)t1 + 23, (size_t)rv); - rv = rvermicelliDoubleExec('A', 'A', 1, (u8 *)t1, - (u8 *)t1 + strlen(t1) - i); + rv = rvermicelliDoubleExec('A', 'A', 1, reinterpret_cast(t1), + reinterpret_cast(t1) + strlen(t1) - i); ASSERT_EQ((size_t)t1 + 52, (size_t)rv); - rv = rvermicelliDoubleExec('A', 'A', 0, (u8 *)t1, - (u8 *)t1 + strlen(t1) - i); + rv = rvermicelliDoubleExec('A', 'A', 0, reinterpret_cast(t1), + reinterpret_cast(t1) + strlen(t1) - i); ASSERT_EQ((size_t)t1 + 22, (size_t)rv); - rv = rvermicelliDoubleExec('a', 'A', 0, (u8 *)t1, - (u8 *)t1 + strlen(t1) - i); + rv = rvermicelliDoubleExec('a', 'A', 0, reinterpret_cast(t1), + reinterpret_cast(t1) + strlen(t1) - i); ASSERT_EQ((size_t)t1 + 21, (size_t)rv); } @@ -275,11 +275,11 @@ TEST(RDoubleVermicelli, Exec4) { for (size_t i = 0; i < 31; i++) { t1[32 + i] = 'a'; t1[32 + i - 1] = 'a'; - const u8 *rv = rvermicelliDoubleExec('a', 'a', 0, (u8 *)t1, - (u8 *)t1 + strlen(t1)); + const u8 *rv = rvermicelliDoubleExec('a', 'a', 0, reinterpret_cast(t1), + reinterpret_cast(t1) + strlen(t1)); ASSERT_EQ((size_t)&t1[32 + i], (size_t)rv); - rv = rvermicelliDoubleExec('A', 'A', 1, (u8 *)t1, (u8 *)t1 + strlen(t1)); + rv = rvermicelliDoubleExec('A', 'A', 1, reinterpret_cast(t1), reinterpret_cast(t1) + strlen(t1)); ASSERT_EQ((size_t)&t1[32 + i], (size_t)rv); } @@ -291,13 +291,13 @@ TEST(RDoubleVermicelli, Exec5) { for (size_t i = 0; i < 16; i++) { for (size_t j = 1; j <= 16; j++) { t1[strlen(t1) - i - j] = 'a'; - const u8 *rv = rvermicelliDoubleExec('b', 'a', 0, (u8 *)t1, - (u8 *)t1 + strlen(t1) - i); + const u8 *rv = rvermicelliDoubleExec('b', 'a', 0, reinterpret_cast(t1), + reinterpret_cast(t1) + strlen(t1) - i); ASSERT_EQ((size_t)&t1[strlen(t1) - i - j], (size_t)rv); - rv = rvermicelliDoubleExec('B', 'A', 1, (u8 *)t1, - (u8 *)t1 + strlen(t1) -i ); + rv = rvermicelliDoubleExec('B', 'A', 1, reinterpret_cast(t1), + reinterpret_cast(t1) + strlen(t1) -i ); ASSERT_EQ((size_t)&t1[strlen(t1) - i - j], (size_t)rv);