diff --git a/src/database.h b/src/database.h index 1b94f1b0..b0a9c01b 100644 --- a/src/database.h +++ b/src/database.h @@ -112,6 +112,7 @@ struct hs_database { static really_inline const void *hs_get_bytecode(const struct hs_database *db) { + // cppcheck-suppress cstyleCast return ((const char *)db + db->bytecode); } diff --git a/src/fdr/fdr_confirm.h b/src/fdr/fdr_confirm.h index a23082cc..3615a6f8 100644 --- a/src/fdr/fdr_confirm.h +++ b/src/fdr/fdr_confirm.h @@ -84,9 +84,10 @@ struct FDRConfirm { static really_inline const u32 *getConfirmLitIndex(const struct FDRConfirm *fdrc) { + // cppcheck-suppress cstyleCast const u8 *base = (const u8 *)fdrc; - const u32 *litIndex = - (const u32 *)(base + ROUNDUP_N(sizeof(*fdrc), alignof(u32))); + // cppcheck-suppress cstyleCast + const u32 *litIndex =(const u32 *)(base + ROUNDUP_N(sizeof(*fdrc), alignof(u32))); assert(ISALIGNED(litIndex)); return litIndex; } diff --git a/src/fdr/fdr_dump.cpp b/src/fdr/fdr_dump.cpp index 1dda751a..1390c4f2 100644 --- a/src/fdr/fdr_dump.cpp +++ b/src/fdr/fdr_dump.cpp @@ -74,9 +74,9 @@ void dumpLitIndex(const FDRConfirm *fdrc, FILE *f) { static void dumpConfirms(const void *fdr_base, u32 conf_offset, u32 num_confirms, FILE *f) { - const u32 *conf = (const u32 *)((const char *)fdr_base + conf_offset); + const u32 *conf = reinterpret_cast(reinterpret_cast(fdr_base) + conf_offset); for (u32 i = 0; i < num_confirms; i++) { - const auto *fdrc = (const FDRConfirm *)((const char *)conf + conf[i]); + const auto *fdrc = reinterpret_cast(reinterpret_cast(conf) + conf[i]); fprintf(f, " confirm %u\n", i); fprintf(f, " andmsk 0x%016llx\n", fdrc->andmsk); fprintf(f, " mult 0x%016llx\n", fdrc->mult); @@ -157,7 +157,7 @@ void dumpTeddy(const Teddy *teddy, FILE *f) { fprintf(f, " buckets %u\n", des->getNumBuckets()); fprintf(f, " packed %s\n", des->packed ? "true" : "false"); fprintf(f, " strings %u\n", teddy->numStrings); - fprintf(f, " size %zu bytes\n", fdrSize((const FDR *)teddy)); + fprintf(f, " size %zu bytes\n", fdrSize(reinterpret_cast(teddy))); fprintf(f, " max length %u\n", teddy->maxStringLen); fprintf(f, " floodoff %u (%x)\n", teddy->floodOffset, teddy->floodOffset); @@ -165,7 +165,7 @@ void dumpTeddy(const Teddy *teddy, FILE *f) { u32 maskWidth = des->getNumBuckets() / 8; size_t headerSize = sizeof(Teddy); - const u8 *teddy_base = (const u8 *)teddy; + const u8 *teddy_base = reinterpret_cast(teddy); const u8 *baseMsk = teddy_base + ROUNDUP_CL(headerSize); dumpTeddyMasks(baseMsk, des->numMasks, maskWidth, f); size_t maskLen = des->numMasks * 16 * 2 * maskWidth; @@ -201,7 +201,7 @@ void dumpFDR(const FDR *fdr, FILE *f) { void fdrPrintStats(const FDR *fdr, FILE *f) { if (fdrIsTeddy(fdr)) { - dumpTeddy((const Teddy *)fdr, f); + dumpTeddy(reinterpret_cast(fdr), f); } else { dumpFDR(fdr, f); } diff --git a/src/hwlm/hwlm_dump.cpp b/src/hwlm/hwlm_dump.cpp index 59353eee..b3a681de 100644 --- a/src/hwlm/hwlm_dump.cpp +++ b/src/hwlm/hwlm_dump.cpp @@ -53,10 +53,10 @@ void hwlmGenerateDumpFiles(const HWLM *h, const string &base) { switch (h->type) { case HWLM_ENGINE_NOOD: - noodPrintStats((const noodTable *)HWLM_C_DATA(h), f); + noodPrintStats(reinterpret_cast(HWLM_C_DATA(h)), f); break; case HWLM_ENGINE_FDR: - fdrPrintStats((const FDR *)HWLM_C_DATA(h), f); + fdrPrintStats(reinterpret_cast(HWLM_C_DATA(h)), f); break; default: fprintf(f, "\n"); diff --git a/src/hwlm/noodle_build.cpp b/src/hwlm/noodle_build.cpp index 74dfbd2c..e92f2985 100644 --- a/src/hwlm/noodle_build.cpp +++ b/src/hwlm/noodle_build.cpp @@ -156,7 +156,7 @@ void noodPrintStats(const noodTable *n, FILE *f) { n->msk_len); fprintf(f, "String: "); for (u32 i = 0; i < n->msk_len; i++) { - const u8 *m = (const u8 *)&n->cmp; + const u8 *m = reinterpret_cast(&n->cmp); if (isgraph(m[i]) && m[i] != '\\') { fprintf(f, "%c", m[i]); } else { diff --git a/src/nfa/accel_dump.cpp b/src/nfa/accel_dump.cpp index 4c33b351..c2c5e01f 100644 --- a/src/nfa/accel_dump.cpp +++ b/src/nfa/accel_dump.cpp @@ -210,31 +210,31 @@ void dumpAccelInfo(FILE *f, const AccelAux &accel) { break; case ACCEL_SHUFTI: { fprintf(f, "\n"); - dumpShuftiMasks(f, (const u8 *)&accel.shufti.lo, - (const u8 *)&accel.shufti.hi); - dumpShuftiCharReach(f, (const u8 *)&accel.shufti.lo, - (const u8 *)&accel.shufti.hi); + dumpShuftiMasks(f, reinterpret_cast(&accel.shufti.lo), + reinterpret_cast(&accel.shufti.hi)); + dumpShuftiCharReach(f, reinterpret_cast(&accel.shufti.lo), + reinterpret_cast(&accel.shufti.hi)); break; } case ACCEL_DSHUFTI: fprintf(f, "\n"); fprintf(f, "mask 1\n"); - dumpShuftiMasks(f, (const u8 *)&accel.dshufti.lo1, - (const u8 *)&accel.dshufti.hi1); + dumpShuftiMasks(f, reinterpret_cast(&accel.dshufti.lo1), + reinterpret_cast(&accel.dshufti.hi1)); fprintf(f, "mask 2\n"); - dumpShuftiMasks(f, (const u8 *)&accel.dshufti.lo2, - (const u8 *)&accel.dshufti.hi2); - dumpDShuftiCharReach(f, (const u8 *)&accel.dshufti.lo1, - (const u8 *)&accel.dshufti.hi1, - (const u8 *)&accel.dshufti.lo2, - (const u8 *)&accel.dshufti.hi2); + dumpShuftiMasks(f, reinterpret_cast(&accel.dshufti.lo2), + reinterpret_cast(&accel.dshufti.hi2)); + dumpDShuftiCharReach(f, reinterpret_cast(&accel.dshufti.lo1), + reinterpret_cast(&accel.dshufti.hi1), + reinterpret_cast(&accel.dshufti.lo2), + reinterpret_cast(&accel.dshufti.hi2)); break; case ACCEL_TRUFFLE: { fprintf(f, "\n"); - dumpTruffleMasks(f, (const u8 *)&accel.truffle.mask1, - (const u8 *)&accel.truffle.mask2); - dumpTruffleCharReach(f, (const u8 *)&accel.truffle.mask1, - (const u8 *)&accel.truffle.mask2); + dumpTruffleMasks(f, reinterpret_cast(&accel.truffle.mask1), + reinterpret_cast(&accel.truffle.mask2)); + dumpTruffleCharReach(f, reinterpret_cast(&accel.truffle.mask1), + reinterpret_cast(&accel.truffle.mask2)); break; } default: diff --git a/src/nfa/castle_dump.cpp b/src/nfa/castle_dump.cpp index 595b98ec..9bf9041e 100644 --- a/src/nfa/castle_dump.cpp +++ b/src/nfa/castle_dump.cpp @@ -56,7 +56,7 @@ namespace ue2 { static void dumpTextSubCastle(const SubCastle &sub, FILE *f) { const RepeatInfo *info = - (const RepeatInfo *)((const char *)&sub + sub.repeatInfoOffset); + reinterpret_cast(reinterpret_cast(&sub) + sub.repeatInfoOffset); fprintf(f, " repeat model: %s\n", repeatTypeName(info->type)); fprintf(f, " repeat bounds: {%u, %u}\n", info->repeatMin, info->repeatMax); @@ -69,7 +69,7 @@ void dumpTextSubCastle(const SubCastle &sub, FILE *f) { } void nfaExecCastle_dump(const struct NFA *nfa, const string &base) { - const Castle *c = (const Castle *)getImplNfa(nfa); + const Castle *c = reinterpret_cast(getImplNfa(nfa)); StdioFile f(base + ".txt", "w"); @@ -88,15 +88,15 @@ void nfaExecCastle_dump(const struct NFA *nfa, const string &base) { fprintf(f, "negated verm, scanning for 0x%02x\n", c->u.verm.c); break; case CASTLE_SHUFTI: { - const CharReach cr = shufti2cr((const u8 *)&c->u.shuf.mask_lo, - (const u8 *)&c->u.shuf.mask_hi); + const CharReach cr = shufti2cr(reinterpret_cast(&c->u.shuf.mask_lo), + reinterpret_cast(&c->u.shuf.mask_hi)); fprintf(f, "shufti, scanning for %s (%zu chars)\n", describeClass(cr).c_str(), cr.count()); break; } case CASTLE_TRUFFLE: { - const CharReach cr = truffle2cr((const u8 *)&c->u.truffle.mask1, - (const u8 *)&c->u.truffle.mask2); + const CharReach cr = truffle2cr(reinterpret_cast(&c->u.truffle.mask1), + reinterpret_cast(&c->u.truffle.mask2)); fprintf(f, "truffle, scanning for %s (%zu chars)\n", describeClass(cr).c_str(), cr.count()); break; @@ -112,7 +112,7 @@ void nfaExecCastle_dump(const struct NFA *nfa, const string &base) { fprintf(f, "\n"); const SubCastle *sub = - (const SubCastle *)((const char *)c + sizeof(Castle)); + reinterpret_cast(reinterpret_cast(c) + sizeof(Castle)); for (u32 i = 0; i < c->numRepeats; i++) { fprintf(f, "Sub %u:\n", i); dumpTextSubCastle(sub[i], f); diff --git a/src/nfa/gough_internal.h b/src/nfa/gough_internal.h index 8bf06e0f..a97ba258 100644 --- a/src/nfa/gough_internal.h +++ b/src/nfa/gough_internal.h @@ -92,6 +92,7 @@ struct gough_info { static really_inline const struct gough_info *get_gough(const struct mcclellan *m) { assert(m->haig_offset); + // cppcheck-suppress cstyleCast const char *n = (const char *)m - sizeof(struct NFA); return (const struct gough_info *)(n + m->haig_offset); } @@ -102,6 +103,7 @@ const u32 *get_gough_top_offsets(const struct mcclellan *m) { if (!g->top_prog_offset) { return NULL; } + // cppcheck-suppress cstyleCast const char *n = (const char *)m - sizeof(struct NFA); return (const u32 *)(n + g->top_prog_offset); } diff --git a/src/nfa/goughdump.cpp b/src/nfa/goughdump.cpp index 5f710612..060d6046 100644 --- a/src/nfa/goughdump.cpp +++ b/src/nfa/goughdump.cpp @@ -59,14 +59,14 @@ namespace ue2 { static void goughGetTransitions(const NFA *n, u16 s, u16 *t) { assert(isGoughType(n->type)); - const mcclellan *m = (const mcclellan *)getImplNfa(n); + const mcclellan *m = reinterpret_cast(getImplNfa(n)); const mstate_aux *aux = getAux(n, s); const u32 as = m->alphaShift; const char *sher_base - = (const char *)m - sizeof(struct NFA) + m->sherman_offset; + = reinterpret_cast(m) - sizeof(struct NFA) + m->sherman_offset; if (n->type == GOUGH_NFA_8) { - const u8 *succ_table = (const u8 *)((const char *)m + sizeof(mcclellan)); + const u8 *succ_table = reinterpret_cast(reinterpret_cast(m) + sizeof(mcclellan)); for (u16 c = 0; c < N_CHARS; c++) { t[c] = succ_table[((u32)s << as) + m->remap[c]]; } @@ -76,14 +76,14 @@ void goughGetTransitions(const NFA *n, u16 s, u16 *t) { if (s >= m->sherman_limit) { const char *state_base = findShermanState(m, sher_base, m->sherman_limit, s); - base_s = *(const u16 *)(state_base + SHERMAN_DADDY_OFFSET); + base_s = *(reinterpret_cast(state_base + SHERMAN_DADDY_OFFSET)); } - const u16 *succ_table = (const u16 *)((const char *)m + const u16 *succ_table = reinterpret_cast(reinterpret_cast(m) + sizeof(mcclellan)); for (u16 c = 0; c < N_CHARS; c++) { const u8 *addr - = (const u8*)(succ_table + (((u32)base_s << as) + m->remap[c])); + = reinterpret_cast(succ_table + (((u32)base_s << as) + m->remap[c])); t[c] = unaligned_load_u16(addr); t[c] &= STATE_MASK; } @@ -91,15 +91,15 @@ void goughGetTransitions(const NFA *n, u16 s, u16 *t) { if (s >= m->sherman_limit) { const char *state_base = findShermanState(m, sher_base, m->sherman_limit, s); - u8 len = *(const u8 *)(SHERMAN_LEN_OFFSET + state_base); - const u8 *chars = (const u8 *)state_base + SHERMAN_CHARS_OFFSET; + u8 len = *(reinterpret_cast(SHERMAN_LEN_OFFSET + state_base)); + const u8 *chars = reinterpret_cast(state_base) + SHERMAN_CHARS_OFFSET; const u16 *states - = (const u16 *)(state_base + SHERMAN_STATES_OFFSET(len)); + = reinterpret_cast(state_base + SHERMAN_STATES_OFFSET(len)); for (u8 i = 0; i < len; i++) { for (u16 c = 0; c < N_CHARS; c++) { if (m->remap[c] != chars[i]) { - t[c] = unaligned_load_u16((const u8*)&states[i]) + t[c] = unaligned_load_u16(reinterpret_cast(&states[i])) & STATE_MASK; } } @@ -116,14 +116,14 @@ void describeNode(const NFA *n, const mcclellan *m, u16 i, FILE *f) { bool isSherman = m->sherman_limit && i >= m->sherman_limit; const char *sher_base - = (const char *)m - sizeof(NFA) + m->sherman_offset; + = reinterpret_cast(m) - sizeof(NFA) + m->sherman_offset; fprintf(f, "%u [ width = 1, fixedsize = true, fontsize = 12, " "label = \"%u%s\" ]; \n", i, i, isSherman ? "w":""); if (aux->accel_offset) { dumpAccelDot(f, i, - &((const gough_accel *)((const char *)m + aux->accel_offset))->accel); + &((const gough_accel *)(reinterpret_cast(m) + aux->accel_offset))->accel); } if (aux->accept_eod) { @@ -151,7 +151,7 @@ void describeNode(const NFA *n, const mcclellan *m, u16 i, FILE *f) { const char *sherman_state = findShermanState(m, sher_base, m->sherman_limit, i); fprintf(f, "%u [ fillcolor = lightblue style=filled ];\n", i); - u16 daddy = *(const u16 *)(sherman_state + SHERMAN_DADDY_OFFSET); + u16 daddy = *(reinterpret_cast(sherman_state + SHERMAN_DADDY_OFFSET)); if (daddy) { fprintf(f, "%u -> %u [ color=royalblue style=dashed weight=0.1]\n", i, daddy); @@ -197,7 +197,7 @@ void dump_programs(FILE *f, const NFA *nfa, for (set, u32 > >::const_iterator it = prog_dump.begin(); it != prog_dump.end(); ++it) { assert(it->second); - const gough_ins *p = (const gough_ins *)((const u8 *)nfa + it->second); + const gough_ins *p = reinterpret_cast(reinterpret_cast(nfa) + it->second); dump_program(f, it->first, p); } } @@ -205,17 +205,17 @@ void dump_programs(FILE *f, const NFA *nfa, static void dumpTransitions(const NFA *nfa, FILE *f, set, u32 > > *prog_dump) { - const mcclellan *m = (const mcclellan *)getImplNfa(nfa); + const mcclellan *m = reinterpret_cast(getImplNfa(nfa)); const gough_info *g = get_gough(m); u32 alphaSize = 1U << m->alphaShift; - const u32 *prog_offset_table = (const u32 *)(g + 1); + const u32 *prog_offset_table = reinterpret_cast(g + 1); for (u16 i = 0; i < m->state_count; i++) { fprintf(f, "%05hu", i); const mstate_aux *aux = getAux(nfa, i); if (aux->accel_offset) { - dumpAccelText(f, (const union AccelAux *)((const char *)m + + dumpAccelText(f, reinterpret_cast(reinterpret_cast(m) + aux->accel_offset)); } @@ -263,7 +263,7 @@ void dumpTransitions(const NFA *nfa, FILE *f, static void nfaExecGough8_dumpDot(const struct NFA *nfa, FILE *f) { assert(nfa->type == GOUGH_NFA_8); - const mcclellan *m = (const mcclellan *)getImplNfa(nfa); + const mcclellan *m = reinterpret_cast(getImplNfa(nfa)); dumpDotPreambleDfa(f); @@ -284,7 +284,7 @@ static void nfaExecGough8_dumpText(const struct NFA *nfa, FILE *f) { assert(nfa->type == GOUGH_NFA_8); - const mcclellan *m = (const mcclellan *)getImplNfa(nfa); + const mcclellan *m = reinterpret_cast(getImplNfa(nfa)); fprintf(f, "gough 8\n"); fprintf(f, "report: %u, states %u, length %u\n", m->arb_report, @@ -308,7 +308,7 @@ void nfaExecGough8_dumpText(const struct NFA *nfa, FILE *f) { static void nfaExecGough16_dumpDot(const struct NFA *nfa, FILE *f) { assert(nfa->type == GOUGH_NFA_16); - const mcclellan *m = (const mcclellan *)getImplNfa(nfa); + const mcclellan *m = reinterpret_cast(getImplNfa(nfa)); dumpDotPreambleDfa(f); @@ -328,7 +328,7 @@ void nfaExecGough16_dumpDot(const struct NFA *nfa, FILE *f) { static void nfaExecGough16_dumpText(const struct NFA *nfa, FILE *f) { assert(nfa->type == GOUGH_NFA_16); - const mcclellan *m = (const mcclellan *)getImplNfa(nfa); + const mcclellan *m = reinterpret_cast(getImplNfa(nfa)); // const gough_info *h = get_gough(m); fprintf(f, "gough 16\n"); diff --git a/src/nfa/lbr_dump.cpp b/src/nfa/lbr_dump.cpp index 89da6871..813af084 100644 --- a/src/nfa/lbr_dump.cpp +++ b/src/nfa/lbr_dump.cpp @@ -56,7 +56,7 @@ namespace ue2 { static void lbrDumpCommon(const lbr_common *lc, FILE *f) { const RepeatInfo *info - = (const RepeatInfo *)((const char *)lc + lc->repeatInfoOffset); + = reinterpret_cast(reinterpret_cast(lc) + lc->repeatInfoOffset); fprintf(f, "Limited Bounded Repeat\n"); fprintf(f, "\n"); fprintf(f, "repeat model: %s\n", repeatTypeName(info->type)); @@ -70,7 +70,7 @@ void lbrDumpCommon(const lbr_common *lc, FILE *f) { void nfaExecLbrDot_dump(const NFA *nfa, const string &base) { assert(nfa); assert(nfa->type == LBR_NFA_DOT); - const lbr_dot *ld = (const lbr_dot *)getImplNfa(nfa); + const lbr_dot *ld = reinterpret_cast(getImplNfa(nfa)); StdioFile f(base + ".txt", "w"); lbrDumpCommon(&ld->common, f); fprintf(f, "DOT model\n"); @@ -81,7 +81,7 @@ void nfaExecLbrDot_dump(const NFA *nfa, const string &base) { void nfaExecLbrVerm_dump(const NFA *nfa, const string &base) { assert(nfa); assert(nfa->type == LBR_NFA_VERM); - const lbr_verm *lv = (const lbr_verm *)getImplNfa(nfa); + const lbr_verm *lv = reinterpret_cast(getImplNfa(nfa)); StdioFile f(base + ".txt", "w"); lbrDumpCommon(&lv->common, f); fprintf(f, "VERM model, scanning for 0x%02x\n", lv->c); @@ -92,7 +92,7 @@ void nfaExecLbrVerm_dump(const NFA *nfa, const string &base) { void nfaExecLbrNVerm_dump(const NFA *nfa, const string &base) { assert(nfa); assert(nfa->type == LBR_NFA_NVERM); - const lbr_verm *lv = (const lbr_verm *)getImplNfa(nfa); + const lbr_verm *lv = reinterpret_cast(getImplNfa(nfa)); StdioFile f(base + ".txt", "w"); lbrDumpCommon(&lv->common, f); fprintf(f, "NEGATED VERM model, scanning for 0x%02x\n", lv->c); @@ -106,11 +106,11 @@ void nfaExecLbrShuf_dump(const NFA *nfa, const string &base) { StdioFile f(base + ".txt", "w"); - const lbr_shuf *ls = (const lbr_shuf *)getImplNfa(nfa); + const lbr_shuf *ls = reinterpret_cast(getImplNfa(nfa)); lbrDumpCommon(&ls->common, f); - CharReach cr = shufti2cr((const u8 *)&ls->mask_lo, - (const u8 *)&ls->mask_hi); + CharReach cr = shufti2cr(reinterpret_cast(&ls->mask_lo), + reinterpret_cast(&ls->mask_hi)); fprintf(f, "SHUF model, scanning for: %s (%zu chars)\n", describeClass(cr, 20, CC_OUT_TEXT).c_str(), cr.count()); fprintf(f, "\n"); @@ -123,11 +123,11 @@ void nfaExecLbrTruf_dump(const NFA *nfa, const string &base) { StdioFile f(base + ".txt", "w"); - const lbr_truf *lt = (const lbr_truf *)getImplNfa(nfa); + const lbr_truf *lt = reinterpret_cast(getImplNfa(nfa)); lbrDumpCommon(<->common, f); - CharReach cr = truffle2cr((const u8 *)<->mask1, - (const u8 *)<->mask2); + CharReach cr = truffle2cr((const u8 *)(<->mask1), + (const u8 *)(<->mask2)); fprintf(f, "TRUFFLE model, scanning for: %s (%zu chars)\n", describeClass(cr, 20, CC_OUT_TEXT).c_str(), cr.count()); fprintf(f, "\n"); diff --git a/src/nfa/limex_dump.cpp b/src/nfa/limex_dump.cpp index d9e49213..6ef68e0e 100644 --- a/src/nfa/limex_dump.cpp +++ b/src/nfa/limex_dump.cpp @@ -108,14 +108,14 @@ void dumpRepeats(const limex_type *limex, u32 model_size, FILE *f) { fprintf(f, "\n"); fprintf(f, "%u bounded repeats.\n", limex->repeatCount); - const char *base = (const char *)limex; - const u32 *repeatOffset = (const u32 *)(base + limex->repeatOffset); + const char *base = reinterpret_cast(limex); + const u32 *repeatOffset = reinterpret_cast(base + limex->repeatOffset); for (u32 i = 0; i < limex->repeatCount; i++) { const NFARepeatInfo *info = - (const NFARepeatInfo *)(base + repeatOffset[i]); + reinterpret_cast(base + repeatOffset[i]); const RepeatInfo *repeat = - (const RepeatInfo *)((const char *)info + sizeof(*info)); + reinterpret_cast(reinterpret_cast(info) + sizeof(*info)); fprintf(f, " repeat %u: %s {%u,%u} packedCtrlSize=%u, " "stateSize=%u\n", i, repeatTypeName(repeat->type), repeat->repeatMin, @@ -123,7 +123,7 @@ void dumpRepeats(const limex_type *limex, u32 model_size, FILE *f) { fprintf(f, " nfa state: stream offset %u\n", info->stateOffset); fprintf(f, " "); - const u8 *tug_mask = (const u8 *)info + info->tugMaskOffset; + const u8 *tug_mask = reinterpret_cast(info) + info->tugMaskOffset; dumpMask(f, "tugs", tug_mask, model_size); } @@ -157,7 +157,7 @@ void dumpLimexReachMap(const u8 *reachMap, FILE *f) { template static const NFA *limex_to_nfa(const limex_type *limex) { - return (const NFA *)((const char *)limex - sizeof(NFA)); + return reinterpret_cast(reinterpret_cast(limex) - sizeof(NFA)); } template @@ -172,8 +172,8 @@ void dumpAccel(const limex_type *limex, FILE *f) { u32 tableOffset = limex->accelTableOffset; u32 auxOffset = limex->accelAuxOffset; - const u8 *accelTable = (const u8 *)((const char *)limex + tableOffset); - const AccelAux *aux = (const AccelAux *)((const char *)limex + auxOffset); + const u8 *accelTable = reinterpret_cast(reinterpret_cast(limex) + tableOffset); + const AccelAux *aux = reinterpret_cast(reinterpret_cast(limex) + auxOffset); for (u32 i = 0; i < limex->accelCount; i++) { fprintf(f, " accel %u (aux entry %u): ", i, accelTable[i]); @@ -191,7 +191,7 @@ void dumpAcceptList(const char *limex_base, const struct NFAAccept *accepts, continue; } fprintf(f, " idx %u fires report list %u:", i, a.reports); - const ReportID *report = (const ReportID *)(limex_base + a.reports); + const ReportID *report = reinterpret_cast(limex_base + a.reports); for (; *report != MO_INVALID_IDX; report++) { fprintf(f, " %u", *report); } @@ -202,18 +202,18 @@ void dumpAcceptList(const char *limex_base, const struct NFAAccept *accepts, template static void dumpAccepts(const limex_type *limex, FILE *f) { - const char *limex_base = (const char *)limex; + const char *limex_base = reinterpret_cast(limex); const u32 acceptCount = limex->acceptCount; const u32 acceptEodCount = limex->acceptEodCount; fprintf(f, "\n%u accepts.\n", acceptCount); const auto *accepts = - (const struct NFAAccept *)(limex_base + limex->acceptOffset); + reinterpret_cast(limex_base + limex->acceptOffset); dumpAcceptList(limex_base, accepts, acceptCount, f); fprintf(f, "\n%u accepts at EOD.\n", acceptEodCount); const auto *accepts_eod = - (const struct NFAAccept *)(limex_base + limex->acceptEodOffset); + reinterpret_cast(limex_base + limex->acceptEodOffset); dumpAcceptList(limex_base, accepts_eod, acceptEodCount, f); fprintf(f, "\n"); } @@ -224,7 +224,7 @@ void dumpSquash(const limex_type *limex, FILE *f) { u32 size = limex_traits::size; // Dump squash masks, if there are any. - const u8 *squashMask = (const u8 *)limex + limex->squashOffset; + const u8 *squashMask = reinterpret_cast(limex) + limex->squashOffset; for (u32 i = 0; i < limex->squashCount; i++) { std::ostringstream name; name << "squash_" << i; @@ -238,7 +238,7 @@ static const typename limex_traits::exception_type * getExceptionTable(const limex_type *limex) { return (const typename limex_traits::exception_type *) - ((const char *)limex + limex->exceptionOffset); + (reinterpret_cast(limex) + limex->exceptionOffset); } template @@ -248,7 +248,7 @@ void dumpLimexExceptions(const limex_type *limex, FILE *f) { getExceptionTable(limex); const u32 size = limex_traits::size; - const char *limex_base = (const char *)limex; + const char *limex_base = reinterpret_cast(limex); fprintf(f, "\n"); for (u32 i = 0; i < limex->exceptionCount; i++) { @@ -259,13 +259,13 @@ void dumpLimexExceptions(const limex_type *limex, FILE *f) { case LIMEX_TRIGGER_POS: fprintf(f, " trigger: POS\n"); break; default: break; } - dumpMask(f, "succ", (const u8 *)&e[i].successors, size); - dumpMask(f, "squash", (const u8 *)&e[i].squash, size); + dumpMask(f, "succ", reinterpret_cast(&e[i].successors), size); + dumpMask(f, "squash", reinterpret_cast(&e[i].squash), size); fprintf(f, "reports: "); if (e[i].reports == MO_INVALID_IDX) { fprintf(f, " \n"); } else { - const ReportID *r = (const ReportID *)(limex_base + e[i].reports); + const ReportID *r = reinterpret_cast(limex_base + e[i].reports); while (*r != MO_INVALID_IDX) { fprintf(f, " %u", *r++); } @@ -282,7 +282,7 @@ void dumpLimexShifts(const limex_type *limex, FILE *f) { fprintf(f, "Shift Masks:\n"); for(u32 i = 0; i < limex->shiftCount; i++) { fprintf(f, "\t Shift %u(%hhu)\t\tMask: %s\n", i, limex->shiftAmount[i], - dumpMask((const u8 *)&limex->shift[i], size).c_str()); + dumpMask(reinterpret_cast(&limex->shift[i]), size).c_str()); } } template @@ -304,20 +304,20 @@ void dumpLimexText(const limex_type *limex, FILE *f) { } fprintf(f, "\n\n"); - dumpMask(f, "init", (const u8 *)&limex->init, size); - dumpMask(f, "init_dot_star", (const u8 *)&limex->initDS, size); - dumpMask(f, "accept", (const u8 *)&limex->accept, size); - dumpMask(f, "accept_at_eod", (const u8 *)&limex->acceptAtEOD, size); - dumpMask(f, "accel", (const u8 *)&limex->accel, size); - dumpMask(f, "accel_and_friends", (const u8 *)&limex->accel_and_friends, + dumpMask(f, "init", reinterpret_cast(&limex->init), size); + dumpMask(f, "init_dot_star", reinterpret_cast(&limex->initDS), size); + dumpMask(f, "accept", reinterpret_cast(&limex->accept), size); + dumpMask(f, "accept_at_eod", reinterpret_cast(&limex->acceptAtEOD), size); + dumpMask(f, "accel", reinterpret_cast(&limex->accel), size); + dumpMask(f, "accel_and_friends", reinterpret_cast(&limex->accel_and_friends), size); - dumpMask(f, "compress_mask", (const u8 *)&limex->compressMask, size); - dumpMask(f, "emask", (const u8 *)&limex->exceptionMask, size); - dumpMask(f, "zombie", (const u8 *)&limex->zombieMask, size); + dumpMask(f, "compress_mask", reinterpret_cast(&limex->compressMask), size); + dumpMask(f, "emask", reinterpret_cast(&limex->exceptionMask), size); + dumpMask(f, "zombie", reinterpret_cast(&limex->zombieMask), size); // Dump top masks, if there are any. u32 topCount = limex->topCount; - const u8 *topMask = (const u8 *)limex + limex->topOffset; + const u8 *topMask = reinterpret_cast(limex) + limex->topOffset; for (u32 i = 0; i < topCount; i++) { std::ostringstream name; name << "top_" << i; @@ -331,7 +331,7 @@ void dumpLimexText(const limex_type *limex, FILE *f) { dumpSquash(limex, f); dumpLimexReachMap(limex->reachMap, f); - dumpLimexReachMasks(size, (const u8 *)limex + sizeof(*limex) /* reach*/, + dumpLimexReachMasks(size, reinterpret_cast(limex) + sizeof(*limex) /* reach*/, limex->reachSize, f); dumpAccepts(limex, f); @@ -378,7 +378,7 @@ struct limex_labeller : public nfa_labeller { void label_state(FILE *f, u32 state) const override { const typename limex_traits::exception_type *exceptions = getExceptionTable(limex); - if (!testbit((const u8 *)&limex->exceptionMask, + if (!testbit(reinterpret_cast(&limex->exceptionMask), limex_traits::size, state)) { return; } @@ -404,11 +404,11 @@ static void dumpVertexDotInfo(const limex_type *limex, u32 state_count, FILE *f, const nfa_labeller &labeller) { u32 size = sizeof(limex->init) * 8; - const u8 *reach = (const u8 *)limex + sizeof(*limex); + const u8 *reach = reinterpret_cast(limex) + sizeof(*limex); vector perStateReach; setupReach(limex->reachMap, reach, size, state_count, &perStateReach); - const u8 *topMask = (const u8 *)limex + limex->topOffset; + const u8 *topMask = reinterpret_cast(limex) + limex->topOffset; for (u32 state = 0; state < state_count; state++) { fprintf(f, "%u [ width = 1, fixedsize = true, fontsize = 12, " @@ -419,15 +419,15 @@ void dumpVertexDotInfo(const limex_type *limex, u32 state_count, FILE *f, // bung in another couple lines to push char class (the widest thing) up a bit fprintf(f, "\\n\\n\" ];\n"); - if (testbit((const u8 *)&limex->acceptAtEOD, size, state)) { + if (testbit(reinterpret_cast(&limex->acceptAtEOD), size, state)) { fprintf(f, "%u [ shape = box ];\n", state); - } else if (testbit((const u8 *)&limex->accept, size, state)) { + } else if (testbit(reinterpret_cast(&limex->accept), size, state)) { fprintf(f, "%u [ shape = doublecircle ];\n", state); } - if (testbit((const u8 *)&limex->accel, size, state)) { + if (testbit(reinterpret_cast(&limex->accel), size, state)) { fprintf(f, "%u [ color = red style = diagonals];\n", state); } - if (testbit((const u8 *)&limex->init, size, state)) { + if (testbit(reinterpret_cast(&limex->init), size, state)) { fprintf(f, "START -> %u [ color = grey ];\n", state); } @@ -447,7 +447,7 @@ template static void dumpExDotInfo(const limex_type *limex, u32 state, FILE *f) { u32 size = limex_traits::size; - if (!testbit((const u8 *)&limex->exceptionMask, size, state)) { + if (!testbit(reinterpret_cast(&limex->exceptionMask), size, state)) { return; /* not exceptional */ } @@ -461,10 +461,10 @@ void dumpExDotInfo(const limex_type *limex, u32 state, FILE *f) { u32 state_count = limex_to_nfa(limex)->nPositions; for (u32 j = 0; j < state_count; j++) { - if (testbit((const u8 *)&e->successors, size, j)) { + if (testbit(reinterpret_cast(&e->successors), size, j)) { fprintf(f, "%u -> %u [color = blue];\n", state, j); } - if (!testbit((const u8 *)&e->squash, size, j)) { + if (!testbit(reinterpret_cast(&e->squash), size, j)) { fprintf(f, "%u -> %u [color = grey style = dashed];\n", state, j); } } @@ -480,7 +480,7 @@ static void dumpLimDotInfo(const limex_type *limex, u32 state, FILE *f) { for (u32 j = 0; j < limex->shiftCount; j++) { const u32 shift_amount = limex->shiftAmount[j]; - if (testbit((const u8 *)&limex->shift[j], + if (testbit(reinterpret_cast(&limex->shift[j]), limex_traits::size, state)) { fprintf(f, "%u -> %u;\n", state, state + shift_amount); } @@ -502,7 +502,7 @@ void dumpLimexDot(const NFA *nfa, const limex_type *limex, FILE *f) { #define LIMEX_DUMP_FN(size) \ void nfaExecLimEx##size##_dump(const NFA *nfa, const string &base) { \ - auto limex = (const LimExNFA##size *)getImplNfa(nfa); \ + auto limex = reinterpret_cast(getImplNfa(nfa)); \ dumpLimexText(limex, StdioFile(base + ".txt", "w")); \ dumpLimexDot(nfa, limex, StdioFile(base + ".dot", "w")); \ } diff --git a/src/nfa/mcclellandump.cpp b/src/nfa/mcclellandump.cpp index 92090bc5..823010f0 100644 --- a/src/nfa/mcclellandump.cpp +++ b/src/nfa/mcclellandump.cpp @@ -61,32 +61,32 @@ namespace ue2 { const mstate_aux *getAux(const NFA *n, dstate_id_t i) { assert(n && isDfaType(n->type)); - const mcclellan *m = (const mcclellan *)getImplNfa(n); + const mcclellan *m = reinterpret_cast(getImplNfa(n)); const mstate_aux *aux_base - = (const mstate_aux *)((const char *)n + m->aux_offset); + = reinterpret_cast(reinterpret_cast(n) + m->aux_offset); const mstate_aux *aux = aux_base + i; - assert((const char *)aux < (const char *)n + m->length); + assert(reinterpret_cast(aux) < reinterpret_cast(n) + m->length); return aux; } static void mcclellanGetTransitions(const NFA *n, u16 s, u16 *t) { assert(isMcClellanType(n->type)); - const mcclellan *m = (const mcclellan *)getImplNfa(n); + const mcclellan *m = reinterpret_cast(getImplNfa(n)); const mstate_aux *aux = getAux(n, s); const u32 as = m->alphaShift; if (n->type == MCCLELLAN_NFA_8) { - const u8 *succ_table = (const u8 *)((const char *)m + const u8 *succ_table = reinterpret_cast(reinterpret_cast(m) + sizeof(mcclellan)); for (u16 c = 0; c < N_CHARS; c++) { t[c] = succ_table[((u32)s << as) + m->remap[c]]; } } else { u16 base_s = s; - const char *winfo_base = (const char *)n + m->sherman_offset; + const char *winfo_base = reinterpret_cast(n) + m->sherman_offset; const char *state_base = winfo_base + SHERMAN_FIXED_SIZE * (s - m->sherman_limit); @@ -94,10 +94,10 @@ void mcclellanGetTransitions(const NFA *n, u16 s, u16 *t) { base_s = unaligned_load_u16(state_base + SHERMAN_DADDY_OFFSET); } - const u16 *succ_table = (const u16 *)((const char *)m + const u16 *succ_table = reinterpret_cast(reinterpret_cast(m) + sizeof(mcclellan)); for (u16 c = 0; c < N_CHARS; c++) { - const u8 *addr = (const u8*)(succ_table + (((u32)base_s << as) + const u8 *addr = reinterpret_cast(succ_table + (((u32)base_s << as) + m->remap[c])); t[c] = unaligned_load_u16(addr); t[c] &= STATE_MASK; @@ -106,15 +106,15 @@ void mcclellanGetTransitions(const NFA *n, u16 s, u16 *t) { if (s >= m->sherman_limit) { UNUSED char type = *(state_base + SHERMAN_TYPE_OFFSET); assert(type == SHERMAN_STATE); - u8 len = *(const u8 *)(SHERMAN_LEN_OFFSET + state_base); + u8 len = *(reinterpret_cast(SHERMAN_LEN_OFFSET + state_base)); const char *chars = state_base + SHERMAN_CHARS_OFFSET; - const u16 *states = (const u16 *)(state_base + const u16 *states = reinterpret_cast(state_base + SHERMAN_STATES_OFFSET(len)); for (u8 i = 0; i < len; i++) { for (u16 c = 0; c < N_CHARS; c++) { if (m->remap[c] == chars[i]) { - t[c] = unaligned_load_u16((const u8*)&states[i]) & STATE_MASK; + t[c] = unaligned_load_u16(reinterpret_cast(&states[i])) & STATE_MASK; } } } @@ -218,8 +218,8 @@ void describeNode(const NFA *n, const mcclellan *m, u16 i, FILE *f) { "label = \"%u%s\" ]; \n", i, i, isSherman ? "w":""); if (aux->accel_offset) { - dumpAccelDot(f, i, (const union AccelAux *) - ((const char *)m + aux->accel_offset)); + dumpAccelDot(f, i, reinterpret_cast + (reinterpret_cast(m) + aux->accel_offset)); } if (aux->accept_eod) { @@ -244,14 +244,14 @@ void describeNode(const NFA *n, const mcclellan *m, u16 i, FILE *f) { } if (isSherman) { - const char *winfo_base = (const char *)n + m->sherman_offset; + const char *winfo_base = reinterpret_cast(n) + m->sherman_offset; const char *state_base = winfo_base + SHERMAN_FIXED_SIZE * (i - m->sherman_limit); - assert(state_base < (const char *)m + m->length - sizeof(NFA)); - UNUSED u8 type = *(const u8 *)(state_base + SHERMAN_TYPE_OFFSET); + assert(state_base < reinterpret_cast(m) + m->length - sizeof(NFA)); + UNUSED u8 type = *(reinterpret_cast(state_base + SHERMAN_TYPE_OFFSET)); assert(type == SHERMAN_STATE); fprintf(f, "%u [ fillcolor = lightblue style=filled ];\n", i); - u16 daddy = *(const u16 *)(state_base + SHERMAN_DADDY_OFFSET); + u16 daddy = *(reinterpret_cast(state_base + SHERMAN_DADDY_OFFSET)); if (daddy) { fprintf(f, "%u -> %u [ color=royalblue style=dashed weight=0.1]\n", i, daddy); @@ -271,7 +271,7 @@ void dumpDotPreambleDfa(FILE *f) { static void nfaExecMcClellan16_dumpDot(const NFA *nfa, FILE *f) { assert(nfa->type == MCCLELLAN_NFA_16); - const mcclellan *m = (const mcclellan *)getImplNfa(nfa); + const mcclellan *m = reinterpret_cast(getImplNfa(nfa)); dumpDotPreambleDfa(f); @@ -292,7 +292,7 @@ void nfaExecMcClellan16_dumpDot(const NFA *nfa, FILE *f) { static void nfaExecMcClellan8_dumpDot(const NFA *nfa, FILE *f) { assert(nfa->type == MCCLELLAN_NFA_8); - const mcclellan *m = (const mcclellan *)getImplNfa(nfa); + const mcclellan *m = reinterpret_cast(getImplNfa(nfa)); dumpDotPreambleDfa(f); @@ -321,7 +321,7 @@ void dumpAccelMasks(FILE *f, const mcclellan *m, const mstate_aux *aux) { continue; } - const AccelAux *accel = (const AccelAux *)((const char *)m + const AccelAux *accel = reinterpret_cast(reinterpret_cast(m) + aux[i].accel_offset); fprintf(f, "%05hu ", i); dumpAccelInfo(f, *accel); @@ -366,7 +366,7 @@ void dumpTransitions(FILE *f, const NFA *nfa, const mcclellan *m, for (u16 i = 0; i < sherman_ceil; i++) { fprintf(f, "%05hu", i); if (aux[i].accel_offset) { - dumpAccelText(f, (const union AccelAux *)((const char *)m + + dumpAccelText(f, reinterpret_cast(reinterpret_cast(m) + aux[i].accel_offset)); } @@ -404,9 +404,9 @@ void dumpTransitions(FILE *f, const NFA *nfa, const mcclellan *m, static void nfaExecMcClellan16_dumpText(const NFA *nfa, FILE *f) { assert(nfa->type == MCCLELLAN_NFA_16); - const mcclellan *m = (const mcclellan *)getImplNfa(nfa); + const mcclellan *m = reinterpret_cast(getImplNfa(nfa)); const mstate_aux *aux = - (const mstate_aux *)((const char *)nfa + m->aux_offset); + reinterpret_cast(reinterpret_cast(nfa) + m->aux_offset); fprintf(f, "mcclellan 16\n"); dumpCommonHeader(f, m); @@ -425,9 +425,9 @@ void nfaExecMcClellan16_dumpText(const NFA *nfa, FILE *f) { static void nfaExecMcClellan8_dumpText(const NFA *nfa, FILE *f) { assert(nfa->type == MCCLELLAN_NFA_8); - const mcclellan *m = (const mcclellan *)getImplNfa(nfa); + const mcclellan *m = reinterpret_cast(getImplNfa(nfa)); const mstate_aux *aux = - (const mstate_aux *)((const char *)nfa + m->aux_offset); + reinterpret_cast(reinterpret_cast(nfa) + m->aux_offset); fprintf(f, "mcclellan 8\n"); dumpCommonHeader(f, m); diff --git a/src/nfa/mcsheng_dump.cpp b/src/nfa/mcsheng_dump.cpp index 7cef82f4..bec4228c 100644 --- a/src/nfa/mcsheng_dump.cpp +++ b/src/nfa/mcsheng_dump.cpp @@ -58,18 +58,18 @@ namespace ue2 { static const mstate_aux *getAux(const NFA *n, dstate_id_t i) { - auto *m = (const mcsheng *)getImplNfa(n); - auto *aux_base = (const mstate_aux *)((const char *)n + m->aux_offset); + auto *m = reinterpret_cast(getImplNfa(n)); + auto *aux_base = reinterpret_cast(reinterpret_cast(n) + m->aux_offset); const mstate_aux *aux = aux_base + i; - assert((const char *)aux < (const char *)n + m->length); + assert(reinterpret_cast(aux) < reinterpret_cast(n) + m->length); return aux; } static void next_states(const NFA *n, u16 s, u16 *t) { - const mcsheng *m = (const mcsheng *)getImplNfa(n); + const mcsheng *m = reinterpret_cast(getImplNfa(n)); const mstate_aux *aux = getAux(n, s); const u32 as = m->alphaShift; assert(s != DEAD_STATE); @@ -77,7 +77,7 @@ void next_states(const NFA *n, u16 s, u16 *t) { if (s < m->sheng_end) { for (u16 c = 0; c < N_CHARS; c++) { u8 sheng_s = s - 1; - auto trans_for_c = (const char *)&m->sheng_masks[c]; + auto trans_for_c = reinterpret_cast(&m->sheng_masks[c]); assert(sheng_s < sizeof(m128)); u8 raw_succ = trans_for_c[sheng_s]; if (raw_succ == m->sheng_end - 1) { @@ -89,14 +89,14 @@ void next_states(const NFA *n, u16 s, u16 *t) { } } } else if (n->type == MCSHENG_NFA_8) { - const u8 *succ_table = (const u8 *)((const char *)m + sizeof(mcsheng)); + const u8 *succ_table = reinterpret_cast(reinterpret_cast(m) + sizeof(mcsheng)); for (u16 c = 0; c < N_CHARS; c++) { u32 normal_id = s - m->sheng_end; t[c] = succ_table[(normal_id << as) + m->remap[c]]; } } else { u16 base_s = s; - const char *winfo_base = (const char *)n + m->sherman_offset; + const char *winfo_base = reinterpret_cast(n) + m->sherman_offset; const char *state_base = winfo_base + SHERMAN_FIXED_SIZE * (s - m->sherman_limit); @@ -105,7 +105,7 @@ void next_states(const NFA *n, u16 s, u16 *t) { assert(base_s >= m->sheng_end); } - const u16 *succ_table = (const u16 *)((const char *)m + const u16 *succ_table = reinterpret_cast(reinterpret_cast(m) + sizeof(mcsheng)); for (u16 c = 0; c < N_CHARS; c++) { u32 normal_id = base_s - m->sheng_end; @@ -115,15 +115,15 @@ void next_states(const NFA *n, u16 s, u16 *t) { if (s >= m->sherman_limit) { UNUSED char type = *(state_base + SHERMAN_TYPE_OFFSET); assert(type == SHERMAN_STATE); - u8 len = *(const u8 *)(SHERMAN_LEN_OFFSET + state_base); + u8 len = *(reinterpret_cast(SHERMAN_LEN_OFFSET + state_base)); const char *chars = state_base + SHERMAN_CHARS_OFFSET; - const u16 *states = (const u16 *)(state_base + const u16 *states = reinterpret_cast(state_base + SHERMAN_STATES_OFFSET(len)); for (u8 i = 0; i < len; i++) { for (u16 c = 0; c < N_CHARS; c++) { if (m->remap[c] == chars[i]) { - t[c] = unaligned_load_u16((const u8*)&states[i]); + t[c] = unaligned_load_u16(reinterpret_cast(&states[i])); } } } @@ -176,18 +176,18 @@ void describeEdge(FILE *f, const mcsheng *m, const u16 *t, u16 i) { static const mstate_aux *getAux64(const NFA *n, dstate_id_t i) { - auto *m = (const mcsheng64 *)getImplNfa(n); - auto *aux_base = (const mstate_aux *)((const char *)n + m->aux_offset); + auto *m = reinterpret_cast(getImplNfa(n)); + auto *aux_base = reinterpret_cast(reinterpret_cast(n) + m->aux_offset); const mstate_aux *aux = aux_base + i; - assert((const char *)aux < (const char *)n + m->length); + assert(reinterpret_cast(aux) < reinterpret_cast(n) + m->length); return aux; } static void next_states64(const NFA *n, u16 s, u16 *t) { - const mcsheng64 *m = (const mcsheng64 *)getImplNfa(n); + const mcsheng64 *m = reinterpret_cast(getImplNfa(n)); const mstate_aux *aux = getAux64(n, s); const u32 as = m->alphaShift; assert(s != DEAD_STATE); @@ -195,7 +195,7 @@ void next_states64(const NFA *n, u16 s, u16 *t) { if (s < m->sheng_end) { for (u16 c = 0; c < N_CHARS; c++) { u8 sheng_s = s - 1; - auto trans_for_c = (const char *)&m->sheng_succ_masks[c]; + auto trans_for_c = reinterpret_cast(&m->sheng_succ_masks[c]); assert(sheng_s < sizeof(m512)); u8 raw_succ = trans_for_c[sheng_s]; if (raw_succ == m->sheng_end - 1) { @@ -207,14 +207,14 @@ void next_states64(const NFA *n, u16 s, u16 *t) { } } } else if (n->type == MCSHENG_64_NFA_8) { - const u8 *succ_table = (const u8 *)((const char *)m + sizeof(mcsheng64)); + const u8 *succ_table = reinterpret_cast(reinterpret_cast(m) + sizeof(mcsheng64)); for (u16 c = 0; c < N_CHARS; c++) { u32 normal_id = s - m->sheng_end; t[c] = succ_table[(normal_id << as) + m->remap[c]]; } } else { u16 base_s = s; - const char *winfo_base = (const char *)n + m->sherman_offset; + const char *winfo_base = reinterpret_cast(n) + m->sherman_offset; const char *state_base = winfo_base + SHERMAN_FIXED_SIZE * (s - m->sherman_limit); @@ -223,7 +223,7 @@ void next_states64(const NFA *n, u16 s, u16 *t) { assert(base_s >= m->sheng_end); } - const u16 *succ_table = (const u16 *)((const char *)m + const u16 *succ_table = reinterpret_cast(reinterpret_cast(m) + sizeof(mcsheng64)); for (u16 c = 0; c < N_CHARS; c++) { u32 normal_id = base_s - m->sheng_end; @@ -233,15 +233,15 @@ void next_states64(const NFA *n, u16 s, u16 *t) { if (s >= m->sherman_limit) { UNUSED char type = *(state_base + SHERMAN_TYPE_OFFSET); assert(type == SHERMAN_STATE); - u8 len = *(const u8 *)(SHERMAN_LEN_OFFSET + state_base); + u8 len = *(reinterpret_cast(SHERMAN_LEN_OFFSET + state_base)); const char *chars = state_base + SHERMAN_CHARS_OFFSET; - const u16 *states = (const u16 *)(state_base + const u16 *states = reinterpret_cast(state_base + SHERMAN_STATES_OFFSET(len)); for (u8 i = 0; i < len; i++) { for (u16 c = 0; c < N_CHARS; c++) { if (m->remap[c] == chars[i]) { - t[c] = unaligned_load_u16((const u8*)&states[i]); + t[c] = unaligned_load_u16(reinterpret_cast(&states[i])); } } } @@ -324,8 +324,8 @@ void describeNode(const NFA *n, const mcsheng *m, u16 i, FILE *f) { "label = \"%u%s\" ]; \n", i, i, isSherman ? "w":""); if (aux->accel_offset) { - dumpAccelDot(f, i, (const union AccelAux *) - ((const char *)m + aux->accel_offset)); + dumpAccelDot(f, i, reinterpret_cast + (reinterpret_cast(m) + aux->accel_offset)); } if (i && i < m->sheng_end) { @@ -354,14 +354,14 @@ void describeNode(const NFA *n, const mcsheng *m, u16 i, FILE *f) { } if (isSherman) { - const char *winfo_base = (const char *)n + m->sherman_offset; + const char *winfo_base = reinterpret_cast(n) + m->sherman_offset; const char *state_base = winfo_base + SHERMAN_FIXED_SIZE * (i - m->sherman_limit); - assert(state_base < (const char *)m + m->length - sizeof(NFA)); - UNUSED u8 type = *(const u8 *)(state_base + SHERMAN_TYPE_OFFSET); + assert(state_base < reinterpret_cast(m) + m->length - sizeof(NFA)); + UNUSED u8 type = *(reinterpret_cast(state_base + SHERMAN_TYPE_OFFSET)); assert(type == SHERMAN_STATE); fprintf(f, "%u [ fillcolor = lightblue style=filled ];\n", i); - u16 daddy = *(const u16 *)(state_base + SHERMAN_DADDY_OFFSET); + u16 daddy = *(reinterpret_cast(state_base + SHERMAN_DADDY_OFFSET)); if (daddy) { fprintf(f, "%u -> %u [ color=royalblue style=dashed weight=0.1]\n", i, daddy); @@ -384,8 +384,8 @@ void describeNode64(const NFA *n, const mcsheng64 *m, u16 i, FILE *f) { "label = \"%u%s\" ]; \n", i, i, isSherman ? "w":""); if (aux->accel_offset) { - dumpAccelDot(f, i, (const union AccelAux *) - ((const char *)m + aux->accel_offset)); + dumpAccelDot(f, i, reinterpret_cast + (reinterpret_cast(m) + aux->accel_offset)); } if (i && i < m->sheng_end) { @@ -414,14 +414,14 @@ void describeNode64(const NFA *n, const mcsheng64 *m, u16 i, FILE *f) { } if (isSherman) { - const char *winfo_base = (const char *)n + m->sherman_offset; + const char *winfo_base = reinterpret_cast(n) + m->sherman_offset; const char *state_base = winfo_base + SHERMAN_FIXED_SIZE * (i - m->sherman_limit); - assert(state_base < (const char *)m + m->length - sizeof(NFA)); - UNUSED u8 type = *(const u8 *)(state_base + SHERMAN_TYPE_OFFSET); + assert(state_base < reinterpret_cast(m) + m->length - sizeof(NFA)); + UNUSED u8 type = *(reinterpret_cast(state_base + SHERMAN_TYPE_OFFSET)); assert(type == SHERMAN_STATE); fprintf(f, "%u [ fillcolor = lightblue style=filled ];\n", i); - u16 daddy = *(const u16 *)(state_base + SHERMAN_DADDY_OFFSET); + u16 daddy = *(reinterpret_cast(state_base + SHERMAN_DADDY_OFFSET)); if (daddy) { fprintf(f, "%u -> %u [ color=royalblue style=dashed weight=0.1]\n", i, daddy); @@ -447,7 +447,7 @@ void dumpDotPreambleDfa(FILE *f) { static void dump_dot_16(const NFA *nfa, FILE *f) { - auto *m = (const mcsheng *)getImplNfa(nfa); + auto *m = reinterpret_cast(getImplNfa(nfa)); dumpDotPreambleDfa(f); @@ -466,7 +466,7 @@ void dump_dot_16(const NFA *nfa, FILE *f) { static void dump_dot_8(const NFA *nfa, FILE *f) { - auto m = (const mcsheng *)getImplNfa(nfa); + auto m = reinterpret_cast(getImplNfa(nfa)); dumpDotPreambleDfa(f); @@ -494,7 +494,7 @@ void dumpAccelMasks(FILE *f, const mcsheng *m, const mstate_aux *aux) { continue; } - auto accel = (const AccelAux *)((const char *)m + aux[i].accel_offset); + auto accel = reinterpret_cast(reinterpret_cast(m) + aux[i].accel_offset); fprintf(f, "%05hu ", i); dumpAccelInfo(f, *accel); } @@ -536,8 +536,8 @@ void dumpCommonHeader(FILE *f, const mcsheng *m) { static void dump_text_16(const NFA *nfa, FILE *f) { - auto *m = (const mcsheng *)getImplNfa(nfa); - auto *aux = (const mstate_aux *)((const char *)nfa + m->aux_offset); + auto *m = reinterpret_cast(getImplNfa(nfa)); + auto *aux = reinterpret_cast(reinterpret_cast(nfa) + m->aux_offset); fprintf(f, "mcsheng 16\n"); dumpCommonHeader(f, m); @@ -554,8 +554,8 @@ void dump_text_16(const NFA *nfa, FILE *f) { static void dump_text_8(const NFA *nfa, FILE *f) { - auto m = (const mcsheng *)getImplNfa(nfa); - auto aux = (const mstate_aux *)((const char *)nfa + m->aux_offset); + auto m = reinterpret_cast(getImplNfa(nfa)); + auto aux = reinterpret_cast(reinterpret_cast(nfa) + m->aux_offset); fprintf(f, "mcsheng 8\n"); dumpCommonHeader(f, m); @@ -572,7 +572,7 @@ void dump_text_8(const NFA *nfa, FILE *f) { static void dump64_dot_16(const NFA *nfa, FILE *f) { - auto *m = (const mcsheng64 *)getImplNfa(nfa); + auto *m = reinterpret_cast(getImplNfa(nfa)); dumpDotPreambleDfa(f); @@ -591,7 +591,7 @@ void dump64_dot_16(const NFA *nfa, FILE *f) { static void dump64_dot_8(const NFA *nfa, FILE *f) { - auto m = (const mcsheng64 *)getImplNfa(nfa); + auto m = reinterpret_cast(getImplNfa(nfa)); dumpDotPreambleDfa(f); @@ -619,7 +619,7 @@ void dumpAccelMasks64(FILE *f, const mcsheng64 *m, const mstate_aux *aux) { continue; } - auto accel = (const AccelAux *)((const char *)m + aux[i].accel_offset); + auto accel = reinterpret_cast(reinterpret_cast(m) + aux[i].accel_offset); fprintf(f, "%05hu ", i); dumpAccelInfo(f, *accel); } @@ -661,8 +661,8 @@ void dumpCommonHeader64(FILE *f, const mcsheng64 *m) { static void dump64_text_8(const NFA *nfa, FILE *f) { - auto m = (const mcsheng64 *)getImplNfa(nfa); - auto aux = (const mstate_aux *)((const char *)nfa + m->aux_offset); + auto m = reinterpret_cast(getImplNfa(nfa)); + auto aux = reinterpret_cast(reinterpret_cast(nfa) + m->aux_offset); fprintf(f, "mcsheng 64-8\n"); dumpCommonHeader64(f, m); @@ -679,8 +679,8 @@ void dump64_text_8(const NFA *nfa, FILE *f) { static void dump64_text_16(const NFA *nfa, FILE *f) { - auto *m = (const mcsheng64 *)getImplNfa(nfa); - auto *aux = (const mstate_aux *)((const char *)nfa + m->aux_offset); + auto *m = reinterpret_cast(getImplNfa(nfa)); + auto *aux = reinterpret_cast(reinterpret_cast(nfa) + m->aux_offset); fprintf(f, "mcsheng 64-16\n"); dumpCommonHeader64(f, m); diff --git a/src/nfa/mpv_dump.cpp b/src/nfa/mpv_dump.cpp index 4979395d..12616fbb 100644 --- a/src/nfa/mpv_dump.cpp +++ b/src/nfa/mpv_dump.cpp @@ -80,9 +80,9 @@ void dumpKilo(FILE *f, const mpv *m, const mpv_kilopuff *k) { case MPV_SHUFTI: fprintf(f, "shufti\n"); fprintf(f, "lo %s\n", - dumpMask((const u8 *)&k->u.shuf.mask_lo, 128).c_str()); + dumpMask(reinterpret_cast(&k->u.shuf.mask_lo), 128).c_str()); fprintf(f, "hi %s\n", - dumpMask((const u8 *)&k->u.shuf.mask_hi, 128).c_str()); + dumpMask(reinterpret_cast(&k->u.shuf.mask_hi), 128).c_str()); break; case MPV_TRUFFLE: fprintf(f, "truffle\n"); @@ -130,7 +130,7 @@ void dumpCounter(FILE *f, const mpv_counter_info *c) { } void nfaExecMpv_dump(const NFA *nfa, const string &base) { - const mpv *m = (const mpv *)getImplNfa(nfa); + const mpv *m = reinterpret_cast(getImplNfa(nfa)); StdioFile f(base + ".txt", "w"); @@ -141,7 +141,7 @@ void nfaExecMpv_dump(const NFA *nfa, const string &base) { fprintf(f, "initial kilopuffs %u - %u\n", m->top_kilo_begin, m->top_kilo_end - 1); - const mpv_kilopuff *k = (const mpv_kilopuff *)(m + 1); + const mpv_kilopuff *k = reinterpret_cast(m + 1); for (u32 i = 0; i < m->kilo_count; i++) { fprintf(f, "\nKILOPUFF %u\n", i); dumpKilo(f, m, k++); diff --git a/src/nfa/mpv_internal.h b/src/nfa/mpv_internal.h index b6b92504..0a39a6f3 100644 --- a/src/nfa/mpv_internal.h +++ b/src/nfa/mpv_internal.h @@ -188,11 +188,13 @@ struct mpv_pq_item { static really_inline const struct mpv_puffette *get_puff_array(const struct mpv *m, const struct mpv_kilopuff *kp) { + // cppcheck-suppress cstyleCast return (const struct mpv_puffette *)((const char *)m + kp->puffette_offset); } static really_inline const struct mpv_counter_info *get_counter_info(const struct mpv *m) { + // cppcheck-suppress cstyleCast return (const struct mpv_counter_info *)((const char *)(m + 1) + m->kilo_count * sizeof(struct mpv_kilopuff)); } diff --git a/src/nfa/nfa_build_util.cpp b/src/nfa/nfa_build_util.cpp index 7139ce99..86eb1510 100644 --- a/src/nfa/nfa_build_util.cpp +++ b/src/nfa/nfa_build_util.cpp @@ -195,7 +195,7 @@ enum NFACategory {NFA_LIMEX, NFA_OTHER}; = "LimEx "#mlt_size; \ template<> struct getDescription { \ static string call(const void *p) { \ - return getDescriptionLimEx((const NFA *)p); \ + return getDescriptionLimEx(reinterpret_cast(p)); \ } \ };) diff --git a/src/nfa/shengdump.cpp b/src/nfa/shengdump.cpp index 6eb78407..c0c4a56f 100644 --- a/src/nfa/shengdump.cpp +++ b/src/nfa/shengdump.cpp @@ -53,13 +53,13 @@ static const sstate_aux *get_aux(const NFA *n, dstate_id_t i) { assert(n && isSheng16Type(n->type)); - const sheng *s = (const sheng *)getImplNfa(n); + const sheng *s = reinterpret_cast(getImplNfa(n)); const sstate_aux *aux_base = - (const sstate_aux *)((const char *)n + s->aux_offset); + reinterpret_cast(reinterpret_cast(n) + s->aux_offset); const sstate_aux *aux = aux_base + i; - assert((const char *)aux < (const char *)s + s->length); + assert(reinterpret_cast(aux) < reinterpret_cast(s) + s->length); return aux; } @@ -68,13 +68,13 @@ static const sstate_aux *get_aux32(const NFA *n, dstate_id_t i) { assert(n && isSheng32Type(n->type)); - const sheng32 *s = (const sheng32 *)getImplNfa(n); + const sheng32 *s = reinterpret_cast(getImplNfa(n)); const sstate_aux *aux_base = - (const sstate_aux *)((const char *)n + s->aux_offset); + reinterpret_cast(reinterpret_cast(n) + s->aux_offset); const sstate_aux *aux = aux_base + i; - assert((const char *)aux < (const char *)s + s->length); + assert(reinterpret_cast(aux) < reinterpret_cast(s) + s->length); return aux; } @@ -83,13 +83,13 @@ static const sstate_aux *get_aux64(const NFA *n, dstate_id_t i) { assert(n && isSheng64Type(n->type)); - const sheng64 *s = (const sheng64 *)getImplNfa(n); + const sheng64 *s = reinterpret_cast(getImplNfa(n)); const sstate_aux *aux_base = - (const sstate_aux *)((const char *)n + s->aux_offset); + reinterpret_cast(reinterpret_cast(n) + s->aux_offset); const sstate_aux *aux = aux_base + i; - assert((const char *)aux < (const char *)s + s->length); + assert(reinterpret_cast(aux) < reinterpret_cast(s) + s->length); return aux; } @@ -234,7 +234,7 @@ void dumpMasks64(FILE *f, const sheng64 *s) { static void nfaExecSheng_dumpText(const NFA *nfa, FILE *f) { assert(nfa->type == SHENG_NFA); - const sheng *s = (const sheng *)getImplNfa(nfa); + const sheng *s = reinterpret_cast(getImplNfa(nfa)); fprintf(f, "sheng DFA\n"); dumpHeader(f, s); @@ -245,19 +245,19 @@ void nfaExecSheng_dumpText(const NFA *nfa, FILE *f) { if (aux->accept) { fprintf(f, "report list:\n"); const report_list *rl = - (const report_list *)((const char *)nfa + aux->accept); + reinterpret_cast(reinterpret_cast(nfa) + aux->accept); dumpReports(f, rl); } if (aux->accept_eod) { fprintf(f, "EOD report list:\n"); const report_list *rl = - (const report_list *)((const char *)nfa + aux->accept_eod); + reinterpret_cast(reinterpret_cast(nfa) + aux->accept_eod); dumpReports(f, rl); } if (aux->accel) { fprintf(f, "accel:\n"); const AccelAux *accel = - (const AccelAux *)((const char *)nfa + aux->accel); + reinterpret_cast(reinterpret_cast(nfa) + aux->accel); dumpAccelInfo(f, *accel); } } @@ -272,7 +272,7 @@ void nfaExecSheng_dumpText(const NFA *nfa, FILE *f) { static void nfaExecSheng32_dumpText(const NFA *nfa, FILE *f) { assert(nfa->type == SHENG_NFA_32); - const sheng32 *s = (const sheng32 *)getImplNfa(nfa); + const sheng32 *s = reinterpret_cast(getImplNfa(nfa)); fprintf(f, "sheng32 DFA\n"); dumpHeader32(f, s); @@ -283,19 +283,19 @@ void nfaExecSheng32_dumpText(const NFA *nfa, FILE *f) { if (aux->accept) { fprintf(f, "report list:\n"); const report_list *rl = - (const report_list *)((const char *)nfa + aux->accept); + reinterpret_cast(reinterpret_cast(nfa) + aux->accept); dumpReports(f, rl); } if (aux->accept_eod) { fprintf(f, "EOD report list:\n"); const report_list *rl = - (const report_list *)((const char *)nfa + aux->accept_eod); + reinterpret_cast(reinterpret_cast(nfa) + aux->accept_eod); dumpReports(f, rl); } if (aux->accel) { fprintf(f, "accel:\n"); const AccelAux *accel = - (const AccelAux *)((const char *)nfa + aux->accel); + reinterpret_cast(reinterpret_cast(nfa) + aux->accel); dumpAccelInfo(f, *accel); } } @@ -310,7 +310,7 @@ void nfaExecSheng32_dumpText(const NFA *nfa, FILE *f) { static void nfaExecSheng64_dumpText(const NFA *nfa, FILE *f) { assert(nfa->type == SHENG_NFA_64); - const sheng64 *s = (const sheng64 *)getImplNfa(nfa); + const sheng64 *s = reinterpret_cast(getImplNfa(nfa)); fprintf(f, "sheng64 DFA\n"); dumpHeader64(f, s); @@ -321,19 +321,19 @@ void nfaExecSheng64_dumpText(const NFA *nfa, FILE *f) { if (aux->accept) { fprintf(f, "report list:\n"); const report_list *rl = - (const report_list *)((const char *)nfa + aux->accept); + reinterpret_cast(reinterpret_cast(nfa) + aux->accept); dumpReports(f, rl); } if (aux->accept_eod) { fprintf(f, "EOD report list:\n"); const report_list *rl = - (const report_list *)((const char *)nfa + aux->accept_eod); + reinterpret_cast(reinterpret_cast(nfa) + aux->accept_eod); dumpReports(f, rl); } if (aux->accel) { fprintf(f, "accel:\n"); const AccelAux *accel = - (const AccelAux *)((const char *)nfa + aux->accel); + reinterpret_cast(reinterpret_cast(nfa) + aux->accel); dumpAccelInfo(f, *accel); } } @@ -487,7 +487,7 @@ void describeEdge(FILE *f, const u16 *t, u16 i) { static void shengGetTransitions(const NFA *n, u16 state, u16 *t) { assert(isSheng16Type(n->type)); - const sheng *s = (const sheng *)getImplNfa(n); + const sheng *s = reinterpret_cast(getImplNfa(n)); const sstate_aux *aux = get_aux(n, state); for (unsigned i = 0; i < N_CHARS; i++) { @@ -505,7 +505,7 @@ void shengGetTransitions(const NFA *n, u16 state, u16 *t) { static void sheng32GetTransitions(const NFA *n, u16 state, u16 *t) { assert(isSheng32Type(n->type)); - const sheng32 *s = (const sheng32 *)getImplNfa(n); + const sheng32 *s = reinterpret_cast(getImplNfa(n)); const sstate_aux *aux = get_aux32(n, state); for (unsigned i = 0; i < N_CHARS; i++) { @@ -523,7 +523,7 @@ void sheng32GetTransitions(const NFA *n, u16 state, u16 *t) { static void sheng64GetTransitions(const NFA *n, u16 state, u16 *t) { assert(isSheng64Type(n->type)); - const sheng64 *s = (const sheng64 *)getImplNfa(n); + const sheng64 *s = reinterpret_cast(getImplNfa(n)); const sstate_aux *aux = get_aux64(n, state); for (unsigned i = 0; i < N_CHARS; i++) { @@ -541,7 +541,7 @@ void sheng64GetTransitions(const NFA *n, u16 state, u16 *t) { static void nfaExecSheng_dumpDot(const NFA *nfa, FILE *f) { assert(nfa->type == SHENG_NFA); - const sheng *s = (const sheng *)getImplNfa(nfa); + const sheng *s = reinterpret_cast(getImplNfa(nfa)); dumpDotPreambleDfa(f); @@ -561,7 +561,7 @@ void nfaExecSheng_dumpDot(const NFA *nfa, FILE *f) { static void nfaExecSheng32_dumpDot(const NFA *nfa, FILE *f) { assert(nfa->type == SHENG_NFA_32); - const sheng32 *s = (const sheng32 *)getImplNfa(nfa); + const sheng32 *s = reinterpret_cast(getImplNfa(nfa)); dumpDotPreambleDfa(f); @@ -581,7 +581,7 @@ void nfaExecSheng32_dumpDot(const NFA *nfa, FILE *f) { static void nfaExecSheng64_dumpDot(const NFA *nfa, FILE *f) { assert(nfa->type == SHENG_NFA_64); - const sheng64 *s = (const sheng64 *)getImplNfa(nfa); + const sheng64 *s = reinterpret_cast(getImplNfa(nfa)); dumpDotPreambleDfa(f); diff --git a/src/nfa/tamarama_dump.cpp b/src/nfa/tamarama_dump.cpp index e6d34f7c..72d926bf 100644 --- a/src/nfa/tamarama_dump.cpp +++ b/src/nfa/tamarama_dump.cpp @@ -52,7 +52,7 @@ using namespace std; namespace ue2 { void nfaExecTamarama_dump(const struct NFA *nfa, const string &base) { - const Tamarama *t = (const Tamarama *)getImplNfa(nfa); + const Tamarama *t = reinterpret_cast(getImplNfa(nfa)); StdioFile f(base + ".txt", "w"); @@ -65,10 +65,10 @@ void nfaExecTamarama_dump(const struct NFA *nfa, const string &base) { fprintf(f, "\n"); const u32 *subOffset = - (const u32 *)((const char *)t + sizeof(struct Tamarama) + + reinterpret_cast(reinterpret_cast(t) + sizeof(struct Tamarama) + t->numSubEngines * sizeof(u32)); for (u32 i = 0; i < t->numSubEngines; i++) { - const NFA *sub = (const struct NFA *)((const char *)t + subOffset[i]); + const NFA *sub = reinterpret_cast(reinterpret_cast(t) + subOffset[i]); stringstream sssub; sssub << base << "_sub_" << i; diff --git a/src/rose/rose_build_engine_blob.h b/src/rose/rose_build_engine_blob.h index da4e355d..7c4adcea 100644 --- a/src/rose/rose_build_engine_blob.h +++ b/src/rose/rose_build_engine_blob.h @@ -144,6 +144,7 @@ public: } void write_bytes(RoseEngine *engine) { + // cppcheck-suppress cstyleCast copy_bytes((char *)engine + base_offset, blob); } diff --git a/src/rose/rose_internal.h b/src/rose/rose_internal.h index 7bd6779c..5986dc77 100644 --- a/src/rose/rose_internal.h +++ b/src/rose/rose_internal.h @@ -560,9 +560,10 @@ const struct anchored_matcher_info *getALiteralMatcher( if (!t->amatcherOffset) { return NULL; } - + // cppcheck-suppress cstyleCast const char *lt = (const char *)t + t->amatcherOffset; assert(ISALIGNED_CL(lt)); + // cppcheck-suppress cstyleCast return (const struct anchored_matcher_info *)lt; } @@ -573,9 +574,10 @@ const struct HWLM *getFLiteralMatcher(const struct RoseEngine *t) { if (!t->fmatcherOffset) { return NULL; } - + // cppcheck-suppress cstyleCast const char *lt = (const char *)t + t->fmatcherOffset; assert(ISALIGNED_CL(lt)); + // cppcheck-suppress cstyleCast return (const struct HWLM *)lt; } @@ -584,7 +586,7 @@ const void *getSBLiteralMatcher(const struct RoseEngine *t) { if (!t->sbmatcherOffset) { return NULL; } - + // cppcheck-suppress cstyleCast const char *matcher = (const char *)t + t->sbmatcherOffset; assert(ISALIGNED_N(matcher, 8)); return matcher; @@ -592,8 +594,8 @@ const void *getSBLiteralMatcher(const struct RoseEngine *t) { static really_inline const struct LeftNfaInfo *getLeftTable(const struct RoseEngine *t) { - const struct LeftNfaInfo *r - = (const struct LeftNfaInfo *)((const char *)t + t->leftOffset); + // cppcheck-suppress cstyleCast + const struct LeftNfaInfo *r = (const struct LeftNfaInfo *)((const char *)t + t->leftOffset); assert(ISALIGNED_N(r, 4)); return r; } @@ -603,16 +605,16 @@ struct mmbit_sparse_iter; // forward decl static really_inline const struct mmbit_sparse_iter *getActiveLeftIter(const struct RoseEngine *t) { assert(t->activeLeftIterOffset); - const struct mmbit_sparse_iter *it = (const struct mmbit_sparse_iter *) - ((const char *)t + t->activeLeftIterOffset); + // cppcheck-suppress cstyleCast + const struct mmbit_sparse_iter *it = (const struct mmbit_sparse_iter *)((const char *)t + t->activeLeftIterOffset); assert(ISALIGNED_N(it, 4)); return it; } static really_inline const struct NfaInfo *getNfaInfoByQueue(const struct RoseEngine *t, u32 qi) { - const struct NfaInfo *infos - = (const struct NfaInfo *)((const char *)t + t->nfaInfoOffset); + // cppcheck-suppress cstyleCast + const struct NfaInfo *infos= (const struct NfaInfo *)((const char *)t + t->nfaInfoOffset); assert(ISALIGNED_N(infos, sizeof(u32))); return &infos[qi]; @@ -621,6 +623,7 @@ const struct NfaInfo *getNfaInfoByQueue(const struct RoseEngine *t, u32 qi) { static really_inline const struct NFA *getNfaByInfo(const struct RoseEngine *t, const struct NfaInfo *info) { + // cppcheck-suppress cstyleCast return (const struct NFA *)((const char *)t + info->nfaOffset); } @@ -650,9 +653,8 @@ const struct SmallWriteEngine *getSmallWrite(const struct RoseEngine *t) { if (!t->smallWriteOffset) { return NULL; } - - const struct SmallWriteEngine *smwr = - (const struct SmallWriteEngine *)((const char *)t + t->smallWriteOffset); + // cppcheck-suppress cstyleCast + const struct SmallWriteEngine *smwr =(const struct SmallWriteEngine *)((const char *)t + t->smallWriteOffset); return smwr; } diff --git a/src/smallwrite/smallwrite_internal.h b/src/smallwrite/smallwrite_internal.h index 8f350dbe..50947ba3 100644 --- a/src/smallwrite/smallwrite_internal.h +++ b/src/smallwrite/smallwrite_internal.h @@ -43,8 +43,8 @@ struct NFA; static really_inline const struct NFA *getSmwrNfa(const struct SmallWriteEngine *smwr) { assert(smwr); - const struct NFA *n - = (const struct NFA *)((const char *)smwr + sizeof(*smwr)); + // cppcheck-suppress cstyleCast + const struct NFA *n= (const struct NFA *)((const char *)smwr + sizeof(*smwr)); assert(ISALIGNED_CL(n)); return n; } diff --git a/src/util/arch/common/simd_utils.h b/src/util/arch/common/simd_utils.h index 24331b10..6f091bc7 100644 --- a/src/util/arch/common/simd_utils.h +++ b/src/util/arch/common/simd_utils.h @@ -238,6 +238,7 @@ static really_inline u32 diffrich64_256(m256 a, m256 b) { // aligned load static really_inline m256 load256(const void *ptr) { assert(ISALIGNED_N(ptr, alignof(m256))); + // cppcheck-suppress cstyleCast m256 rv = { load128(ptr), load128((const char *)ptr + 16) }; return rv; } @@ -255,11 +256,13 @@ static really_inline m256 loadu2x128(const void *ptr) { static really_inline void store256(void *ptr, m256 a) { assert(ISALIGNED_N(ptr, alignof(m256))); ptr = vectorscan_assume_aligned(ptr, 16); + // cppcheck-suppress cstyleCast *(m256 *)ptr = a; } // unaligned load static really_inline m256 loadu256(const void *ptr) { + // cppcheck-suppress cstyleCast m256 rv = { loadu128(ptr), loadu128((const char *)ptr + 16) }; return rv; } @@ -267,6 +270,7 @@ static really_inline m256 loadu256(const void *ptr) { // unaligned store static really_inline void storeu256(void *ptr, m256 a) { storeu128(ptr, a.lo); + // cppcheck-suppress cstyleCast storeu128((char *)ptr + 16, a.hi); } @@ -476,8 +480,8 @@ static really_inline u32 diffrich64_384(m384 a, m384 b) { // aligned load static really_inline m384 load384(const void *ptr) { assert(ISALIGNED_16(ptr)); - m384 rv = { load128(ptr), load128((const char *)ptr + 16), - load128((const char *)ptr + 32) }; + // cppcheck-suppress cstyleCast + m384 rv = { load128(ptr), load128((const char *)ptr + 16),load128((const char *)ptr + 32) }; return rv; } @@ -485,13 +489,14 @@ static really_inline m384 load384(const void *ptr) { static really_inline void store384(void *ptr, m384 a) { assert(ISALIGNED_16(ptr)); ptr = vectorscan_assume_aligned(ptr, 16); + // cppcheck-suppress cstyleCast *(m384 *)ptr = a; } // unaligned load static really_inline m384 loadu384(const void *ptr) { - m384 rv = { loadu128(ptr), loadu128((const char *)ptr + 16), - loadu128((const char *)ptr + 32)}; + // cppcheck-suppress cstyleCast + m384 rv = { loadu128(ptr), loadu128((const char *)ptr + 16),loadu128((const char *)ptr + 32)}; return rv; } @@ -703,6 +708,7 @@ u32 diffrich64_512(m512 a, m512 b) { static really_inline m512 load512(const void *ptr) { assert(ISALIGNED_N(ptr, alignof(m256))); + // cppcheck-suppress cstyleCast m512 rv = { load256(ptr), load256((const char *)ptr + 32) }; return rv; } @@ -711,6 +717,7 @@ m512 load512(const void *ptr) { static really_inline void store512(void *ptr, m512 a) { assert(ISALIGNED_N(ptr, alignof(m512))); + // cppcheck-suppress cstyleCast m512 *x = (m512 *)ptr; store256(&x->lo, a.lo); store256(&x->hi, a.hi); @@ -719,6 +726,7 @@ void store512(void *ptr, m512 a) { // unaligned load static really_inline m512 loadu512(const void *ptr) { + // cppcheck-suppress cstyleCast m512 rv = { loadu256(ptr), loadu256((const char *)ptr + 32) }; return rv; } diff --git a/src/util/arch/x86/simd_utils.h b/src/util/arch/x86/simd_utils.h index 49797aba..1fc15800 100644 --- a/src/util/arch/x86/simd_utils.h +++ b/src/util/arch/x86/simd_utils.h @@ -290,6 +290,7 @@ static really_inline m128 andnot128(m128 a, m128 b) { static really_inline m128 load128(const void *ptr) { assert(ISALIGNED_N(ptr, alignof(m128))); ptr = vectorscan_assume_aligned(ptr, 16); + // cppcheck-suppress cstyleCast return _mm_load_si128((const m128 *)ptr); } @@ -297,16 +298,19 @@ static really_inline m128 load128(const void *ptr) { static really_inline void store128(void *ptr, m128 a) { assert(ISALIGNED_N(ptr, alignof(m128))); ptr = vectorscan_assume_aligned(ptr, 16); + // cppcheck-suppress cstyleCast *(m128 *)ptr = a; } // unaligned load static really_inline m128 loadu128(const void *ptr) { + // cppcheck-suppress cstyleCast return _mm_loadu_si128((const m128 *)ptr); } // unaligned store static really_inline void storeu128(void *ptr, m128 a) { + // cppcheck-suppress cstyleCast _mm_storeu_si128 ((m128 *)ptr, a); } diff --git a/src/util/partial_store.h b/src/util/partial_store.h index a49d1fae..efe357cc 100644 --- a/src/util/partial_store.h +++ b/src/util/partial_store.h @@ -43,12 +43,14 @@ void partial_store_u32(void *ptr, u32 value, u32 numBytes) { break; case 3: unaligned_store_u16(ptr, (u16)value); + // cppcheck-suppress cstyleCast *((u8 *)ptr + 2) = (u8)(value >> 16); break; case 2: unaligned_store_u16(ptr, (u16)value); break; case 1: + // cppcheck-suppress cstyleCast *(u8 *)ptr = (u8)value; break; case 0: @@ -66,12 +68,14 @@ u32 partial_load_u32(const void *ptr, u32 numBytes) { return value; case 3: value = unaligned_load_u16(ptr); + // cppcheck-suppress cstyleCast value |= ((u32)(*((const u8 *)ptr + 2)) << 16); return value; case 2: value = unaligned_load_u16(ptr); return value; case 1: + // cppcheck-suppress cstyleCast value = *(const u8 *)ptr; return value; case 0: @@ -90,15 +94,19 @@ void partial_store_u64a(void *ptr, u64a value, u32 numBytes) { break; case 7: unaligned_store_u32(ptr, (u32)value); + // cppcheck-suppress cstyleCast unaligned_store_u16((u8 *)ptr + 4, (u16)(value >> 32)); + // cppcheck-suppress cstyleCast *((u8 *)ptr + 6) = (u8)(value >> 48); break; case 6: unaligned_store_u32(ptr, (u32)value); + // cppcheck-suppress cstyleCast unaligned_store_u16((u8 *)ptr + 4, (u16)(value >> 32)); break; case 5: unaligned_store_u32(ptr, (u32)value); + // cppcheck-suppress cstyleCast *((u8 *)ptr + 4) = (u8)(value >> 32); break; case 4: @@ -106,12 +114,14 @@ void partial_store_u64a(void *ptr, u64a value, u32 numBytes) { break; case 3: unaligned_store_u16(ptr, (u16)value); + // cppcheck-suppress cstyleCast *((u8 *)ptr + 2) = (u8)(value >> 16); break; case 2: unaligned_store_u16(ptr, (u16)value); break; case 1: + // cppcheck-suppress cstyleCast *(u8 *)ptr = (u8)value; break; case 0: @@ -129,15 +139,19 @@ u64a partial_load_u64a(const void *ptr, u32 numBytes) { return value; case 7: value = unaligned_load_u32(ptr); + // cppcheck-suppress cstyleCast value |= (u64a)unaligned_load_u16((const u8 *)ptr + 4) << 32; + // cppcheck-suppress cstyleCast value |= (u64a)(*((const u8 *)ptr + 6)) << 48; return value; case 6: value = unaligned_load_u32(ptr); + // cppcheck-suppress cstyleCast value |= (u64a)unaligned_load_u16((const u8 *)ptr + 4) << 32; return value; case 5: value = unaligned_load_u32(ptr); + // cppcheck-suppress cstyleCast value |= (u64a)(*((const u8 *)ptr + 4)) << 32; return value; case 4: @@ -145,12 +159,14 @@ u64a partial_load_u64a(const void *ptr, u32 numBytes) { return value; case 3: value = unaligned_load_u16(ptr); + // cppcheck-suppress cstyleCast value |= (u64a)(*((const u8 *)ptr + 2)) << 16; return value; case 2: value = unaligned_load_u16(ptr); return value; case 1: + // cppcheck-suppress cstyleCast value = *(const u8 *)ptr; return value; case 0: diff --git a/src/util/supervector/arch/x86/impl.cpp b/src/util/supervector/arch/x86/impl.cpp index 0323d5e5..38b8b179 100644 --- a/src/util/supervector/arch/x86/impl.cpp +++ b/src/util/supervector/arch/x86/impl.cpp @@ -1112,7 +1112,7 @@ really_inline SuperVector<32> SuperVector<32>::Ones_vshl(uint8_t const N) template <> really_inline SuperVector<32> SuperVector<32>::loadu(void const *ptr) { - return {SuperVector<32>(_mm256_loadu_si256((const m256 *)ptr))}; + return {SuperVector<32>(_mm256_loadu_si256(reinterpret_cast(ptr)))}; } template <> @@ -1120,7 +1120,7 @@ really_inline SuperVector<32> SuperVector<32>::load(void const *ptr) { assert(ISALIGNED_N(ptr, alignof(SuperVector::size))); ptr = vectorscan_assume_aligned(ptr, SuperVector::size); - return {SuperVector<32>(_mm256_load_si256((const m256 *)ptr))}; + return {SuperVector<32>(_mm256_load_si256(reinterpret_cast(ptr)))}; } template <> @@ -1128,7 +1128,7 @@ really_inline SuperVector<32> SuperVector<32>::loadu_maskz(void const *ptr, uint { #ifdef HAVE_AVX512 u32 mask = (~0ULL) >> (32 - len); - SuperVector<32> v = SuperVector<32>(_mm256_mask_loadu_epi8(Zeroes().u.v256[0], mask, (const m256 *)ptr)); + SuperVector<32> v = SuperVector<32>(_mm256_mask_loadu_epi8(Zeroes().u.v256[0], mask, reinterpret_cast(ptr))); v.print8("v"); return v; #else @@ -1136,7 +1136,7 @@ really_inline SuperVector<32> SuperVector<32>::loadu_maskz(void const *ptr, uint SuperVector<32> mask = Ones_vshr(32 -len); mask.print8("mask"); (Ones() >> (32 - len)).print8("mask"); - SuperVector<32> v = SuperVector<32>(_mm256_loadu_si256((const m256 *)ptr)); + SuperVector<32> v = SuperVector<32>(_mm256_loadu_si256(reinterpret_cast(ptr))); v.print8("v"); return mask & v; #endif @@ -1762,7 +1762,7 @@ really_inline SuperVector<64> SuperVector<64>::operator<<(uint8_t const N) const template <> really_inline SuperVector<64> SuperVector<64>::loadu(void const *ptr) { - return {SuperVector<64>(_mm512_loadu_si512((const m512 *)ptr))}; + return {SuperVector<64>(_mm512_loadu_si512(reinterpret_cast(ptr)))}; } template <> @@ -1770,7 +1770,7 @@ really_inline SuperVector<64> SuperVector<64>::load(void const *ptr) { assert(ISALIGNED_N(ptr, alignof(SuperVector::size))); ptr = vectorscan_assume_aligned(ptr, SuperVector::size); - return {SuperVector<64>(_mm512_load_si512((const m512 *)ptr))}; + return {SuperVector<64>(_mm512_load_si512(reinterpret_cast(ptr)))}; } template <> @@ -1778,7 +1778,7 @@ really_inline SuperVector<64> SuperVector<64>::loadu_maskz(void const *ptr, uint { u64a mask = (~0ULL) >> (64 - len); DEBUG_PRINTF("mask = %016llx\n", mask); - SuperVector<64> v = SuperVector<64>(_mm512_mask_loadu_epi8(Zeroes().u.v512[0], mask, (const m512 *)ptr)); + SuperVector<64> v = SuperVector<64>(_mm512_mask_loadu_epi8(Zeroes().u.v512[0], mask, reinterpret_cast(ptr))); v.print8("v"); return v; } diff --git a/src/util/unaligned.h b/src/util/unaligned.h index a8fba6b1..3f662de1 100644 --- a/src/util/unaligned.h +++ b/src/util/unaligned.h @@ -41,6 +41,7 @@ static really_inline u16 unaligned_load_u16(const void *ptr) { struct unaligned { u16 u; } PACKED__MAY_ALIAS; + // cppcheck-suppress cstyleCast const struct unaligned *uptr = (const struct unaligned *)ptr; return uptr->u; } @@ -49,6 +50,7 @@ u16 unaligned_load_u16(const void *ptr) { static really_inline u32 unaligned_load_u32(const void *ptr) { struct unaligned { u32 u; } PACKED__MAY_ALIAS; + // cppcheck-suppress cstyleCast const struct unaligned *uptr = (const struct unaligned *)ptr; return uptr->u; } @@ -57,6 +59,7 @@ u32 unaligned_load_u32(const void *ptr) { static really_inline u64a unaligned_load_u64a(const void *ptr) { struct unaligned { u64a u; } PACKED__MAY_ALIAS; + // cppcheck-suppress cstyleCast const struct unaligned *uptr = (const struct unaligned *)ptr; return uptr->u; } @@ -65,6 +68,7 @@ u64a unaligned_load_u64a(const void *ptr) { static really_inline void unaligned_store_u16(void *ptr, u16 val) { struct unaligned { u16 u; } PACKED__MAY_ALIAS; + // cppcheck-suppress cstyleCast struct unaligned *uptr = (struct unaligned *)ptr; uptr->u = val; } @@ -73,6 +77,7 @@ void unaligned_store_u16(void *ptr, u16 val) { static really_inline void unaligned_store_u32(void *ptr, u32 val) { struct unaligned { u32 u; } PACKED__MAY_ALIAS; + // cppcheck-suppress cstyleCast struct unaligned *uptr = (struct unaligned *)ptr; uptr->u = val; } @@ -81,6 +86,7 @@ void unaligned_store_u32(void *ptr, u32 val) { static really_inline void unaligned_store_u64a(void *ptr, u64a val) { struct unaligned { u64a u; } PACKED__MAY_ALIAS; + // cppcheck-suppress cstyleCast struct unaligned *uptr = (struct unaligned *)ptr; uptr->u = val; }