app-layer: minor code cleanups suggested by cppcheck

pull/7392/head
Victor Julien 3 years ago
parent 4403e7fe8e
commit a5df176956

@ -272,12 +272,9 @@ int AppLayerParserSetup(void)
void AppLayerParserPostStreamSetup(void) void AppLayerParserPostStreamSetup(void)
{ {
AppProto alproto = 0;
int flow_proto = 0;
/* lets set a default value for stream_depth */ /* lets set a default value for stream_depth */
for (flow_proto = 0; flow_proto < FLOW_PROTO_DEFAULT; flow_proto++) { for (int flow_proto = 0; flow_proto < FLOW_PROTO_DEFAULT; flow_proto++) {
for (alproto = 0; alproto < ALPROTO_MAX; alproto++) { for (AppProto alproto = 0; alproto < ALPROTO_MAX; alproto++) {
if (!(alp_ctx.ctxs[flow_proto][alproto].internal_flags & if (!(alp_ctx.ctxs[flow_proto][alproto].internal_flags &
APP_LAYER_PARSER_INT_STREAM_DEPTH_SET)) { APP_LAYER_PARSER_INT_STREAM_DEPTH_SET)) {
alp_ctx.ctxs[flow_proto][alproto].stream_depth = alp_ctx.ctxs[flow_proto][alproto].stream_depth =
@ -301,17 +298,12 @@ AppLayerParserThreadCtx *AppLayerParserThreadCtxAlloc(void)
{ {
SCEnter(); SCEnter();
AppProto alproto = 0; AppLayerParserThreadCtx *tctx = SCCalloc(1, sizeof(*tctx));
uint8_t flow_proto = 0;
AppLayerParserThreadCtx *tctx;
tctx = SCMalloc(sizeof(*tctx));
if (tctx == NULL) if (tctx == NULL)
goto end; goto end;
memset(tctx, 0, sizeof(*tctx));
for (flow_proto = 0; flow_proto < FLOW_PROTO_DEFAULT; flow_proto++) { for (uint8_t flow_proto = 0; flow_proto < FLOW_PROTO_DEFAULT; flow_proto++) {
for (alproto = 0; alproto < ALPROTO_MAX; alproto++) { for (AppProto alproto = 0; alproto < ALPROTO_MAX; alproto++) {
uint8_t ipproto = FlowGetReverseProtoMapping(flow_proto); uint8_t ipproto = FlowGetReverseProtoMapping(flow_proto);
tctx->alproto_local_storage[flow_proto][alproto] = tctx->alproto_local_storage[flow_proto][alproto] =
@ -327,11 +319,8 @@ void AppLayerParserThreadCtxFree(AppLayerParserThreadCtx *tctx)
{ {
SCEnter(); SCEnter();
AppProto alproto = 0; for (uint8_t flow_proto = 0; flow_proto < FLOW_PROTO_DEFAULT; flow_proto++) {
uint8_t flow_proto = 0; for (AppProto alproto = 0; alproto < ALPROTO_MAX; alproto++) {
for (flow_proto = 0; flow_proto < FLOW_PROTO_DEFAULT; flow_proto++) {
for (alproto = 0; alproto < ALPROTO_MAX; alproto++) {
uint8_t ipproto = FlowGetReverseProtoMapping(flow_proto); uint8_t ipproto = FlowGetReverseProtoMapping(flow_proto);
AppLayerParserDestroyProtocolParserLocalStorage(ipproto, alproto, AppLayerParserDestroyProtocolParserLocalStorage(ipproto, alproto,
@ -739,7 +728,7 @@ uint64_t AppLayerParserGetTransactionInspectId(AppLayerParserState *pstate, uint
if (pstate == NULL) if (pstate == NULL)
SCReturnCT(0ULL, "uint64_t"); SCReturnCT(0ULL, "uint64_t");
SCReturnCT(pstate->inspect_id[direction & STREAM_TOSERVER ? 0 : 1], "uint64_t"); SCReturnCT(pstate->inspect_id[(direction & STREAM_TOSERVER) ? 0 : 1], "uint64_t");
} }
static inline uint64_t GetTxDetectFlags(AppLayerTxData *txd, const uint8_t dir) static inline uint64_t GetTxDetectFlags(AppLayerTxData *txd, const uint8_t dir)
@ -1172,7 +1161,7 @@ uint64_t AppLayerParserGetTransactionActive(const Flow *f,
uint64_t active_id; uint64_t active_id;
uint64_t log_id = pstate->log_id; uint64_t log_id = pstate->log_id;
uint64_t inspect_id = pstate->inspect_id[direction & STREAM_TOSERVER ? 0 : 1]; uint64_t inspect_id = pstate->inspect_id[(direction & STREAM_TOSERVER) ? 0 : 1];
if (alp_ctx.ctxs[f->protomap][f->alproto].logger == true) { if (alp_ctx.ctxs[f->protomap][f->alproto].logger == true) {
active_id = MIN(log_id, inspect_id); active_id = MIN(log_id, inspect_id);
} else { } else {

@ -308,9 +308,8 @@ failure:
return; return;
} }
static int TCPProtoDetectTriggerOpposingSide(ThreadVars *tv, static int TCPProtoDetectTriggerOpposingSide(ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx,
TcpReassemblyThreadCtx *ra_ctx, Packet *p, TcpSession *ssn, const TcpStream *stream)
Packet *p, TcpSession *ssn, TcpStream *stream)
{ {
TcpStream *opposing_stream = NULL; TcpStream *opposing_stream = NULL;
if (stream == &ssn->client) { if (stream == &ssn->client) {
@ -985,7 +984,7 @@ void AppLayerRegisterGlobalCounters(void)
#define IPPROTOS_MAX 2 #define IPPROTOS_MAX 2
void AppLayerSetupCounters() void AppLayerSetupCounters()
{ {
uint8_t ipprotos[] = { IPPROTO_TCP, IPPROTO_UDP }; const uint8_t ipprotos[] = { IPPROTO_TCP, IPPROTO_UDP };
AppProto alprotos[ALPROTO_MAX]; AppProto alprotos[ALPROTO_MAX];
const char *str = "app_layer.flow."; const char *str = "app_layer.flow.";
const char *estr = "app_layer.error."; const char *estr = "app_layer.error.";
@ -1065,7 +1064,7 @@ void AppLayerSetupCounters()
void AppLayerRegisterThreadCounters(ThreadVars *tv) void AppLayerRegisterThreadCounters(ThreadVars *tv)
{ {
uint8_t ipprotos[] = { IPPROTO_TCP, IPPROTO_UDP }; const uint8_t ipprotos[] = { IPPROTO_TCP, IPPROTO_UDP };
AppProto alprotos[ALPROTO_MAX]; AppProto alprotos[ALPROTO_MAX];
AppLayerProtoDetectSupportedAppProtocols(alprotos); AppLayerProtoDetectSupportedAppProtocols(alprotos);

Loading…
Cancel
Save