mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
Merge pull request #286 from VectorCamp/bugfix/cppcheck-fix-wrong-casts
Fix remaining C style casts and suppressions
This commit is contained in:
commit
cd39f71e80
@ -106,7 +106,8 @@ struct FiveTuple {
|
||||
dstAddr = iphdr->ip_dst.s_addr;
|
||||
|
||||
// UDP/TCP ports
|
||||
const struct udphdr *uh = reinterpret_cast<const struct udphdr *>(iphdr) + (iphdr->ip_hl * 4);
|
||||
const char * iphdr_base = reinterpret_cast<const char *>(iphdr);
|
||||
const struct udphdr *uh = reinterpret_cast<const struct udphdr *>(iphdr_base + (iphdr->ip_hl * 4));
|
||||
srcPort = uh->uh_sport;
|
||||
dstPort = uh->uh_dport;
|
||||
}
|
||||
@ -231,7 +232,7 @@ public:
|
||||
}
|
||||
|
||||
// Valid TCP or UDP packet
|
||||
const struct ip *iphdr = reinterpret_cast<const struct ip *>(pktData) + sizeof(struct ether_header);
|
||||
const struct ip *iphdr = reinterpret_cast<const struct ip *>(pktData + sizeof(struct ether_header));
|
||||
const char *payload = reinterpret_cast<const char *>(pktData) + offset;
|
||||
|
||||
size_t id = stream_map.insert(std::make_pair(FiveTuple(iphdr),
|
||||
@ -572,7 +573,8 @@ int main(int argc, char **argv) {
|
||||
*/
|
||||
static bool payloadOffset(const unsigned char *pkt_data, unsigned int *offset,
|
||||
unsigned int *length) {
|
||||
const ip *iph = reinterpret_cast<const ip *>(pkt_data) + sizeof(ether_header);
|
||||
const ip *iph = reinterpret_cast<const ip *>(pkt_data + sizeof(ether_header));
|
||||
const char *iph_base = reinterpret_cast<const char *>(iph);
|
||||
const tcphdr *th = nullptr;
|
||||
|
||||
// Ignore packets that aren't IPv4
|
||||
@ -591,7 +593,7 @@ static bool payloadOffset(const unsigned char *pkt_data, unsigned int *offset,
|
||||
|
||||
switch (iph->ip_p) {
|
||||
case IPPROTO_TCP:
|
||||
th = reinterpret_cast<const tcphdr *>(iph) + ihlen;
|
||||
th = reinterpret_cast<const tcphdr *>(iph_base + ihlen);
|
||||
thlen = th->th_off * 4;
|
||||
break;
|
||||
case IPPROTO_UDP:
|
||||
|
@ -632,11 +632,12 @@ buildCastle(const CastleProto &proto,
|
||||
|
||||
if (patchSize[i]) {
|
||||
RepeatInfo *info = reinterpret_cast<RepeatInfo *>(ptr);
|
||||
u64a *table = reinterpret_cast<u64a *>(ROUNDUP_PTR(info +
|
||||
char *info_base = reinterpret_cast<char *>(info);
|
||||
u64a *table = reinterpret_cast<u64a *>(ROUNDUP_PTR(info_base +
|
||||
sizeof(*info), alignof(u64a)));
|
||||
copy(tables.begin() + tableIdx,
|
||||
tables.begin() + tableIdx + patchSize[i], table);
|
||||
u32 diff = reinterpret_cast<ptrdiff_t>(table) - reinterpret_cast<ptrdiff_t>(info) +
|
||||
u32 diff = reinterpret_cast<char *>(table) - info_base +
|
||||
sizeof(u64a) * patchSize[i];
|
||||
info->length = diff;
|
||||
length += diff;
|
||||
|
@ -1077,7 +1077,6 @@ bytecode_ptr<NFA> goughCompile(raw_som_dfa &raw, u8 somPrecision,
|
||||
return bytecode_ptr<NFA>(nullptr);
|
||||
}
|
||||
|
||||
// cppcheck-suppress cstyleCast
|
||||
const auto nfa = static_cast<const mcclellan *>(getImplNfa(basic_dfa.get()));
|
||||
u8 alphaShift = nfa->alphaShift;
|
||||
u32 edge_count = (1U << alphaShift) * raw.states.size();
|
||||
@ -1134,7 +1133,6 @@ bytecode_ptr<NFA> goughCompile(raw_som_dfa &raw, u8 somPrecision,
|
||||
gough_dfa->streamStateSize = base_state_size + slot_count * somPrecision;
|
||||
gough_dfa->scratchStateSize = (u32)(16 + scratch_slot_count * sizeof(u64a));
|
||||
|
||||
// cppcheck-suppress cstyleCast
|
||||
auto *m = reinterpret_cast<mcclellan *>(getMutableImplNfa(gough_dfa.get()));
|
||||
m->haig_offset = haig_offset;
|
||||
|
||||
|
@ -269,7 +269,7 @@ void maskClear(Mask &m) {
|
||||
template<class Mask>
|
||||
u8 *maskGetByte(Mask &m, u32 bit) {
|
||||
assert(bit < sizeof(m)*8);
|
||||
u8 *m8 = (u8 *)&m;
|
||||
u8 *m8 = reinterpret_cast<u8 *>(&m);
|
||||
|
||||
return m8 + bit/8;
|
||||
}
|
||||
@ -290,7 +290,7 @@ void maskSetBits(Mask &m, const NFAStateSet &bits) {
|
||||
|
||||
template<class Mask>
|
||||
bool isMaskZero(Mask &m) {
|
||||
const u8 *m8 = (u8 *)&m;
|
||||
const u8 *m8 = reinterpret_cast<u8 *>(&m);
|
||||
for (u32 i = 0; i < sizeof(m); i++) {
|
||||
if (m8[i]) {
|
||||
return false;
|
||||
@ -303,7 +303,7 @@ bool isMaskZero(Mask &m) {
|
||||
template<class Mask>
|
||||
void maskSetByte(Mask &m, const unsigned int idx, const char val) {
|
||||
assert(idx < sizeof(m));
|
||||
char *m8 = (char *)&m;
|
||||
char *m8 = reinterpret_cast<char *>(&m);
|
||||
char &byte = m8[idx];
|
||||
byte = val;
|
||||
}
|
||||
@ -1702,7 +1702,7 @@ struct Factory {
|
||||
static
|
||||
void allocState(NFA *nfa, u32 repeatscratchStateSize,
|
||||
u32 repeatStreamState) {
|
||||
const implNFA_t *limex = (implNFA_t *)getMutableImplNfa(nfa);
|
||||
const implNFA_t *limex = reinterpret_cast<implNFA_t *>(getMutableImplNfa(nfa));
|
||||
|
||||
// LimEx NFAs now store the following in state:
|
||||
// 1. state bitvector (always present)
|
||||
@ -1768,7 +1768,7 @@ struct Factory {
|
||||
u32 tableOffset, tugMaskOffset;
|
||||
size_t len = repeatAllocSize(br, &tableOffset, &tugMaskOffset);
|
||||
auto info = make_zeroed_bytecode_ptr<NFARepeatInfo>(len);
|
||||
char *info_ptr = (char *)info.get();
|
||||
char *info_ptr = reinterpret_cast<char *>(info.get());
|
||||
|
||||
// Collect state space info.
|
||||
RepeatStateInfo rsi(br.type, br.repeatMin, br.repeatMax, br.minPeriod);
|
||||
@ -1783,8 +1783,7 @@ struct Factory {
|
||||
info->tugMaskOffset = tugMaskOffset;
|
||||
|
||||
// Fill the RepeatInfo structure.
|
||||
RepeatInfo *repeat =
|
||||
(RepeatInfo *)(info_ptr + sizeof(NFARepeatInfo));
|
||||
RepeatInfo *repeat = reinterpret_cast<RepeatInfo *>(info_ptr + sizeof(NFARepeatInfo));
|
||||
repeat->type = br.type;
|
||||
repeat->repeatMin = depth_to_u32(br.repeatMin);
|
||||
repeat->repeatMax = depth_to_u32(br.repeatMax);
|
||||
@ -1810,7 +1809,7 @@ struct Factory {
|
||||
}
|
||||
|
||||
// Fill the tug mask.
|
||||
tableRow_t *tugMask = (tableRow_t *)(info_ptr + tugMaskOffset);
|
||||
tableRow_t *tugMask = reinterpret_cast<tableRow_t *>(info_ptr + tugMaskOffset);
|
||||
for (auto v : br.tug_triggers) {
|
||||
u32 state_id = args.state_ids.at(v);
|
||||
assert(state_id != NO_STATE);
|
||||
@ -1931,7 +1930,7 @@ struct Factory {
|
||||
const u32 reportListOffset) {
|
||||
DEBUG_PRINTF("exceptionsOffset=%u\n", exceptionsOffset);
|
||||
|
||||
exception_t *etable = (exception_t *)((char *)limex + exceptionsOffset);
|
||||
exception_t *etable = reinterpret_cast<exception_t *>(reinterpret_cast<char *>(limex) + exceptionsOffset);
|
||||
assert(ISALIGNED(etable));
|
||||
|
||||
map<u32, ExceptionProto> exception_by_state;
|
||||
@ -1979,10 +1978,10 @@ struct Factory {
|
||||
limex->exceptionCount = ecount;
|
||||
|
||||
if (args.num_states > 64 && args.cc.target_info.has_avx512vbmi()) {
|
||||
const u8 *exceptionMask = (const u8 *)(&limex->exceptionMask);
|
||||
u8 *shufMask = (u8 *)&limex->exceptionShufMask;
|
||||
u8 *bitMask = (u8 *)&limex->exceptionBitMask;
|
||||
u8 *andMask = (u8 *)&limex->exceptionAndMask;
|
||||
const u8 *exceptionMask = reinterpret_cast<const u8 *>(&limex->exceptionMask);
|
||||
u8 *shufMask = reinterpret_cast<u8 *>(&limex->exceptionShufMask);
|
||||
u8 *bitMask = reinterpret_cast<u8 *>(&limex->exceptionBitMask);
|
||||
u8 *andMask = reinterpret_cast<u8 *>(&limex->exceptionAndMask);
|
||||
|
||||
u32 tot_cnt = 0;
|
||||
u32 pos = 0;
|
||||
@ -2042,7 +2041,7 @@ struct Factory {
|
||||
copy(reachMap.begin(), reachMap.end(), &limex->reachMap[0]);
|
||||
|
||||
// Reach table is right after the LimEx structure.
|
||||
tableRow_t *reachMask = (tableRow_t *)((char *)limex + reachOffset);
|
||||
tableRow_t *reachMask = reinterpret_cast<tableRow_t *>(reinterpret_cast<char *>(limex) + reachOffset);
|
||||
assert(ISALIGNED(reachMask));
|
||||
for (size_t i = 0, end = reach.size(); i < end; i++) {
|
||||
maskSetBits(reachMask[i], reach[i]);
|
||||
@ -2056,7 +2055,7 @@ struct Factory {
|
||||
DEBUG_PRINTF("topsOffset=%u\n", topsOffset);
|
||||
|
||||
limex->topOffset = topsOffset;
|
||||
tableRow_t *topMasks = (tableRow_t *)((char *)limex + topsOffset);
|
||||
tableRow_t *topMasks = reinterpret_cast<tableRow_t *>(reinterpret_cast<char *>(limex) + topsOffset);
|
||||
assert(ISALIGNED(topMasks));
|
||||
|
||||
for (size_t i = 0, end = tops.size(); i < end; i++) {
|
||||
@ -2068,8 +2067,8 @@ struct Factory {
|
||||
|
||||
static
|
||||
void writeAccelSsse3Masks(const NFAStateSet &accelMask, implNFA_t *limex) {
|
||||
char *perm_base = (char *)&limex->accelPermute;
|
||||
char *comp_base = (char *)&limex->accelCompare;
|
||||
char *perm_base = reinterpret_cast<char *>(&limex->accelPermute);
|
||||
char *comp_base = reinterpret_cast<char *>(&limex->accelCompare);
|
||||
|
||||
u32 num = 0; // index in accel table.
|
||||
for (size_t i = accelMask.find_first(); i != accelMask.npos;
|
||||
@ -2080,8 +2079,8 @@ struct Factory {
|
||||
// PSHUFB permute and compare masks
|
||||
size_t mask_idx = sizeof(u_128) * (state_id / 128U);
|
||||
DEBUG_PRINTF("mask_idx=%zu\n", mask_idx);
|
||||
u_128 *perm = (u_128 *)(perm_base + mask_idx);
|
||||
u_128 *comp = (u_128 *)(comp_base + mask_idx);
|
||||
u_128 *perm = reinterpret_cast<u_128 *>(perm_base + mask_idx);
|
||||
u_128 *comp = reinterpret_cast<u_128 *>(comp_base + mask_idx);
|
||||
maskSetByte(*perm, num, ((state_id % 128U) / 8U));
|
||||
maskSetByte(*comp, num, ~(1U << (state_id % 8U)));
|
||||
}
|
||||
@ -2099,11 +2098,11 @@ struct Factory {
|
||||
// Write accel lookup table.
|
||||
limex->accelTableOffset = accelTableOffset;
|
||||
copy(accelTable.begin(), accelTable.end(),
|
||||
(u8 *)((char *)limex + accelTableOffset));
|
||||
reinterpret_cast<u8 *>(reinterpret_cast<char *>(limex) + accelTableOffset));
|
||||
|
||||
// Write accel aux structures.
|
||||
limex->accelAuxOffset = accelAuxOffset;
|
||||
AccelAux *auxTable = (AccelAux *)((char *)limex + accelAuxOffset);
|
||||
AccelAux *auxTable = reinterpret_cast<AccelAux *>(reinterpret_cast<char *>(limex) + accelAuxOffset);
|
||||
assert(ISALIGNED(auxTable));
|
||||
copy(accelAux.begin(), accelAux.end(), auxTable);
|
||||
|
||||
@ -2133,7 +2132,7 @@ struct Factory {
|
||||
const vector<NFAStateSet> &squash, implNFA_t *limex,
|
||||
const u32 acceptsOffset, const u32 acceptsEodOffset,
|
||||
const u32 squashOffset, const u32 reportListOffset) {
|
||||
char *limex_base = (char *)limex;
|
||||
char *limex_base = reinterpret_cast<char *>(limex);
|
||||
|
||||
DEBUG_PRINTF("acceptsOffset=%u, acceptsEodOffset=%u, squashOffset=%u\n",
|
||||
acceptsOffset, acceptsEodOffset, squashOffset);
|
||||
@ -2156,7 +2155,7 @@ struct Factory {
|
||||
limex->acceptOffset = acceptsOffset;
|
||||
limex->acceptCount = verify_u32(accepts.size());
|
||||
DEBUG_PRINTF("NFA has %zu accepts\n", accepts.size());
|
||||
NFAAccept *acceptsTable = (NFAAccept *)(limex_base + acceptsOffset);
|
||||
NFAAccept *acceptsTable = reinterpret_cast<NFAAccept *>(limex_base + acceptsOffset);
|
||||
assert(ISALIGNED(acceptsTable));
|
||||
transform(accepts.begin(), accepts.end(), acceptsTable,
|
||||
transform_offset_fn);
|
||||
@ -2165,7 +2164,7 @@ struct Factory {
|
||||
limex->acceptEodOffset = acceptsEodOffset;
|
||||
limex->acceptEodCount = verify_u32(acceptsEod.size());
|
||||
DEBUG_PRINTF("NFA has %zu EOD accepts\n", acceptsEod.size());
|
||||
NFAAccept *acceptsEodTable = (NFAAccept *)(limex_base + acceptsEodOffset);
|
||||
NFAAccept *acceptsEodTable = reinterpret_cast<NFAAccept *>(limex_base + acceptsEodOffset);
|
||||
assert(ISALIGNED(acceptsEodTable));
|
||||
transform(acceptsEod.begin(), acceptsEod.end(), acceptsEodTable,
|
||||
transform_offset_fn);
|
||||
@ -2174,7 +2173,7 @@ struct Factory {
|
||||
limex->squashCount = verify_u32(squash.size());
|
||||
limex->squashOffset = squashOffset;
|
||||
DEBUG_PRINTF("NFA has %zu report squash masks\n", squash.size());
|
||||
tableRow_t *mask = (tableRow_t *)(limex_base + squashOffset);
|
||||
tableRow_t *mask = reinterpret_cast<tableRow_t *>(limex_base + squashOffset);
|
||||
assert(ISALIGNED(mask));
|
||||
for (size_t i = 0, end = squash.size(); i < end; i++) {
|
||||
maskSetBits(mask[i], squash[i]);
|
||||
@ -2196,13 +2195,13 @@ struct Factory {
|
||||
for (u32 i = 0; i < num_repeats; i++) {
|
||||
repeatOffsets[i] = offset;
|
||||
assert(repeats[i]);
|
||||
memcpy((char *)limex + offset, repeats[i].get(), repeats[i].size());
|
||||
memcpy(reinterpret_cast<char *>(limex) + offset, repeats[i].get(), repeats[i].size());
|
||||
offset += repeats[i].size();
|
||||
}
|
||||
|
||||
// Write repeat offset lookup table.
|
||||
assert(ISALIGNED_N((char *)limex + repeatOffsetsOffset, alignof(u32)));
|
||||
copy_bytes((char *)limex + repeatOffsetsOffset, repeatOffsets);
|
||||
assert(ISALIGNED_N(reinterpret_cast<char *>(limex) + repeatOffsetsOffset, alignof(u32)));
|
||||
copy_bytes(reinterpret_cast<char *>(limex) + repeatOffsetsOffset, repeatOffsets);
|
||||
|
||||
limex->repeatOffset = repeatOffsetsOffset;
|
||||
limex->repeatCount = num_repeats;
|
||||
@ -2212,9 +2211,9 @@ struct Factory {
|
||||
void writeReportList(const vector<ReportID> &reports, implNFA_t *limex,
|
||||
const u32 reportListOffset) {
|
||||
DEBUG_PRINTF("reportListOffset=%u\n", reportListOffset);
|
||||
assert(ISALIGNED_N((char *)limex + reportListOffset,
|
||||
assert(ISALIGNED_N(reinterpret_cast<char *>(limex) + reportListOffset,
|
||||
alignof(ReportID)));
|
||||
copy_bytes((char *)limex + reportListOffset, reports);
|
||||
copy_bytes(reinterpret_cast<char *>(limex) + reportListOffset, reports);
|
||||
}
|
||||
|
||||
static
|
||||
@ -2323,7 +2322,7 @@ struct Factory {
|
||||
auto nfa = make_zeroed_bytecode_ptr<NFA>(nfaSize);
|
||||
assert(nfa); // otherwise we would have thrown std::bad_alloc
|
||||
|
||||
implNFA_t *limex = (implNFA_t *)getMutableImplNfa(nfa.get());
|
||||
implNFA_t *limex = reinterpret_cast<implNFA_t *>(getMutableImplNfa(nfa.get()));
|
||||
assert(ISALIGNED(limex));
|
||||
|
||||
writeReachMapping(reach, reachMap, limex, reachOffset);
|
||||
|
@ -106,9 +106,10 @@ static really_inline
|
||||
const char *findShermanState(UNUSED const struct mcclellan *m,
|
||||
const char *sherman_base_offset, u32 sherman_base,
|
||||
u32 s) {
|
||||
const char *rv
|
||||
= sherman_base_offset + SHERMAN_FIXED_SIZE * (s - sherman_base);
|
||||
const char *rv = sherman_base_offset + SHERMAN_FIXED_SIZE * (s - sherman_base);
|
||||
// cppcheck-suppress cstyleCast
|
||||
assert(rv < (const char *)m + m->length - sizeof(struct NFA));
|
||||
// cppcheck-suppress cstyleCast
|
||||
UNUSED u8 type = *(const u8 *)(rv + SHERMAN_TYPE_OFFSET);
|
||||
assert(type == SHERMAN_STATE);
|
||||
return rv;
|
||||
@ -123,13 +124,15 @@ char *findMutableShermanState(char *sherman_base_offset, u16 sherman_base,
|
||||
static really_inline
|
||||
const char *findWideEntry8(UNUSED const struct mcclellan *m,
|
||||
const char *wide_base, u32 wide_limit, u32 s) {
|
||||
// cppcheck-suppress cstyleCast
|
||||
UNUSED u8 type = *(const u8 *)wide_base;
|
||||
assert(type == WIDE_STATE);
|
||||
const u32 entry_offset
|
||||
= *(const u32 *)(wide_base
|
||||
// cppcheck-suppress cstyleCast
|
||||
const u32 entry_offset = *(const u32 *)(wide_base
|
||||
+ WIDE_ENTRY_OFFSET8((s - wide_limit) * sizeof(u32)));
|
||||
|
||||
const char *rv = wide_base + entry_offset;
|
||||
// cppcheck-suppress cstyleCast
|
||||
assert(rv < (const char *)m + m->length - sizeof(struct NFA));
|
||||
return rv;
|
||||
}
|
||||
@ -137,21 +140,23 @@ const char *findWideEntry8(UNUSED const struct mcclellan *m,
|
||||
static really_inline
|
||||
const char *findWideEntry16(UNUSED const struct mcclellan *m,
|
||||
const char *wide_base, u32 wide_limit, u32 s) {
|
||||
// cppcheck-suppress cstyleCast
|
||||
UNUSED u8 type = *(const u8 *)wide_base;
|
||||
assert(type == WIDE_STATE);
|
||||
const u32 entry_offset
|
||||
= *(const u32 *)(wide_base
|
||||
// cppcheck-suppress cstyleCast
|
||||
const u32 entry_offset = *(const u32 *)(wide_base
|
||||
+ WIDE_ENTRY_OFFSET16((s - wide_limit) * sizeof(u32)));
|
||||
|
||||
const char *rv = wide_base + entry_offset;
|
||||
// cppcheck-suppress cstyleCast
|
||||
assert(rv < (const char *)m + m->length - sizeof(struct NFA));
|
||||
return rv;
|
||||
}
|
||||
|
||||
static really_inline
|
||||
char *findMutableWideEntry16(char *wide_base, u32 wide_limit, u32 s) {
|
||||
u32 entry_offset
|
||||
= *(const u32 *)(wide_base
|
||||
// cppcheck-suppress cstyleCast
|
||||
u32 entry_offset = *(const u32 *)(wide_base
|
||||
+ WIDE_ENTRY_OFFSET16((s - wide_limit) * sizeof(u32)));
|
||||
|
||||
return wide_base + entry_offset;
|
||||
|
@ -176,11 +176,11 @@ static
|
||||
mstate_aux *getAux(NFA *n, dstate_id_t i) {
|
||||
assert(isMcClellanType(n->type));
|
||||
|
||||
const mcclellan *m = (mcclellan *)getMutableImplNfa(n);
|
||||
mstate_aux *aux_base = (mstate_aux *)((char *)n + m->aux_offset);
|
||||
const mcclellan *m = reinterpret_cast<const mcclellan *>(getImplNfa(n));
|
||||
mstate_aux *aux_base = reinterpret_cast<mstate_aux *>(reinterpret_cast<u8 *>(n) + m->aux_offset);
|
||||
|
||||
mstate_aux *aux = aux_base + i;
|
||||
assert((const char *)aux < (const char *)n + m->length);
|
||||
assert(reinterpret_cast<const char *>(aux) < reinterpret_cast<const char *>(n) + m->length);
|
||||
return aux;
|
||||
}
|
||||
|
||||
@ -190,7 +190,7 @@ void markEdges(NFA *n, u16 *succ_table, const dfa_info &info) {
|
||||
assert(n->type == MCCLELLAN_NFA_16);
|
||||
u8 alphaShift = info.getAlphaShift();
|
||||
u16 alphaSize = info.impl_alpha_size;
|
||||
mcclellan *m = (mcclellan *)getMutableImplNfa(n);
|
||||
mcclellan *m = reinterpret_cast<mcclellan *>(getMutableImplNfa(n));
|
||||
|
||||
/* handle the normal states */
|
||||
for (u32 i = 0; i < m->sherman_limit; i++) {
|
||||
@ -215,17 +215,17 @@ void markEdges(NFA *n, u16 *succ_table, const dfa_info &info) {
|
||||
}
|
||||
|
||||
/* handle the sherman states */
|
||||
char *sherman_base_offset = (char *)n + m->sherman_offset;
|
||||
char *sherman_base_offset = reinterpret_cast<char *>(n) + m->sherman_offset;
|
||||
u16 sherman_ceil = m->has_wide == 1 ? m->wide_limit : m->state_count;
|
||||
for (u16 j = m->sherman_limit; j < sherman_ceil; j++) {
|
||||
char *sherman_cur
|
||||
= findMutableShermanState(sherman_base_offset, m->sherman_limit, j);
|
||||
assert(*(sherman_cur + SHERMAN_TYPE_OFFSET) == SHERMAN_STATE);
|
||||
u8 len = *(u8 *)(sherman_cur + SHERMAN_LEN_OFFSET);
|
||||
u16 *succs = (u16 *)(sherman_cur + SHERMAN_STATES_OFFSET(len));
|
||||
u8 len = *(reinterpret_cast<u8 *>(sherman_cur + SHERMAN_LEN_OFFSET));
|
||||
u16 *succs = reinterpret_cast<u16 *>(sherman_cur + SHERMAN_STATES_OFFSET(len));
|
||||
|
||||
for (u8 i = 0; i < len; i++) {
|
||||
u16 succ_i = unaligned_load_u16((u8 *)&succs[i]);
|
||||
u16 succ_i = unaligned_load_u16(reinterpret_cast<u8 *>(&succs[i]));
|
||||
// wide state has no aux structure.
|
||||
if (m->has_wide && succ_i >= m->wide_limit) {
|
||||
continue;
|
||||
@ -241,25 +241,25 @@ void markEdges(NFA *n, u16 *succ_table, const dfa_info &info) {
|
||||
succ_i |= ACCEL_FLAG;
|
||||
}
|
||||
|
||||
unaligned_store_u16((u8 *)&succs[i], succ_i);
|
||||
unaligned_store_u16(reinterpret_cast<u8 *>(&succs[i]), succ_i);
|
||||
}
|
||||
}
|
||||
|
||||
/* handle the wide states */
|
||||
if (m->has_wide) {
|
||||
u32 wide_limit = m->wide_limit;
|
||||
char *wide_base = (char *)n + m->wide_offset;
|
||||
char *wide_base = reinterpret_cast<char *>(n) + m->wide_offset;
|
||||
assert(*wide_base == WIDE_STATE);
|
||||
u16 wide_number = verify_u16(info.wide_symbol_chain.size());
|
||||
// traverse over wide head states.
|
||||
for (u16 j = wide_limit; j < wide_limit + wide_number; j++) {
|
||||
char *wide_cur
|
||||
= findMutableWideEntry16(wide_base, wide_limit, j);
|
||||
u16 width = *(const u16 *)(wide_cur + WIDE_WIDTH_OFFSET);
|
||||
u16 *trans = (u16 *)(wide_cur + WIDE_TRANSITION_OFFSET16(width));
|
||||
u16 width = *(reinterpret_cast<const u16 *>(wide_cur + WIDE_WIDTH_OFFSET));
|
||||
u16 *trans = reinterpret_cast<u16 *>(wide_cur + WIDE_TRANSITION_OFFSET16(width));
|
||||
|
||||
// check successful transition
|
||||
u16 next = unaligned_load_u16((u8 *)trans);
|
||||
u16 next = unaligned_load_u16(reinterpret_cast<u8 *>(trans));
|
||||
if (next < wide_limit) {
|
||||
const mstate_aux *aux = getAux(n, next);
|
||||
if (aux->accept) {
|
||||
@ -268,13 +268,13 @@ void markEdges(NFA *n, u16 *succ_table, const dfa_info &info) {
|
||||
if (aux->accel_offset) {
|
||||
next |= ACCEL_FLAG;
|
||||
}
|
||||
unaligned_store_u16((u8 *)trans, next);
|
||||
unaligned_store_u16(reinterpret_cast<u8 *>(trans), next);
|
||||
}
|
||||
trans++;
|
||||
|
||||
// check failure transition
|
||||
for (symbol_t k = 0; k < alphaSize; k++) {
|
||||
u16 next_k = unaligned_load_u16((u8 *)&trans[k]);
|
||||
u16 next_k = unaligned_load_u16(reinterpret_cast<u8 *>(&trans[k]));
|
||||
if (next_k >= wide_limit) {
|
||||
continue;
|
||||
}
|
||||
@ -285,7 +285,7 @@ void markEdges(NFA *n, u16 *succ_table, const dfa_info &info) {
|
||||
if (aux_k->accel_offset) {
|
||||
next_k |= ACCEL_FLAG;
|
||||
}
|
||||
unaligned_store_u16((u8 *)&trans[k], next_k);
|
||||
unaligned_store_u16(reinterpret_cast<u8 *>(&trans[k]), next_k);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -321,7 +321,7 @@ void populateBasicInfo(size_t state_size, const dfa_info &info,
|
||||
nfa->type = MCCLELLAN_NFA_16;
|
||||
}
|
||||
|
||||
mcclellan *m = (mcclellan *)getMutableImplNfa(nfa);
|
||||
mcclellan *m = reinterpret_cast<mcclellan *>(getMutableImplNfa(nfa));
|
||||
for (u32 i = 0; i < 256; i++) {
|
||||
m->remap[i] = verify_u8(info.alpha_remap[i]);
|
||||
}
|
||||
@ -485,7 +485,7 @@ void raw_report_info_impl::fillReportLists(NFA *n, size_t base_offset,
|
||||
for (const auto &reps : rl) {
|
||||
ro.emplace_back(base_offset);
|
||||
|
||||
report_list *p = (report_list *)((char *)n + base_offset);
|
||||
report_list *p = reinterpret_cast<report_list *>(reinterpret_cast<char *>(n) + base_offset);
|
||||
|
||||
u32 i = 0;
|
||||
for (const ReportID report : reps.reports) {
|
||||
@ -665,7 +665,7 @@ bytecode_ptr<NFA> mcclellanCompile16(dfa_info &info, const CompileContext &cc,
|
||||
DEBUG_PRINTF("total_size %zu\n", total_size);
|
||||
|
||||
auto nfa = make_zeroed_bytecode_ptr<NFA>(total_size);
|
||||
char *nfa_base = (char *)nfa.get();
|
||||
char *nfa_base = reinterpret_cast<char *>(nfa.get());
|
||||
|
||||
populateBasicInfo(sizeof(u16), info, total_size, aux_offset, accel_offset,
|
||||
accel_escape_info.size(), arb, single, nfa.get());
|
||||
@ -674,9 +674,9 @@ bytecode_ptr<NFA> mcclellanCompile16(dfa_info &info, const CompileContext &cc,
|
||||
|
||||
ri->fillReportLists(nfa.get(), aux_offset + aux_size, reportOffsets);
|
||||
|
||||
u16 *succ_table = (u16 *)(nfa_base + sizeof(NFA) + sizeof(mcclellan));
|
||||
mstate_aux *aux = (mstate_aux *)(nfa_base + aux_offset);
|
||||
mcclellan *m = (mcclellan *)getMutableImplNfa(nfa.get());
|
||||
u16 *succ_table = reinterpret_cast<u16 *>(nfa_base + sizeof(NFA) + sizeof(mcclellan));
|
||||
mstate_aux *aux = reinterpret_cast<mstate_aux *>(nfa_base + aux_offset);
|
||||
mcclellan *m = reinterpret_cast<mcclellan *>(getMutableImplNfa(nfa.get()));
|
||||
|
||||
m->wide_limit = wide_limit;
|
||||
m->wide_offset = wide_offset;
|
||||
@ -710,7 +710,7 @@ bytecode_ptr<NFA> mcclellanCompile16(dfa_info &info, const CompileContext &cc,
|
||||
assert(accel_offset + sizeof(NFA) <= sherman_offset);
|
||||
assert(ISALIGNED_N(accel_offset, alignof(union AccelAux)));
|
||||
info.strat.buildAccel(i, accel_escape_info.at(i),
|
||||
(void *)((char *)m + this_aux->accel_offset));
|
||||
reinterpret_cast<void *>(reinterpret_cast<char *>(m) + this_aux->accel_offset));
|
||||
}
|
||||
}
|
||||
|
||||
@ -740,17 +740,17 @@ bytecode_ptr<NFA> mcclellanCompile16(dfa_info &info, const CompileContext &cc,
|
||||
assert(accel_offset + sizeof(NFA) <= sherman_offset);
|
||||
assert(ISALIGNED_N(accel_offset, alignof(union AccelAux)));
|
||||
info.strat.buildAccel(i, accel_escape_info.at(i),
|
||||
(void *)((char *)m + this_aux->accel_offset));
|
||||
reinterpret_cast<void *>(reinterpret_cast<char *>(m) + this_aux->accel_offset));
|
||||
}
|
||||
|
||||
u8 len = verify_u8(info.impl_alpha_size - info.extra[i].daddytaken);
|
||||
assert(len <= 9);
|
||||
dstate_id_t d = info.states[i].daddy;
|
||||
|
||||
*(u8 *)(curr_sherman_entry + SHERMAN_TYPE_OFFSET) = SHERMAN_STATE;
|
||||
*(u8 *)(curr_sherman_entry + SHERMAN_LEN_OFFSET) = len;
|
||||
*(u16 *)(curr_sherman_entry + SHERMAN_DADDY_OFFSET) = info.implId(d);
|
||||
u8 *chars = (u8 *)(curr_sherman_entry + SHERMAN_CHARS_OFFSET);
|
||||
*(reinterpret_cast<u8 *>(curr_sherman_entry + SHERMAN_TYPE_OFFSET)) = SHERMAN_STATE;
|
||||
*(reinterpret_cast<u8 *>(curr_sherman_entry + SHERMAN_LEN_OFFSET)) = len;
|
||||
*(reinterpret_cast<u16 *>(curr_sherman_entry + SHERMAN_DADDY_OFFSET)) = info.implId(d);
|
||||
u8 *chars = reinterpret_cast<u8 *>(curr_sherman_entry + SHERMAN_CHARS_OFFSET);
|
||||
|
||||
for (u16 s = 0; s < info.impl_alpha_size; s++) {
|
||||
if (info.states[i].next[s] != info.states[d].next[s]) {
|
||||
@ -758,13 +758,13 @@ bytecode_ptr<NFA> mcclellanCompile16(dfa_info &info, const CompileContext &cc,
|
||||
}
|
||||
}
|
||||
|
||||
u16 *states = (u16 *)(curr_sherman_entry + SHERMAN_STATES_OFFSET(len));
|
||||
u16 *states = reinterpret_cast<u16 *>(curr_sherman_entry + SHERMAN_STATES_OFFSET(len));
|
||||
for (u16 s = 0; s < info.impl_alpha_size; s++) {
|
||||
if (info.states[i].next[s] != info.states[d].next[s]) {
|
||||
DEBUG_PRINTF("s overrider %hu dad %hu char next %hu\n",
|
||||
fs, info.implId(d),
|
||||
info.implId(info.states[i].next[s]));
|
||||
unaligned_store_u16((u8 *)states++,
|
||||
unaligned_store_u16(reinterpret_cast<u8 *>(states++),
|
||||
info.implId(info.states[i].next[s]));
|
||||
}
|
||||
}
|
||||
@ -777,13 +777,13 @@ bytecode_ptr<NFA> mcclellanCompile16(dfa_info &info, const CompileContext &cc,
|
||||
assert(ISALIGNED_16(wide_base));
|
||||
|
||||
char *wide_top = wide_base;
|
||||
*(u8 *)(wide_top++) = WIDE_STATE;
|
||||
*(reinterpret_cast<u8 *>(wide_top++)) = WIDE_STATE;
|
||||
wide_top = ROUNDUP_PTR(wide_top, 2);
|
||||
*(u16 *)(wide_top) = wide_number;
|
||||
*(reinterpret_cast<u16 *>(wide_top)) = wide_number;
|
||||
wide_top += 2;
|
||||
|
||||
char *curr_wide_entry = wide_top + wide_number * sizeof(u32);
|
||||
u32 *wide_offset_list = (u32 *)wide_top;
|
||||
u32 *wide_offset_list = reinterpret_cast<u32 *>(wide_top);
|
||||
|
||||
/* get the order of writing wide states */
|
||||
vector<size_t> order(wide_number);
|
||||
@ -798,8 +798,8 @@ bytecode_ptr<NFA> mcclellanCompile16(dfa_info &info, const CompileContext &cc,
|
||||
const vector<symbol_t> &symbol_chain = info.wide_symbol_chain[i];
|
||||
|
||||
u16 width = verify_u16(symbol_chain.size());
|
||||
*(u16 *)(curr_wide_entry + WIDE_WIDTH_OFFSET) = width;
|
||||
u8 *chars = (u8 *)(curr_wide_entry + WIDE_SYMBOL_OFFSET16);
|
||||
*(reinterpret_cast<u16 *>(curr_wide_entry + WIDE_WIDTH_OFFSET)) = width;
|
||||
u8 *chars = reinterpret_cast<u8 *>(curr_wide_entry + WIDE_SYMBOL_OFFSET16);
|
||||
|
||||
// store wide state symbol chain
|
||||
for (size_t j = 0; j < width; j++) {
|
||||
@ -807,7 +807,7 @@ bytecode_ptr<NFA> mcclellanCompile16(dfa_info &info, const CompileContext &cc,
|
||||
}
|
||||
|
||||
// store wide state transition table
|
||||
u16 *trans = (u16 *)(curr_wide_entry
|
||||
u16 *trans = reinterpret_cast<u16 *>(curr_wide_entry
|
||||
+ WIDE_TRANSITION_OFFSET16(width));
|
||||
dstate_id_t tail = state_chain[width - 1];
|
||||
symbol_t last = symbol_chain[width -1];
|
||||
@ -831,7 +831,7 @@ bytecode_ptr<NFA> mcclellanCompile16(dfa_info &info, const CompileContext &cc,
|
||||
|
||||
*wide_offset_list++ = verify_u32(curr_wide_entry - wide_base);
|
||||
|
||||
curr_wide_entry = (char *)trans;
|
||||
curr_wide_entry = reinterpret_cast<char *>(trans);
|
||||
}
|
||||
}
|
||||
|
||||
@ -953,9 +953,9 @@ bytecode_ptr<NFA> mcclellanCompile8(dfa_info &info, const CompileContext &cc,
|
||||
assert(ISALIGNED_N(accel_offset, alignof(union AccelAux)));
|
||||
|
||||
auto nfa = make_zeroed_bytecode_ptr<NFA>(total_size);
|
||||
char *nfa_base = (char *)nfa.get();
|
||||
char *nfa_base = reinterpret_cast<char *>(nfa.get());
|
||||
|
||||
mcclellan *m = (mcclellan *)getMutableImplNfa(nfa.get());
|
||||
mcclellan *m = reinterpret_cast<mcclellan *>(getMutableImplNfa(nfa.get()));
|
||||
|
||||
allocateFSN8(info, accel_escape_info, &m->accel_limit_8,
|
||||
&m->accept_limit_8);
|
||||
@ -967,8 +967,8 @@ bytecode_ptr<NFA> mcclellanCompile8(dfa_info &info, const CompileContext &cc,
|
||||
ri->fillReportLists(nfa.get(), aux_offset + aux_size, reportOffsets);
|
||||
|
||||
/* copy in the state information */
|
||||
u8 *succ_table = (u8 *)(nfa_base + sizeof(NFA) + sizeof(mcclellan));
|
||||
mstate_aux *aux = (mstate_aux *)(nfa_base + aux_offset);
|
||||
u8 *succ_table = reinterpret_cast<u8 *>(nfa_base + sizeof(NFA) + sizeof(mcclellan));
|
||||
mstate_aux *aux = reinterpret_cast<mstate_aux *>(nfa_base + aux_offset);
|
||||
|
||||
for (size_t i = 0; i < info.size(); i++) {
|
||||
if (contains(accel_escape_info, i)) {
|
||||
@ -978,7 +978,7 @@ bytecode_ptr<NFA> mcclellanCompile8(dfa_info &info, const CompileContext &cc,
|
||||
accel_offset += info.strat.accelSize();
|
||||
|
||||
info.strat.buildAccel(i, accel_escape_info.at(i),
|
||||
(void *)((char *)m + aux[j].accel_offset));
|
||||
reinterpret_cast<void *>(reinterpret_cast<char *>(m) + aux[j].accel_offset));
|
||||
}
|
||||
|
||||
fillInBasicState8(info, aux, succ_table, reportOffsets, reports,
|
||||
@ -1550,7 +1550,7 @@ u32 mcclellanStartReachSize(const raw_dfa *raw) {
|
||||
}
|
||||
|
||||
bool has_accel_mcclellan(const NFA *nfa) {
|
||||
const mcclellan *m = (const mcclellan *)getImplNfa(nfa);
|
||||
const mcclellan *m = reinterpret_cast<const mcclellan *>(getImplNfa(nfa));
|
||||
return m->has_accel;
|
||||
}
|
||||
|
||||
|
@ -180,25 +180,27 @@ void writeKiloPuff(const map<ClusterKey, vector<raw_puff>>::const_iterator &it,
|
||||
#ifdef HAVE_SVE2
|
||||
} else if (reach.count() >= 240) {
|
||||
kp->type = MPV_VERM16;
|
||||
vermicelli16Build(~reach, (u8 *)&kp->u.verm16.mask);
|
||||
vermicelli16Build(~reach, reinterpret_cast<u8 *>(&kp->u.verm16.mask));
|
||||
} else if (reach.count() <= 16) {
|
||||
kp->type = MPV_NVERM16;
|
||||
vermicelli16Build(reach, (u8 *)&kp->u.verm16.mask);
|
||||
vermicelli16Build(reach, reinterpret_cast<u8 *>(&kp->u.verm16.mask));
|
||||
#endif // HAVE_SVE2
|
||||
} else if (shuftiBuildMasks(~reach, (u8 *)&kp->u.shuf.mask_lo,
|
||||
(u8 *)&kp->u.shuf.mask_hi) != -1) {
|
||||
} else if (shuftiBuildMasks(~reach,
|
||||
reinterpret_cast<u8 *>(&kp->u.shuf.mask_lo),
|
||||
reinterpret_cast<u8 *>(&kp->u.shuf.mask_hi)) != -1) {
|
||||
kp->type = MPV_SHUFTI;
|
||||
} else {
|
||||
kp->type = MPV_TRUFFLE;
|
||||
truffleBuildMasks(~reach, (u8 *)&kp->u.truffle.mask1,
|
||||
(u8 *)&kp->u.truffle.mask2);
|
||||
truffleBuildMasks(~reach,
|
||||
reinterpret_cast<u8 *>(&kp->u.truffle.mask1),
|
||||
reinterpret_cast<u8 *>(&kp->u.truffle.mask2));
|
||||
}
|
||||
|
||||
kp->count = verify_u32(puffs.size());
|
||||
kp->counter_offset = counter_offset;
|
||||
|
||||
/* start of real puffette array */
|
||||
kp->puffette_offset = verify_u32((char *)*pa - (char *)m);
|
||||
kp->puffette_offset = verify_u32(reinterpret_cast<char *>(*pa) - reinterpret_cast<char *>(m));
|
||||
for (size_t i = 0; i < puffs.size(); i++) {
|
||||
assert(!it->first.auto_restart || puffs[i].unbounded);
|
||||
writePuffette(*pa + i, puffs[i], rm);
|
||||
@ -355,8 +357,8 @@ bytecode_ptr<NFA> mpvCompile(const vector<raw_puff> &puffs_in,
|
||||
|
||||
auto nfa = make_zeroed_bytecode_ptr<NFA>(len);
|
||||
|
||||
mpv_puffette *pa_base = (mpv_puffette *)
|
||||
((char *)nfa.get() + sizeof(NFA) + sizeof(mpv)
|
||||
char *nfa_base = reinterpret_cast<char *>(nfa.get());
|
||||
mpv_puffette *pa_base = reinterpret_cast<mpv_puffette *>(nfa_base + sizeof(NFA) + sizeof(mpv)
|
||||
+ sizeof(mpv_kilopuff) * puff_clusters.size()
|
||||
+ sizeof(mpv_counter_info) * counters.size());
|
||||
mpv_puffette *pa = pa_base;
|
||||
@ -373,7 +375,7 @@ bytecode_ptr<NFA> mpvCompile(const vector<raw_puff> &puffs_in,
|
||||
min_repeat = min(min_repeat, puffs.front().repeats);
|
||||
}
|
||||
|
||||
mpv *m = (mpv *)getMutableImplNfa(nfa.get());
|
||||
mpv *m = reinterpret_cast<mpv *>(getMutableImplNfa(nfa.get()));
|
||||
m->kilo_count = verify_u32(puff_clusters.size());
|
||||
m->counter_count = verify_u32(counters.size());
|
||||
m->puffette_count = puffette_count;
|
||||
@ -384,7 +386,7 @@ bytecode_ptr<NFA> mpvCompile(const vector<raw_puff> &puffs_in,
|
||||
m->top_kilo_begin = verify_u32(triggered_puffs.size());
|
||||
m->top_kilo_end = verify_u32(puff_clusters.size());
|
||||
|
||||
mpv_kilopuff *kp_begin = (mpv_kilopuff *)(m + 1);
|
||||
mpv_kilopuff *kp_begin = reinterpret_cast<mpv_kilopuff *>(m + 1);
|
||||
mpv_kilopuff *kp = kp_begin;
|
||||
for (auto it = puff_clusters.begin(); it != puff_clusters.end(); ++it) {
|
||||
writeKiloPuff(it, rm,
|
||||
@ -392,14 +394,14 @@ bytecode_ptr<NFA> mpvCompile(const vector<raw_puff> &puffs_in,
|
||||
kp, &pa);
|
||||
++kp;
|
||||
}
|
||||
assert((char *)pa == (char *)nfa.get() + len);
|
||||
assert(reinterpret_cast<char *>(pa) == nfa_base + len);
|
||||
|
||||
mpv_counter_info *out_ci = (mpv_counter_info *)kp;
|
||||
mpv_counter_info *out_ci = reinterpret_cast<mpv_counter_info *>(kp);
|
||||
for (const auto &counter : counters) {
|
||||
*out_ci = counter;
|
||||
++out_ci;
|
||||
}
|
||||
assert((char *)out_ci == (char *)pa_base);
|
||||
assert(reinterpret_cast<char *>(out_ci) == reinterpret_cast<char *>(pa_base));
|
||||
|
||||
writeCoreNfa(nfa.get(), len, min_repeat, max_counter, curr_comp_offset,
|
||||
curr_decomp_offset);
|
||||
|
@ -86,14 +86,14 @@ typedef bool (*nfa_dispatch_fn)(const NFA *nfa);
|
||||
template<typename T>
|
||||
static
|
||||
bool has_accel_limex(const NFA *nfa) {
|
||||
const T *limex = (const T *)getImplNfa(nfa);
|
||||
const T *limex = reinterpret_cast<const T *>(getImplNfa(nfa));
|
||||
return limex->accelCount;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static
|
||||
bool has_repeats_limex(const NFA *nfa) {
|
||||
const T *limex = (const T *)getImplNfa(nfa);
|
||||
const T *limex = reinterpret_cast<const T *>(getImplNfa(nfa));
|
||||
return limex->repeatCount;
|
||||
}
|
||||
|
||||
@ -101,16 +101,16 @@ bool has_repeats_limex(const NFA *nfa) {
|
||||
template<typename T>
|
||||
static
|
||||
bool has_repeats_other_than_firsts_limex(const NFA *nfa) {
|
||||
const T *limex = (const T *)getImplNfa(nfa);
|
||||
const char *ptr = (const char *)limex;
|
||||
const T *limex = reinterpret_cast<const T *>(getImplNfa(nfa));
|
||||
const char *ptr = reinterpret_cast<const char *>(limex);
|
||||
|
||||
const u32 *repeatOffset = (const u32 *)(ptr + limex->repeatOffset);
|
||||
const u32 *repeatOffset = reinterpret_cast<const u32 *>(ptr + limex->repeatOffset);
|
||||
|
||||
for (u32 i = 0; i < limex->repeatCount; i++) {
|
||||
u32 offset = repeatOffset[i];
|
||||
const NFARepeatInfo *info = (const NFARepeatInfo *)(ptr + offset);
|
||||
const NFARepeatInfo *info = reinterpret_cast<const NFARepeatInfo *>(ptr + offset);
|
||||
const RepeatInfo *repeat =
|
||||
(const RepeatInfo *)((const char *)info + sizeof(*info));
|
||||
reinterpret_cast<const RepeatInfo *>(reinterpret_cast<const char *>(info) + sizeof(*info));
|
||||
if (repeat->type != REPEAT_FIRST) {
|
||||
return true;
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ void raw_report_info_impl::fillReportLists(NFA *n, size_t base_offset,
|
||||
for (const auto &reps : rl) {
|
||||
ro.emplace_back(base_offset);
|
||||
|
||||
report_list *p = (report_list *)((char *)n + base_offset);
|
||||
report_list *p = reinterpret_cast<report_list *>(reinterpret_cast<char *>(n) + base_offset);
|
||||
|
||||
u32 i = 0;
|
||||
for (const ReportID report : reps.reports) {
|
||||
@ -389,17 +389,17 @@ static
|
||||
void fillAccelAux(struct NFA *n, dfa_info &info,
|
||||
map<dstate_id_t, AccelScheme> &accelInfo) {
|
||||
DEBUG_PRINTF("Filling accel aux structures\n");
|
||||
T *s = (T *)getMutableImplNfa(n);
|
||||
T *s = reinterpret_cast<T *>(getMutableImplNfa(n));
|
||||
u32 offset = s->accel_offset;
|
||||
|
||||
for (dstate_id_t i = 0; i < info.size(); i++) {
|
||||
dstate_id_t state_id = info.raw_id(i);
|
||||
if (accelInfo.find(state_id) != accelInfo.end()) {
|
||||
s->flags |= SHENG_FLAG_HAS_ACCEL;
|
||||
AccelAux *aux = (AccelAux *)((char *)n + offset);
|
||||
AccelAux *aux = reinterpret_cast<AccelAux *>(reinterpret_cast<char *>(n) + offset);
|
||||
info.strat.buildAccel(state_id, accelInfo[state_id], aux);
|
||||
sstate_aux *saux =
|
||||
(sstate_aux *)((char *)n + s->aux_offset) + state_id;
|
||||
reinterpret_cast<sstate_aux *>(reinterpret_cast<char *>(n) + s->aux_offset) + state_id;
|
||||
saux->accel = offset;
|
||||
DEBUG_PRINTF("Accel offset: %u\n", offset);
|
||||
offset += ROUNDUP_N(sizeof(AccelAux), alignof(AccelAux));
|
||||
@ -429,7 +429,7 @@ void populateBasicInfo<sheng>(struct NFA *n, dfa_info &info,
|
||||
n->type = SHENG_NFA;
|
||||
n->flags |= info.raw.hasEodReports() ? NFA_ACCEPTS_EOD : 0;
|
||||
|
||||
sheng *s = (sheng *)getMutableImplNfa(n);
|
||||
sheng *s = reinterpret_cast<sheng *>(getMutableImplNfa(n));
|
||||
s->aux_offset = aux_offset;
|
||||
s->report_offset = report_offset;
|
||||
s->accel_offset = accel_offset;
|
||||
@ -454,7 +454,7 @@ void populateBasicInfo<sheng32>(struct NFA *n, dfa_info &info,
|
||||
n->type = SHENG_NFA_32;
|
||||
n->flags |= info.raw.hasEodReports() ? NFA_ACCEPTS_EOD : 0;
|
||||
|
||||
sheng32 *s = (sheng32 *)getMutableImplNfa(n);
|
||||
sheng32 *s = reinterpret_cast<sheng32 *>(getMutableImplNfa(n));
|
||||
s->aux_offset = aux_offset;
|
||||
s->report_offset = report_offset;
|
||||
s->accel_offset = accel_offset;
|
||||
@ -479,7 +479,7 @@ void populateBasicInfo<sheng64>(struct NFA *n, dfa_info &info,
|
||||
n->type = SHENG_NFA_64;
|
||||
n->flags |= info.raw.hasEodReports() ? NFA_ACCEPTS_EOD : 0;
|
||||
|
||||
sheng64 *s = (sheng64 *)getMutableImplNfa(n);
|
||||
sheng64 *s = reinterpret_cast<sheng64 *>(getMutableImplNfa(n));
|
||||
s->aux_offset = aux_offset;
|
||||
s->report_offset = report_offset;
|
||||
s->accel_offset = accel_offset;
|
||||
@ -495,15 +495,15 @@ template <typename T>
|
||||
static
|
||||
void fillTops(NFA *n, dfa_info &info, dstate_id_t id,
|
||||
map<dstate_id_t, AccelScheme> &accelInfo) {
|
||||
T *s = (T *)getMutableImplNfa(n);
|
||||
T *s = reinterpret_cast<T *>(getMutableImplNfa(n));
|
||||
u32 aux_base = s->aux_offset;
|
||||
|
||||
DEBUG_PRINTF("Filling tops for state %u\n", id);
|
||||
|
||||
sstate_aux *aux = (sstate_aux *)((char *)n + aux_base) + id;
|
||||
sstate_aux *aux = reinterpret_cast<sstate_aux *>(reinterpret_cast<char *>(n) + aux_base) + id;
|
||||
|
||||
DEBUG_PRINTF("Aux structure for state %u, offset %zd\n", id,
|
||||
(char *)aux - (char *)n);
|
||||
reinterpret_cast<char *>(aux) - reinterpret_cast<char *>(n));
|
||||
|
||||
/* we could conceivably end up in an accept/dead state on a top event,
|
||||
* so mark top as accept/dead state if it indeed is.
|
||||
@ -519,13 +519,13 @@ template <typename T>
|
||||
static
|
||||
void fillAux(NFA *n, dfa_info &info, dstate_id_t id, vector<u32> &reports,
|
||||
vector<u32> &reports_eod, vector<u32> &report_offsets) {
|
||||
T *s = (T *)getMutableImplNfa(n);
|
||||
T *s = reinterpret_cast<T *>(getMutableImplNfa(n));
|
||||
u32 aux_base = s->aux_offset;
|
||||
auto raw_id = info.raw_id(id);
|
||||
|
||||
auto &state = info[id];
|
||||
|
||||
sstate_aux *aux = (sstate_aux *)((char *)n + aux_base) + id;
|
||||
sstate_aux *aux = reinterpret_cast<sstate_aux *>(reinterpret_cast<char *>(n) + aux_base) + id;
|
||||
|
||||
DEBUG_PRINTF("Filling aux and report structures for state %u\n", id);
|
||||
DEBUG_PRINTF("Aux structure for state %u, offset %zd\n", id,
|
||||
@ -542,7 +542,7 @@ void fillAux(NFA *n, dfa_info &info, dstate_id_t id, vector<u32> &reports,
|
||||
template <typename T>
|
||||
static
|
||||
void fillSingleReport(NFA *n, ReportID r_id) {
|
||||
T *s = (T *)getMutableImplNfa(n);
|
||||
T *s = reinterpret_cast<T *>(getMutableImplNfa(n));
|
||||
|
||||
DEBUG_PRINTF("Single report ID: %u\n", r_id);
|
||||
s->report = r_id;
|
||||
@ -689,7 +689,8 @@ bytecode_ptr<NFA> shengCompile_int(raw_dfa &raw, const CompileContext &cc,
|
||||
fillAccelOut(accelInfo, accel_states);
|
||||
}
|
||||
|
||||
if (!createShuffleMasks<T>((T *)getMutableImplNfa(nfa.get()), info, accelInfo)) {
|
||||
T *s = reinterpret_cast<T *>(getMutableImplNfa(nfa.get()));
|
||||
if (!createShuffleMasks<T>(s, info, accelInfo)) {
|
||||
return bytecode_ptr<NFA>(nullptr);
|
||||
}
|
||||
|
||||
@ -727,18 +728,18 @@ bytecode_ptr<NFA> sheng32Compile(raw_dfa &raw, const CompileContext &cc,
|
||||
set<dstate_id_t> *accel_states) {
|
||||
if (!cc.grey.allowSheng) {
|
||||
DEBUG_PRINTF("Sheng is not allowed!\n");
|
||||
bytecode_ptr<NFA>(nullptr);
|
||||
return bytecode_ptr<NFA>(nullptr);
|
||||
}
|
||||
|
||||
#ifdef HAVE_SVE
|
||||
if (svcntb()<32) {
|
||||
DEBUG_PRINTF("Sheng32 failed, SVE width is too small!\n");
|
||||
bytecode_ptr<NFA>(nullptr);
|
||||
return bytecode_ptr<NFA>(nullptr);
|
||||
}
|
||||
#else
|
||||
if (!cc.target_info.has_avx512vbmi()) {
|
||||
DEBUG_PRINTF("Sheng32 failed, no HS_CPU_FEATURES_AVX512VBMI!\n");
|
||||
bytecode_ptr<NFA>(nullptr);
|
||||
return bytecode_ptr<NFA>(nullptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -142,9 +142,9 @@ buildTamarama(const TamaInfo &tamaInfo, const u32 queue,
|
||||
nfa->length = verify_u32(total_size);
|
||||
nfa->queueIndex = queue;
|
||||
|
||||
char *ptr = (char *)nfa.get() + sizeof(NFA);
|
||||
char *ptr = reinterpret_cast<char *>(nfa.get()) + sizeof(NFA);
|
||||
char *base_offset = ptr;
|
||||
Tamarama *t = (Tamarama *)ptr;
|
||||
Tamarama *t = reinterpret_cast<Tamarama *>(ptr);
|
||||
t->numSubEngines = verify_u32(subSize);
|
||||
t->activeIdxSize = verify_u8(activeIdxSize);
|
||||
|
||||
@ -152,11 +152,11 @@ buildTamarama(const TamaInfo &tamaInfo, const u32 queue,
|
||||
copy_bytes(ptr, top_base);
|
||||
ptr += byte_length(top_base);
|
||||
|
||||
u32 *offsets = (u32 *)ptr;
|
||||
u32 *offsets = reinterpret_cast<u32 *>(ptr);
|
||||
char *sub_nfa_offset = ptr + sizeof(u32) * subSize;
|
||||
copyInSubnfas(base_offset, *nfa, tamaInfo, offsets, sub_nfa_offset,
|
||||
activeIdxSize);
|
||||
assert((size_t)(sub_nfa_offset - (char *)nfa.get()) <= total_size);
|
||||
assert(static_cast<size_t>(sub_nfa_offset - reinterpret_cast<char *>(nfa.get())) <= total_size);
|
||||
return nfa;
|
||||
}
|
||||
|
||||
|
@ -182,7 +182,7 @@ bytecode_ptr<NFA> buildLbrVerm(const CharReach &cr, const depth &repeatMin,
|
||||
enum RepeatType rtype = chooseRepeatType(repeatMin, repeatMax, minPeriod,
|
||||
is_reset);
|
||||
auto nfa = makeLbrNfa<lbr_verm>(LBR_NFA_VERM, rtype, repeatMax);
|
||||
struct lbr_verm *lv = (struct lbr_verm *)getMutableImplNfa(nfa.get());
|
||||
struct lbr_verm *lv = reinterpret_cast<struct lbr_verm *>(getMutableImplNfa(nfa.get()));
|
||||
lv->c = escapes.find_first();
|
||||
|
||||
fillNfa<lbr_verm>(nfa.get(), &lv->common, report, repeatMin, repeatMax,
|
||||
|
@ -65,7 +65,7 @@ bool isValidUtf8(const char *expression, const size_t len) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const u8 *s = (const u8 *)expression;
|
||||
const u8 *s = reinterpret_cast<const u8 *>(expression);
|
||||
u32 val;
|
||||
|
||||
size_t i = 0;
|
||||
|
@ -2966,7 +2966,7 @@ void buildFragmentPrograms(const RoseBuildImpl &build,
|
||||
!lit_prog.empty()) {
|
||||
const auto &cfrag = fragments[pfrag.included_frag_id];
|
||||
assert(pfrag.s.length() >= cfrag.s.length() &&
|
||||
!pfrag.s.any_nocase() == !cfrag.s.any_nocase());
|
||||
!pfrag.s.any_nocase() != !cfrag.s.any_nocase());
|
||||
/** !pfrag.s.any_nocase() >= !cfrag.s.any_nocase()); **/
|
||||
u32 child_offset = cfrag.lit_program_offset;
|
||||
DEBUG_PRINTF("child %u offset %u\n", cfrag.fragment_id,
|
||||
|
@ -68,8 +68,8 @@ namespace ue2 {
|
||||
#endif
|
||||
|
||||
void *aligned_malloc_internal(size_t size, size_t align) {
|
||||
// cppcheck-suppress cstyleCast
|
||||
void *mem= nullptr;;
|
||||
// cppcheck-suppress cstyleCast
|
||||
int rv = posix_memalign(&mem, align, size);
|
||||
if (rv != 0) {
|
||||
DEBUG_PRINTF("posix_memalign returned %d when asked for %zu bytes\n",
|
||||
|
@ -41,37 +41,58 @@
|
||||
#include "unaligned.h"
|
||||
|
||||
// Aligned loads
|
||||
#ifndef __cplusplus__
|
||||
#define load_u8(a) (*(const u8 *)(a))
|
||||
#define load_u16(a) (*(const u16 *)(a))
|
||||
#define load_u32(a) (*(const u32 *)(a))
|
||||
#define load_u64a(a) (*(const u64a *)(a))
|
||||
#else
|
||||
#define load_u8(a) (*(reinterpret_cast<const u8 *>(a))
|
||||
#define load_u16(a) (*(reinterpret_cast<const u16 *>(a))
|
||||
#define load_u32(a) (*(reinterpret_cast<const u32 *>(a))
|
||||
#define load_u64a(a) (*(reinterpret_cast<const u64a *>(a))
|
||||
#endif // __cplusplus__
|
||||
#define load_m128(a) load128(a)
|
||||
#define load_m256(a) load256(a)
|
||||
#define load_m384(a) load384(a)
|
||||
#define load_m512(a) load512(a)
|
||||
|
||||
// Unaligned loads
|
||||
#ifndef __cplusplus__
|
||||
#define loadu_u8(a) (*(const u8 *)(a))
|
||||
#define loadu_u16(a) unaligned_load_u16((const u8 *)(a))
|
||||
#define loadu_u32(a) unaligned_load_u32((const u8 *)(a))
|
||||
#define loadu_u64a(a) unaligned_load_u64a((const u8 *)(a))
|
||||
#else
|
||||
#define loadu_u8(a) (*(reinterpret_cast<const u8 *>(a))
|
||||
#define loadu_u16(a) unaligned_load_u16(reinterpret_cast<const u8 *>(a))
|
||||
#define loadu_u32(a) unaligned_load_u32(reinterpret_cast<const u8 *>(a))
|
||||
#define loadu_u64a(a) unaligned_load_u64a(reinterpret_cast<const u8 *>(a))
|
||||
#endif // __cplusplus__
|
||||
#define loadu_m128(a) loadu128(a)
|
||||
#define loadu_m256(a) loadu256(a)
|
||||
#define loadu_m384(a) loadu384(a)
|
||||
#define loadu_m512(a) loadu512(a)
|
||||
|
||||
// Aligned stores
|
||||
#define store_u8(ptr, a) do { *(u8 *)(ptr) = (a); } while(0)
|
||||
#define store_u16(ptr, a) do { *(u16 *)(ptr) = (a); } while(0)
|
||||
#define store_u32(ptr, a) do { *(u32 *)(ptr) = (a); } while(0)
|
||||
#define store_u64a(ptr, a) do { *(u64a *)(ptr) = (a); } while(0)
|
||||
#ifndef __cplusplus__
|
||||
#define store_u8(ptr, a) do { *(reinterpret_cast<u8 *>(ptr)) = (a); } while(0)
|
||||
#define store_u16(ptr, a) do { *(reinterpret_cast<u16 *>(ptr)) = (a); } while(0)
|
||||
#define store_u32(ptr, a) do { *(reinterpret_cast<u32 *>(ptr)) = (a); } while(0)
|
||||
#define store_u64a(ptr, a) do { *(reinterpret_cast<u64a *>(ptr)) = (a); } while(0)
|
||||
#else
|
||||
#endif // __cplusplus__
|
||||
#define store_m128(ptr, a) store128(ptr, a)
|
||||
#define store_m256(ptr, a) store256(ptr, a)
|
||||
#define store_m384(ptr, a) store384(ptr, a)
|
||||
#define store_m512(ptr, a) store512(ptr, a)
|
||||
|
||||
// Unaligned stores
|
||||
#ifndef __cplusplus__
|
||||
#define storeu_u8(ptr, a) do { *(u8 *)(ptr) = (a); } while(0)
|
||||
#else
|
||||
#define storeu_u8(ptr, a) do { *(reinterpret_cast<u8 *>(ptr)) = (a); } while(0)
|
||||
#endif // __cplusplus__
|
||||
#define storeu_u16(ptr, a) unaligned_store_u16(ptr, a)
|
||||
#define storeu_u32(ptr, a) unaligned_store_u32(ptr, a)
|
||||
#define storeu_u64a(ptr, a) unaligned_store_u64a(ptr, a)
|
||||
|
@ -104,7 +104,7 @@ TEST(ExtParam, LargeExactOffset) {
|
||||
// Try the exact match.
|
||||
corpus = "hatstand" + string(199983, '_') + "teakettle";
|
||||
err = hs_scan(db, corpus.c_str(), corpus.length(), 0, scratch, record_cb,
|
||||
(void *)&c);
|
||||
reinterpret_cast<void *>(&c));
|
||||
ASSERT_EQ(HS_SUCCESS, err);
|
||||
ASSERT_EQ(1U, c.matches.size());
|
||||
ASSERT_EQ(MatchRecord(200000, 0), c.matches[0]);
|
||||
|
@ -52,7 +52,7 @@ static
|
||||
int vectorCallback(unsigned id, unsigned long long from,
|
||||
unsigned long long to, unsigned, void *ctx) {
|
||||
//printf("match id %u at (%llu,%llu)\n", id, from, to);
|
||||
vector<Match> *matches = (vector<Match> *)ctx;
|
||||
vector<Match> *matches = reinterpret_cast<vector<Match> *>(ctx);
|
||||
matches->push_back(Match(id, from, to));
|
||||
return 0;
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ TEST_P(LbrTest, MatchMax) {
|
||||
const string corpus = matchingCorpus(params.max);
|
||||
|
||||
initQueue();
|
||||
q.buffer = (const u8 *)corpus.c_str();
|
||||
q.buffer = reinterpret_cast<const u8 *>(corpus.c_str());
|
||||
q.length = corpus.length();
|
||||
u64a end = corpus.length();
|
||||
|
||||
|
@ -94,7 +94,7 @@ hs_database_t * loadDatabase(const char *filename, bool verbose) {
|
||||
}
|
||||
size_t len = st.st_size;
|
||||
|
||||
bytes = (char *)mmap(nullptr, len, PROT_READ, MAP_SHARED, fd, 0);
|
||||
bytes = reinterpret_cast<char *>(mmap(nullptr, len, PROT_READ, MAP_SHARED, fd, 0));
|
||||
if (bytes == MAP_FAILED) {
|
||||
cout << "mmap failed" << endl;
|
||||
close(fd);
|
||||
|
@ -141,7 +141,7 @@ void prettyPrintRange(std::ostream &out, it_t begin, it_t end) {
|
||||
static really_inline
|
||||
char *makeHex(const unsigned char *pat, unsigned patlen) {
|
||||
size_t hexlen = patlen * 4;
|
||||
char *hexbuf = (char *)malloc(hexlen + 1);
|
||||
char *hexbuf = reinterpret_cast<char *>(malloc(hexlen + 1));
|
||||
unsigned i;
|
||||
char *buf;
|
||||
for (i = 0, buf = hexbuf; i < patlen; i++, buf += 4) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user