]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
app-layer: minor code cleanups suggested by cppcheck
authorVictor Julien <vjulien@oisf.net>
Wed, 27 Apr 2022 19:16:05 +0000 (21:16 +0200)
committerVictor Julien <vjulien@oisf.net>
Mon, 9 May 2022 14:06:46 +0000 (16:06 +0200)
src/app-layer-parser.c
src/app-layer.c

index 43accd7217ce2617a5ee66ee1f614421e04b9222..65b574716f18c103f15a64104e25f33a0d3bd5c5 100644 (file)
@@ -272,12 +272,9 @@ int AppLayerParserSetup(void)
 
 void AppLayerParserPostStreamSetup(void)
 {
-    AppProto alproto = 0;
-    int flow_proto = 0;
-
     /* lets set a default value for stream_depth */
-    for (flow_proto = 0; flow_proto < FLOW_PROTO_DEFAULT; flow_proto++) {
-        for (alproto = 0; alproto < ALPROTO_MAX; alproto++) {
+    for (int flow_proto = 0; flow_proto < FLOW_PROTO_DEFAULT; flow_proto++) {
+        for (AppProto alproto = 0; alproto < ALPROTO_MAX; alproto++) {
             if (!(alp_ctx.ctxs[flow_proto][alproto].internal_flags &
                         APP_LAYER_PARSER_INT_STREAM_DEPTH_SET)) {
                 alp_ctx.ctxs[flow_proto][alproto].stream_depth =
@@ -301,17 +298,12 @@ AppLayerParserThreadCtx *AppLayerParserThreadCtxAlloc(void)
 {
     SCEnter();
 
-    AppProto alproto = 0;
-    uint8_t flow_proto = 0;
-    AppLayerParserThreadCtx *tctx;
-
-    tctx = SCMalloc(sizeof(*tctx));
+    AppLayerParserThreadCtx *tctx = SCCalloc(1, sizeof(*tctx));
     if (tctx == NULL)
         goto end;
-    memset(tctx, 0, sizeof(*tctx));
 
-    for (flow_proto = 0; flow_proto < FLOW_PROTO_DEFAULT; flow_proto++) {
-        for (alproto = 0; alproto < ALPROTO_MAX; alproto++) {
+    for (uint8_t flow_proto = 0; flow_proto < FLOW_PROTO_DEFAULT; flow_proto++) {
+        for (AppProto alproto = 0; alproto < ALPROTO_MAX; alproto++) {
             uint8_t ipproto = FlowGetReverseProtoMapping(flow_proto);
 
             tctx->alproto_local_storage[flow_proto][alproto] =
@@ -327,11 +319,8 @@ void AppLayerParserThreadCtxFree(AppLayerParserThreadCtx *tctx)
 {
     SCEnter();
 
-    AppProto alproto = 0;
-    uint8_t flow_proto = 0;
-
-    for (flow_proto = 0; flow_proto < FLOW_PROTO_DEFAULT; flow_proto++) {
-        for (alproto = 0; alproto < ALPROTO_MAX; alproto++) {
+    for (uint8_t flow_proto = 0; flow_proto < FLOW_PROTO_DEFAULT; flow_proto++) {
+        for (AppProto alproto = 0; alproto < ALPROTO_MAX; alproto++) {
             uint8_t ipproto = FlowGetReverseProtoMapping(flow_proto);
 
             AppLayerParserDestroyProtocolParserLocalStorage(ipproto, alproto,
@@ -739,7 +728,7 @@ uint64_t AppLayerParserGetTransactionInspectId(AppLayerParserState *pstate, uint
     if (pstate == NULL)
         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)
@@ -1172,7 +1161,7 @@ uint64_t AppLayerParserGetTransactionActive(const Flow *f,
 
     uint64_t active_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) {
         active_id = MIN(log_id, inspect_id);
     } else {
index f7c55dcf7035da374949bc286453b10a7d59036d..eb4ce8aca40eb14868034a4d754d4227a00ecf3f 100644 (file)
@@ -308,9 +308,8 @@ failure:
     return;
 }
 
-static int TCPProtoDetectTriggerOpposingSide(ThreadVars *tv,
-        TcpReassemblyThreadCtx *ra_ctx,
-        Packet *p, TcpSession *ssn, TcpStream *stream)
+static int TCPProtoDetectTriggerOpposingSide(ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx,
+        Packet *p, TcpSession *ssn, const TcpStream *stream)
 {
     TcpStream *opposing_stream = NULL;
     if (stream == &ssn->client) {
@@ -985,7 +984,7 @@ void AppLayerRegisterGlobalCounters(void)
 #define IPPROTOS_MAX 2
 void AppLayerSetupCounters()
 {
-    uint8_t ipprotos[] = { IPPROTO_TCP, IPPROTO_UDP };
+    const uint8_t ipprotos[] = { IPPROTO_TCP, IPPROTO_UDP };
     AppProto alprotos[ALPROTO_MAX];
     const char *str = "app_layer.flow.";
     const char *estr = "app_layer.error.";
@@ -1065,7 +1064,7 @@ void AppLayerSetupCounters()
 
 void AppLayerRegisterThreadCounters(ThreadVars *tv)
 {
-    uint8_t ipprotos[] = { IPPROTO_TCP, IPPROTO_UDP };
+    const uint8_t ipprotos[] = { IPPROTO_TCP, IPPROTO_UDP };
     AppProto alprotos[ALPROTO_MAX];
     AppLayerProtoDetectSupportedAppProtocols(alprotos);