Merge pull request #279 from VectorCamp/bugfix/cppcheck-unreadVariable-others

Fix marked as done cppcheck warnings unreadVariable & others
This commit is contained in:
Konstantinos Margaritis
2024-05-15 23:18:02 +03:00
committed by GitHub
27 changed files with 54 additions and 52 deletions

View File

@@ -304,6 +304,7 @@ void minimize_hopcroft(raw_dfa &rdfa, const Grey &grey) {
DEBUG_PRINTF("dfa is empty\n");
}
// cppcheck-suppress unreadVariable
UNUSED const size_t states_before = rdfa.states.size();
HopcroftInfo info(rdfa);

View File

@@ -978,7 +978,6 @@ char nfaExecGough16_initCompressedState(const struct NFA *nfa, u64a offset,
char nfaExecGough8_reportCurrent(const struct NFA *n, struct mq *q) {
const struct mcclellan *m = (const struct mcclellan *)getImplNfa(n);
NfaCallback cb = q->cb;
void *ctxt = q->context;
u8 s = *(u8 *)q->state;
u64a offset = q_cur_offset(q);
const struct gough_som_info *som = getSomInfo(q->state);
@@ -986,6 +985,7 @@ char nfaExecGough8_reportCurrent(const struct NFA *n, struct mq *q) {
assert(s);
if (s >= m->accept_limit_8) {
void *ctxt = q->context;
u32 cached_accept_id = 0;
u16 cached_accept_state = 0;
u32 cached_accept_som = 0;
@@ -1000,7 +1000,6 @@ char nfaExecGough8_reportCurrent(const struct NFA *n, struct mq *q) {
char nfaExecGough16_reportCurrent(const struct NFA *n, struct mq *q) {
const struct mcclellan *m = (const struct mcclellan *)getImplNfa(n);
NfaCallback cb = q->cb;
void *ctxt = q->context;
u16 s = *(u16 *)q->state;
const struct mstate_aux *aux = get_aux(m, s);
u64a offset = q_cur_offset(q);
@@ -1010,6 +1009,7 @@ char nfaExecGough16_reportCurrent(const struct NFA *n, struct mq *q) {
assert(s);
if (aux->accept) {
void *ctxt = q->context;
u32 cached_accept_id = 0;
u16 cached_accept_state = 0;
u32 cached_accept_som = 0;

View File

@@ -803,7 +803,7 @@ private:
static
void prep_joins_for_generation(const GoughGraph &g, GoughVertex v,
map<GoughEdge, edge_join_info> *edge_info) {
map<GoughEdge, edge_join_info> &edge_info) {
DEBUG_PRINTF("writing out joins for %u\n", g[v].state_id);
for (const auto &var : g[v].vars) {
u32 dest_slot = var->slot;
@@ -814,7 +814,7 @@ void prep_joins_for_generation(const GoughGraph &g, GoughVertex v,
}
for (const GoughEdge &incoming_edge : var_edges.second) {
(*edge_info)[incoming_edge].insert(input, dest_slot);
edge_info[incoming_edge].insert(input, dest_slot);
DEBUG_PRINTF("need %u<-%u\n", dest_slot, input);
}
}
@@ -912,7 +912,7 @@ void build_blocks(const GoughGraph &g,
}
map<GoughEdge, edge_join_info> eji;
prep_joins_for_generation(g, t, &eji);
prep_joins_for_generation(g, t, eji);
for (auto &m : eji) {
vector<gough_ins> &block = (*blocks)[gough_edge_id(g, m.first)];

View File

@@ -302,8 +302,8 @@ int PE_FN(STATE_ARG, ESTATE_ARG, UNUSED u32 diffmask, STATE_T *succ,
}
#else
// A copy of the estate as an array of GPR-sized chunks.
CHUNK_T chunks[sizeof(STATE_T) / sizeof(CHUNK_T)];
CHUNK_T emask_chunks[sizeof(STATE_T) / sizeof(CHUNK_T)];
CHUNK_T chunks[sizeof(STATE_T) / sizeof(CHUNK_T)]; // cppcheck-suppress duplicateExpression
CHUNK_T emask_chunks[sizeof(STATE_T) / sizeof(CHUNK_T)]; // cppcheck-suppress duplicateExpression
#ifdef ESTATE_ON_STACK
memcpy(chunks, &estate, sizeof(STATE_T));
#else
@@ -311,7 +311,7 @@ int PE_FN(STATE_ARG, ESTATE_ARG, UNUSED u32 diffmask, STATE_T *succ,
#endif
memcpy(emask_chunks, &limex->exceptionMask, sizeof(STATE_T));
u32 base_index[sizeof(STATE_T) / sizeof(CHUNK_T)];
u32 base_index[sizeof(STATE_T) / sizeof(CHUNK_T)]; // cppcheck-suppress duplicateExpression
base_index[0] = 0;
for (s32 i = 0; i < (s32)ARRAY_LENGTH(base_index) - 1; i++) {
base_index[i + 1] = base_index[i] + POPCOUNT_FN(emask_chunks[i]);

View File

@@ -1379,7 +1379,6 @@ void generate_symbol_chain(dfa_info &info, vector<symbol_t> &chain_tail) {
for (size_t j = 0; j < width; j++) {
dstate_id_t curr_id = state_chain[j];
dstate_id_t next_id = state_chain[j + 1];
// The last state of the chain doesn't belong to a wide state.
info.extra[curr_id].wideState = true;
@@ -1388,6 +1387,7 @@ void generate_symbol_chain(dfa_info &info, vector<symbol_t> &chain_tail) {
if (j == width - 1) {
symbol_chain.emplace_back(chain_tail[i]);
} else {
dstate_id_t next_id = state_chain[j + 1];
for (symbol_t sym = 0; sym < info.impl_alpha_size; sym++) {
if (rdfa.states[curr_id].next[sym] == next_id) {
symbol_chain.emplace_back(sym);

View File

@@ -1018,12 +1018,16 @@ bytecode_ptr<NFA> mcshengCompile16(dfa_info &info, dstate_id_t sheng_end,
// Sherman optimization
if (info.impl_alpha_size > 16) {
#ifdef DEBUG
u16 total_daddy = 0;
#endif // DEBUG
for (u32 i = 0; i < info.size(); i++) {
find_better_daddy(info, i,
is_cyclic_near(info.raw, info.raw.start_anchored),
grey);
#ifdef DEBUG
total_daddy += info.extra[i].daddytaken;
#endif // DEBUG
}
DEBUG_PRINTF("daddy %hu/%zu states=%zu alpha=%hu\n", total_daddy,
@@ -1172,12 +1176,16 @@ bytecode_ptr<NFA> mcsheng64Compile16(dfa_info&info, dstate_id_t sheng_end,
// Sherman optimization
if (info.impl_alpha_size > 16) {
#ifdef DEBUG
u16 total_daddy = 0;
#endif // DEBUG
for (u32 i = 0; i < info.size(); i++) {
find_better_daddy(info, i,
is_cyclic_near(info.raw, info.raw.start_anchored),
grey);
#ifdef DEBUG
total_daddy += info.extra[i].daddytaken;
#endif // DEBUG
}
DEBUG_PRINTF("daddy %hu/%zu states=%zu alpha=%hu\n", total_daddy,
@@ -1430,11 +1438,9 @@ bytecode_ptr<NFA> mcshengCompile(raw_dfa &raw, const CompileContext &cc,
map<dstate_id_t, AccelScheme> accel_escape_info
= info.strat.getAccelInfo(cc.grey);
auto old_states = info.states;
dstate_id_t sheng_end = find_sheng_states(info, accel_escape_info, MAX_SHENG_STATES);
if (sheng_end <= DEAD_STATE + 1) {
info.states = old_states;
return bytecode_ptr<NFA>(nullptr);
}
@@ -1447,7 +1453,6 @@ bytecode_ptr<NFA> mcshengCompile(raw_dfa &raw, const CompileContext &cc,
}
if (!nfa) {
info.states = old_states;
return nfa;
}

View File

@@ -251,6 +251,10 @@ void q_skip_forward_to(struct mq *q, s64a min_loc) {
// Dump the contents of the given queue.
static never_inline UNUSED
void debugQueue(const struct mq *q) {
if (q == nullptr) {
DEBUG_PRINTF("q=NULL!\n");
return;
}
DEBUG_PRINTF("q=%p, nfa=%p\n", q, q->nfa);
DEBUG_PRINTF("q offset=%llu, buf={%p, len=%zu}, history={%p, len=%zu}\n",
q->offset, q->buffer, q->length, q->history, q->hlength);

View File

@@ -814,7 +814,6 @@ char nfaExecSheng_testEOD(const struct NFA *nfa, const char *state,
char nfaExecSheng_reportCurrent(const struct NFA *n, struct mq *q) {
const struct sheng *sh = (const struct sheng *)getImplNfa(n);
NfaCallback cb = q->cb;
void *ctxt = q->context;
u8 s = *(u8 *)q->state;
const struct sstate_aux *aux = get_aux(sh, s);
u64a offset = q_cur_offset(q);
@@ -823,6 +822,7 @@ char nfaExecSheng_reportCurrent(const struct NFA *n, struct mq *q) {
assert(q_cur_type(q) == MQE_START);
if (aux->accept) {
void *ctxt = q->context;
if (sh->flags & SHENG_FLAG_SINGLE_REPORT) {
fireSingleReport(cb, ctxt, sh->report, offset);
} else {

View File

@@ -800,7 +800,7 @@ bytecode_ptr<NFA> sheng64Compile(raw_dfa &raw, const CompileContext &cc,
old_states = info.states;
auto nfa = shengCompile_int<sheng64>(raw, cc, accel_states, strat, info);
if (!nfa) {
info.states = old_states;
info.states = old_states; // cppcheck-suppress unreadVariable
}
return nfa;
}