From: Philippe Antoine Date: Fri, 14 Jan 2022 12:15:57 +0000 (+0100) Subject: util: fix int warnings in unit tests X-Git-Tag: suricata-7.0.0-beta1~825 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1bb51d114c1f252cfb275f214407232d4c6e49f8;p=thirdparty%2Fsuricata.git util: fix int warnings in unit tests Ticket: 4516 --- diff --git a/src/util-action.c b/src/util-action.c index 769135a027..063aa651a8 100644 --- a/src/util-action.c +++ b/src/util-action.c @@ -432,8 +432,8 @@ action-order:\n\ static int UtilActionTest08(void) { int res = 0; - uint8_t *buf = (uint8_t *)"Hi all!"; - uint16_t buflen = strlen((char *)buf); + uint8_t buf[] = "Hi all!"; + uint16_t buflen = sizeof(buf) - 1; Packet *p[3]; p[0] = UTHBuildPacketReal((uint8_t *)buf, buflen, IPPROTO_TCP, "192.168.1.5", "192.168.1.1", @@ -497,8 +497,8 @@ end: static int UtilActionTest09(void) { int res = 1; - uint8_t *buf = (uint8_t *)"Hi all!"; - uint16_t buflen = strlen((char *)buf); + uint8_t buf[] = "Hi all!"; + uint16_t buflen = sizeof(buf) - 1; Packet *p[3]; action_order_sigs[0] = ACTION_DROP; @@ -573,10 +573,10 @@ end: static int UtilActionTest10(void) { int res = 0; - uint8_t *buf = (uint8_t *)"Hi all!"; - uint16_t buflen = strlen((char *)buf); - uint8_t *buf2 = (uint8_t *)"wo!"; - uint16_t buflen2 = strlen((char *)buf2); + uint8_t buf[] = "Hi all!"; + uint16_t buflen = sizeof(buf) - 1; + uint8_t buf2[] = "wo!"; + uint16_t buflen2 = sizeof(buf2) - 1; Packet *p[3]; p[0] = UTHBuildPacketReal((uint8_t *)buf, buflen, IPPROTO_TCP, "192.168.1.5", "192.168.1.1", @@ -640,10 +640,10 @@ end: static int UtilActionTest11(void) { int res = 1; - uint8_t *buf = (uint8_t *)"Hi all!"; - uint16_t buflen = strlen((char *)buf); - uint8_t *buf2 = (uint8_t *)"Hi all wo!"; - uint16_t buflen2 = strlen((char *)buf2); + uint8_t buf[] = "Hi all!"; + uint16_t buflen = sizeof(buf) - 1; + uint8_t buf2[] = "Hi all wo!"; + uint16_t buflen2 = sizeof(buf2) - 1; Packet *p[3]; action_order_sigs[0] = ACTION_DROP; @@ -718,8 +718,8 @@ end: static int UtilActionTest12(void) { int res = 0; - uint8_t *buf = (uint8_t *)"Hi all!"; - uint16_t buflen = strlen((char *)buf); + uint8_t buf[] = "Hi all!"; + uint16_t buflen = sizeof(buf) - 1; Packet *p[3]; p[0] = UTHBuildPacketReal((uint8_t *)buf, buflen, IPPROTO_TCP, "192.168.1.5", "192.168.1.1", @@ -781,8 +781,8 @@ end: static int UtilActionTest13(void) { int res = 1; - uint8_t *buf = (uint8_t *)"Hi all!"; - uint16_t buflen = strlen((char *)buf); + uint8_t buf[] = "Hi all!"; + uint16_t buflen = sizeof(buf) - 1; Packet *p[3]; action_order_sigs[0] = ACTION_DROP; @@ -856,8 +856,8 @@ end: static int UtilActionTest14(void) { int res = 1; - uint8_t *buf = (uint8_t *)"Hi all!"; - uint16_t buflen = strlen((char *)buf); + uint8_t buf[] = "Hi all!"; + uint16_t buflen = sizeof(buf) - 1; Packet *p[3]; action_order_sigs[0] = ACTION_DROP; @@ -930,8 +930,8 @@ end: static int UtilActionTest15(void) { int res = 1; - uint8_t *buf = (uint8_t *)"Hi all!"; - uint16_t buflen = strlen((char *)buf); + uint8_t buf[] = "Hi all!"; + uint16_t buflen = sizeof(buf) - 1; Packet *p[3]; p[0] = UTHBuildPacketReal((uint8_t *)buf, buflen, IPPROTO_TCP, @@ -994,8 +994,8 @@ end: static int UtilActionTest16(void) { int res = 1; - uint8_t *buf = (uint8_t *)"Hi all!"; - uint16_t buflen = strlen((char *)buf); + uint8_t buf[] = "Hi all!"; + uint16_t buflen = sizeof(buf) - 1; Packet *p[3]; p[0] = UTHBuildPacketReal((uint8_t *)buf, buflen, IPPROTO_TCP, @@ -1058,8 +1058,8 @@ end: static int UtilActionTest17(void) { int res = 1; - uint8_t *buf = (uint8_t *)"Hi all!"; - uint16_t buflen = strlen((char *)buf); + uint8_t buf[] = "Hi all!"; + uint16_t buflen = sizeof(buf) - 1; Packet *p[3]; p[0] = UTHBuildPacketReal((uint8_t *)buf, buflen, IPPROTO_TCP, @@ -1122,8 +1122,8 @@ end: static int UtilActionTest18(void) { int res = 1; - uint8_t *buf = (uint8_t *)"Hi all!"; - uint16_t buflen = strlen((char *)buf); + uint8_t buf[] = "Hi all!"; + uint16_t buflen = sizeof(buf) - 1; Packet *p[3]; action_order_sigs[0] = ACTION_DROP; @@ -1197,8 +1197,8 @@ end: static int UtilActionTest19(void) { int res = 1; - uint8_t *buf = (uint8_t *)"Hi all!"; - uint16_t buflen = strlen((char *)buf); + uint8_t buf[] = "Hi all!"; + uint16_t buflen = sizeof(buf) - 1; Packet *p[3]; action_order_sigs[0] = ACTION_DROP; @@ -1272,8 +1272,8 @@ end: static int UtilActionTest20(void) { int res = 1; - uint8_t *buf = (uint8_t *)"Hi all!"; - uint16_t buflen = strlen((char *)buf); + uint8_t buf[] = "Hi all!"; + uint16_t buflen = sizeof(buf) - 1; Packet *p[3]; action_order_sigs[0] = ACTION_DROP; @@ -1341,8 +1341,8 @@ end: static int UtilActionTest21(void) { int res = 1; - uint8_t *buf = (uint8_t *)"Hi all!"; - uint16_t buflen = strlen((char *)buf); + uint8_t buf[] = "Hi all!"; + uint16_t buflen = sizeof(buf) - 1; Packet *p[3]; action_order_sigs[0] = ACTION_DROP; @@ -1416,8 +1416,8 @@ end: static int UtilActionTest22(void) { int res = 1; - uint8_t *buf = (uint8_t *)"Hi all!"; - uint16_t buflen = strlen((char *)buf); + uint8_t buf[] = "Hi all!"; + uint16_t buflen = sizeof(buf) - 1; Packet *p[3]; action_order_sigs[0] = ACTION_DROP; @@ -1491,8 +1491,8 @@ end: static int UtilActionTest23(void) { int res = 1; - uint8_t *buf = (uint8_t *)"Hi all!"; - uint16_t buflen = strlen((char *)buf); + uint8_t buf[] = "Hi all!"; + uint16_t buflen = sizeof(buf) - 1; Packet *p[3]; action_order_sigs[0] = ACTION_DROP; diff --git a/src/util-byte.c b/src/util-byte.c index 4de066c8d3..2676607666 100644 --- a/src/util-byte.c +++ b/src/util-byte.c @@ -877,10 +877,10 @@ static int ByteTest06 (void) static int ByteTest07 (void) { - const char *str = "1234567890"; + const char str[] = "1234567890"; uint64_t val = 1234567890; uint64_t i64 = 0xbfbfbfbfbfbfbfbfULL; - int ret = ByteExtractStringUint64(&i64, 10, strlen(str), str); + int ret = ByteExtractStringUint64(&i64, 10, sizeof(str) - 1, str); if ((ret == 10) && (i64 == val)) { return 1; @@ -891,10 +891,10 @@ static int ByteTest07 (void) static int ByteTest08 (void) { - const char *str = "1234567890"; + const char str[] = "1234567890"; uint32_t val = 1234567890; uint32_t i32 = 0xbfbfbfbf; - int ret = ByteExtractStringUint32(&i32, 10, strlen(str), str); + int ret = ByteExtractStringUint32(&i32, 10, sizeof(str) - 1, str); if ((ret == 10) && (i32 == val)) { return 1; @@ -905,10 +905,10 @@ static int ByteTest08 (void) static int ByteTest09 (void) { - const char *str = "12345"; + const char str[] = "12345"; uint16_t val = 12345; uint16_t i16 = 0xbfbf; - int ret = ByteExtractStringUint16(&i16, 10, strlen(str), str); + int ret = ByteExtractStringUint16(&i16, 10, sizeof(str) - 1, str); if ((ret == 5) && (i16 == val)) { return 1; @@ -919,10 +919,10 @@ static int ByteTest09 (void) static int ByteTest10 (void) { - const char *str = "123"; + const char str[] = "123"; uint8_t val = 123; uint8_t i8 = 0xbf; - int ret = ByteExtractStringUint8(&i8, 10, strlen(str), str); + int ret = ByteExtractStringUint8(&i8, 10, sizeof(str) - 1, str); if ((ret == 3) && (i8 == val)) { return 1; @@ -933,10 +933,10 @@ static int ByteTest10 (void) static int ByteTest11 (void) { - const char *str = "-1234567890"; + const char str[] = "-1234567890"; int64_t val = -1234567890; int64_t i64 = 0xbfbfbfbfbfbfbfbfULL; - int ret = ByteExtractStringInt64(&i64, 10, strlen(str), str); + int ret = ByteExtractStringInt64(&i64, 10, sizeof(str) - 1, str); if ((ret == 11) && (i64 == val)) { return 1; @@ -947,10 +947,10 @@ static int ByteTest11 (void) static int ByteTest12 (void) { - const char *str = "-1234567890"; + const char str[] = "-1234567890"; int32_t val = -1234567890; int32_t i32 = 0xbfbfbfbf; - int ret = ByteExtractStringInt32(&i32, 10, strlen(str), str); + int ret = ByteExtractStringInt32(&i32, 10, sizeof(str) - 1, str); if ((ret == 11) && (i32 == val)) { return 1; @@ -961,10 +961,10 @@ static int ByteTest12 (void) static int ByteTest13 (void) { - const char *str = "-12345"; + const char str[] = "-12345"; int16_t val = -12345; int16_t i16 = 0xbfbf; - int ret = ByteExtractStringInt16(&i16, 10, strlen(str), str); + int ret = ByteExtractStringInt16(&i16, 10, sizeof(str) - 1, str); if ((ret == 6) && (i16 == val)) { return 1; @@ -975,10 +975,10 @@ static int ByteTest13 (void) static int ByteTest14 (void) { - const char *str = "-123"; + const char str[] = "-123"; int8_t val = -123; int8_t i8 = 0xbf; - int ret = ByteExtractStringInt8(&i8, 10, strlen(str), str); + int ret = ByteExtractStringInt8(&i8, 10, sizeof(str) - 1, str); if ((ret == 4) && (i8 == val)) { return 1; @@ -990,11 +990,11 @@ static int ByteTest14 (void) /** \test max u32 value */ static int ByteTest15 (void) { - const char *str = "4294967295"; + const char str[] = "4294967295"; uint32_t val = 4294967295UL; uint32_t u32 = 0xffffffff; - int ret = ByteExtractStringUint32(&u32, 10, strlen(str), str); + int ret = ByteExtractStringUint32(&u32, 10, sizeof(str) - 1, str); if ((ret == 10) && (u32 == val)) { return 1; } @@ -1005,10 +1005,10 @@ static int ByteTest15 (void) /** \test max u32 value + 1 */ static int ByteTest16 (void) { - const char *str = "4294967296"; + const char str[] = "4294967296"; uint32_t u32 = 0; - int ret = ByteExtractStringUint32(&u32, 10, strlen(str), str); + int ret = ByteExtractStringUint32(&u32, 10, sizeof(str) - 1, str); if (ret != 0) { return 1; } diff --git a/src/util-macset.c b/src/util-macset.c index d169711fea..0896e907cd 100644 --- a/src/util-macset.c +++ b/src/util-macset.c @@ -375,14 +375,13 @@ static int MacSetTest02(void) static int MacSetTest03(void) { MacSet *ms = NULL; - int i = 0; SC_ATOMIC_SET(flow_config.memcap, 10000); ms = MacSetInit(10); FAIL_IF_NULL(ms); FAIL_IF_NOT(MacSetSize(ms) == 0); - for (i = 1; i < 100; i++) { + for (uint8_t i = 1; i < 100; i++) { MacAddr addr1 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x1}, addr2 = {0x1, 0x0, 0x0, 0x0, 0x0, 0x1}; addr1[5] = i; @@ -409,14 +408,14 @@ static int MacSetTest04(void) static int MacSetTest05(void) { MacSet *ms = NULL; - int ret = 0, i = 0; + int ret = 0; SC_ATOMIC_SET(flow_config.memcap, 64); ms = MacSetInit(10); FAIL_IF_NULL(ms); FAIL_IF_NOT(MacSetSize(ms) == 0); - for (i = 1; i < 100; i++) { + for (uint8_t i = 1; i < 100; i++) { MacAddr addr1 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x1}, addr2 = {0x1, 0x0, 0x0, 0x0, 0x0, 0x1}; addr1[5] = i; @@ -425,7 +424,8 @@ static int MacSetTest05(void) } FAIL_IF_NOT(MacSetSize(ms) == 2); - ret = MacSetForEach(ms, CheckTest1Membership, &i); + int i2 = 100; + ret = MacSetForEach(ms, CheckTest1Membership, &i2); FAIL_IF_NOT(ret == 0); MacSetFree(ms); diff --git a/src/util-mpm-ac-bs.c b/src/util-mpm-ac-bs.c index a507ec6778..3fd35bd440 100644 --- a/src/util-mpm-ac-bs.c +++ b/src/util-mpm-ac-bs.c @@ -1850,8 +1850,8 @@ static int SCACBSTest13(void) SCACBSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx); /* 1 match */ - const char *pat = "abcdefghijklmnopqrstuvwxyzABCD"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "abcdefghijklmnopqrstuvwxyzABCD"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCACBSPreparePatterns(&mpm_ctx); @@ -1884,8 +1884,8 @@ static int SCACBSTest14(void) SCACBSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx); /* 1 match */ - const char *pat = "abcdefghijklmnopqrstuvwxyzABCDE"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "abcdefghijklmnopqrstuvwxyzABCDE"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCACBSPreparePatterns(&mpm_ctx); @@ -1918,8 +1918,8 @@ static int SCACBSTest15(void) SCACBSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx); /* 1 match */ - const char *pat = "abcdefghijklmnopqrstuvwxyzABCDEF"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "abcdefghijklmnopqrstuvwxyzABCDEF"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCACBSPreparePatterns(&mpm_ctx); @@ -1952,8 +1952,8 @@ static int SCACBSTest16(void) SCACBSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx); /* 1 match */ - const char *pat = "abcdefghijklmnopqrstuvwxyzABC"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "abcdefghijklmnopqrstuvwxyzABC"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCACBSPreparePatterns(&mpm_ctx); @@ -1986,8 +1986,8 @@ static int SCACBSTest17(void) SCACBSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx); /* 1 match */ - const char *pat = "abcdefghijklmnopqrstuvwxyzAB"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "abcdefghijklmnopqrstuvwxyzAB"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCACBSPreparePatterns(&mpm_ctx); @@ -2020,8 +2020,13 @@ static int SCACBSTest18(void) SCACBSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx); /* 1 match */ - const char *pat = "abcde""fghij""klmno""pqrst""uvwxy""z"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "abcde" + "fghij" + "klmno" + "pqrst" + "uvwxy" + "z"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCACBSPreparePatterns(&mpm_ctx); @@ -2054,8 +2059,8 @@ static int SCACBSTest19(void) SCACBSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx); /* 1 */ - const char *pat = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCACBSPreparePatterns(&mpm_ctx); @@ -2087,8 +2092,14 @@ static int SCACBSTest20(void) SCACBSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx); /* 1 */ - const char *pat = "AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AA"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "AAAAA" + "AAAAA" + "AAAAA" + "AAAAA" + "AAAAA" + "AAAAA" + "AA"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCACBSPreparePatterns(&mpm_ctx); @@ -2409,8 +2420,8 @@ static int SCACBSTest29(void) static int SCACBSTest30(void) { - uint8_t *buf = (uint8_t *)"onetwothreefourfivesixseveneightnine"; - uint16_t buflen = strlen((char *)buf); + uint8_t buf[] = "onetwothreefourfivesixseveneightnine"; + uint16_t buflen = sizeof(buf) - 1; Packet *p = NULL; ThreadVars th_v; DetectEngineThreadCtx *det_ctx = NULL; diff --git a/src/util-mpm-ac-ks.c b/src/util-mpm-ac-ks.c index 3f7153d17a..1e487d28f8 100644 --- a/src/util-mpm-ac-ks.c +++ b/src/util-mpm-ac-ks.c @@ -1925,8 +1925,8 @@ static int SCACTileTest13(void) SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx); /* 1 match */ - const char *pat = "abcdefghijklmnopqrstuvwxyzABCD"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "abcdefghijklmnopqrstuvwxyzABCD"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCACTilePreparePatterns(&mpm_ctx); @@ -1959,8 +1959,8 @@ static int SCACTileTest14(void) SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx); /* 1 match */ - const char *pat = "abcdefghijklmnopqrstuvwxyzABCDE"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "abcdefghijklmnopqrstuvwxyzABCDE"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCACTilePreparePatterns(&mpm_ctx); @@ -1993,8 +1993,8 @@ static int SCACTileTest15(void) SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx); /* 1 match */ - const char *pat = "abcdefghijklmnopqrstuvwxyzABCDEF"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "abcdefghijklmnopqrstuvwxyzABCDEF"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCACTilePreparePatterns(&mpm_ctx); @@ -2027,8 +2027,8 @@ static int SCACTileTest16(void) SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx); /* 1 match */ - const char *pat = "abcdefghijklmnopqrstuvwxyzABC"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "abcdefghijklmnopqrstuvwxyzABC"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCACTilePreparePatterns(&mpm_ctx); @@ -2061,8 +2061,8 @@ static int SCACTileTest17(void) SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx); /* 1 match */ - const char *pat = "abcdefghijklmnopqrstuvwxyzAB"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "abcdefghijklmnopqrstuvwxyzAB"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCACTilePreparePatterns(&mpm_ctx); @@ -2095,8 +2095,13 @@ static int SCACTileTest18(void) SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx); /* 1 match */ - const char *pat = "abcde""fghij""klmno""pqrst""uvwxy""z"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "abcde" + "fghij" + "klmno" + "pqrst" + "uvwxy" + "z"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCACTilePreparePatterns(&mpm_ctx); @@ -2129,8 +2134,8 @@ static int SCACTileTest19(void) SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx); /* 1 */ - const char *pat = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCACTilePreparePatterns(&mpm_ctx); @@ -2163,8 +2168,14 @@ static int SCACTileTest20(void) SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx); /* 1 */ - const char *pat = "AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AA"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "AAAAA" + "AAAAA" + "AAAAA" + "AAAAA" + "AAAAA" + "AAAAA" + "AA"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCACTilePreparePatterns(&mpm_ctx); @@ -2450,8 +2461,8 @@ static int SCACTileTest28(void) static int SCACTileTest29(void) { - uint8_t *buf = (uint8_t *)"onetwothreefourfivesixseveneightnine"; - uint16_t buflen = strlen((char *)buf); + uint8_t buf[] = "onetwothreefourfivesixseveneightnine"; + uint16_t buflen = sizeof(buf) - 1; Packet *p = NULL; ThreadVars th_v; DetectEngineThreadCtx *det_ctx = NULL; diff --git a/src/util-mpm-ac.c b/src/util-mpm-ac.c index 84129d4b26..c6f5f9b0d4 100644 --- a/src/util-mpm-ac.c +++ b/src/util-mpm-ac.c @@ -1696,8 +1696,8 @@ static int SCACTest13(void) SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx); /* 1 match */ - const char *pat = "abcdefghijklmnopqrstuvwxyzABCD"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "abcdefghijklmnopqrstuvwxyzABCD"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCACPreparePatterns(&mpm_ctx); @@ -1730,8 +1730,8 @@ static int SCACTest14(void) SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx); /* 1 match */ - const char *pat = "abcdefghijklmnopqrstuvwxyzABCDE"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "abcdefghijklmnopqrstuvwxyzABCDE"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCACPreparePatterns(&mpm_ctx); @@ -1764,8 +1764,8 @@ static int SCACTest15(void) SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx); /* 1 match */ - const char *pat = "abcdefghijklmnopqrstuvwxyzABCDEF"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "abcdefghijklmnopqrstuvwxyzABCDEF"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCACPreparePatterns(&mpm_ctx); @@ -1798,8 +1798,8 @@ static int SCACTest16(void) SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx); /* 1 match */ - const char *pat = "abcdefghijklmnopqrstuvwxyzABC"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "abcdefghijklmnopqrstuvwxyzABC"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCACPreparePatterns(&mpm_ctx); @@ -1832,8 +1832,8 @@ static int SCACTest17(void) SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx); /* 1 match */ - const char *pat = "abcdefghijklmnopqrstuvwxyzAB"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "abcdefghijklmnopqrstuvwxyzAB"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCACPreparePatterns(&mpm_ctx); @@ -1866,8 +1866,13 @@ static int SCACTest18(void) SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx); /* 1 match */ - const char *pat = "abcde""fghij""klmno""pqrst""uvwxy""z"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "abcde" + "fghij" + "klmno" + "pqrst" + "uvwxy" + "z"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCACPreparePatterns(&mpm_ctx); @@ -1900,8 +1905,8 @@ static int SCACTest19(void) SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx); /* 1 */ - const char *pat = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCACPreparePatterns(&mpm_ctx); @@ -1934,8 +1939,14 @@ static int SCACTest20(void) SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx); /* 1 */ - const char *pat = "AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AA"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "AAAAA" + "AAAAA" + "AAAAA" + "AAAAA" + "AAAAA" + "AAAAA" + "AA"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCACPreparePatterns(&mpm_ctx); @@ -2221,8 +2232,8 @@ static int SCACTest28(void) static int SCACTest29(void) { - uint8_t *buf = (uint8_t *)"onetwothreefourfivesixseveneightnine"; - uint16_t buflen = strlen((char *)buf); + uint8_t buf[] = "onetwothreefourfivesixseveneightnine"; + uint16_t buflen = sizeof(buf) - 1; Packet *p = NULL; ThreadVars th_v; DetectEngineThreadCtx *det_ctx = NULL; diff --git a/src/util-mpm-hs.c b/src/util-mpm-hs.c index 9ad204456f..420c091dd1 100644 --- a/src/util-mpm-hs.c +++ b/src/util-mpm-hs.c @@ -1538,8 +1538,8 @@ static int SCHSTest13(void) MpmInitCtx(&mpm_ctx, MPM_HS); /* 1 match */ - const char *pat = "abcdefghijklmnopqrstuvwxyzABCD"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "abcdefghijklmnopqrstuvwxyzABCD"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCHSPreparePatterns(&mpm_ctx); @@ -1572,8 +1572,8 @@ static int SCHSTest14(void) MpmInitCtx(&mpm_ctx, MPM_HS); /* 1 match */ - const char *pat = "abcdefghijklmnopqrstuvwxyzABCDE"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "abcdefghijklmnopqrstuvwxyzABCDE"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCHSPreparePatterns(&mpm_ctx); @@ -1606,8 +1606,8 @@ static int SCHSTest15(void) MpmInitCtx(&mpm_ctx, MPM_HS); /* 1 match */ - const char *pat = "abcdefghijklmnopqrstuvwxyzABCDEF"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "abcdefghijklmnopqrstuvwxyzABCDEF"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCHSPreparePatterns(&mpm_ctx); @@ -1640,8 +1640,8 @@ static int SCHSTest16(void) MpmInitCtx(&mpm_ctx, MPM_HS); /* 1 match */ - const char *pat = "abcdefghijklmnopqrstuvwxyzABC"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "abcdefghijklmnopqrstuvwxyzABC"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCHSPreparePatterns(&mpm_ctx); @@ -1674,8 +1674,8 @@ static int SCHSTest17(void) MpmInitCtx(&mpm_ctx, MPM_HS); /* 1 match */ - const char *pat = "abcdefghijklmnopqrstuvwxyzAB"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "abcdefghijklmnopqrstuvwxyzAB"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCHSPreparePatterns(&mpm_ctx); @@ -1708,13 +1708,13 @@ static int SCHSTest18(void) MpmInitCtx(&mpm_ctx, MPM_HS); /* 1 match */ - const char *pat = "abcde" - "fghij" - "klmno" - "pqrst" - "uvwxy" - "z"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "abcde" + "fghij" + "klmno" + "pqrst" + "uvwxy" + "z"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCHSPreparePatterns(&mpm_ctx); @@ -1752,8 +1752,8 @@ static int SCHSTest19(void) MpmInitCtx(&mpm_ctx, MPM_HS); /* 1 */ - const char *pat = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCHSPreparePatterns(&mpm_ctx); @@ -1786,14 +1786,14 @@ static int SCHSTest20(void) MpmInitCtx(&mpm_ctx, MPM_HS); /* 1 */ - const char *pat = "AAAAA" - "AAAAA" - "AAAAA" - "AAAAA" - "AAAAA" - "AAAAA" - "AA"; - MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0); + const char pat[] = "AAAAA" + "AAAAA" + "AAAAA" + "AAAAA" + "AAAAA" + "AAAAA" + "AA"; + MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, sizeof(pat) - 1, 0, 0, 0, 0, 0); PmqSetup(&pmq); SCHSPreparePatterns(&mpm_ctx); @@ -2086,8 +2086,8 @@ static int SCHSTest28(void) static int SCHSTest29(void) { - uint8_t *buf = (uint8_t *)"onetwothreefourfivesixseveneightnine"; - uint16_t buflen = strlen((char *)buf); + uint8_t buf[] = "onetwothreefourfivesixseveneightnine"; + uint16_t buflen = sizeof(buf) - 1; Packet *p = NULL; ThreadVars th_v; DetectEngineThreadCtx *det_ctx = NULL; diff --git a/src/util-spm-bm.c b/src/util-spm-bm.c index 8bdd347dfe..df6742054f 100644 --- a/src/util-spm-bm.c +++ b/src/util-spm-bm.c @@ -271,7 +271,7 @@ static void PreBmGsNocase(const uint8_t *x, uint16_t m, uint16_t *bmGs) } j = 0; for (i = m; i > 0; --i) { - if (suff[i-1] == i) { + if (suff[i - 1] == i) { for (; j < m - i; ++j) { if (bmGs[j] == m) { bmGs[j] = m - i; diff --git a/src/util-spm.c b/src/util-spm.c index 3d2048e6cb..0652758e70 100644 --- a/src/util-spm.c +++ b/src/util-spm.c @@ -298,7 +298,7 @@ uint8_t *BoyerMooreNocaseSearch(const uint8_t *text, uint32_t textlen, static uint8_t *BasicSearchWrapper(uint8_t *text, uint8_t *needle, int times) { uint32_t textlen = strlen((char *)text); - uint16_t needlelen = strlen((char *)needle); + uint16_t needlelen = (uint16_t)strlen((char *)needle); uint8_t *ret = NULL; int i = 0; @@ -318,7 +318,7 @@ static uint8_t *BasicSearchWrapper(uint8_t *text, uint8_t *needle, int times) static uint8_t *BasicSearchNocaseWrapper(uint8_t *text, uint8_t *needle, int times) { uint32_t textlen = strlen((char *)text); - uint16_t needlelen = strlen((char *)needle); + uint16_t needlelen = (uint16_t)strlen((char *)needle); uint8_t *ret = NULL; int i = 0; @@ -335,7 +335,7 @@ static uint8_t *BasicSearchNocaseWrapper(uint8_t *text, uint8_t *needle, int tim static uint8_t *Bs2bmWrapper(uint8_t *text, uint8_t *needle, int times) { uint32_t textlen = strlen((char *)text); - uint16_t needlelen = strlen((char *)needle); + uint16_t needlelen = (uint16_t)strlen((char *)needle); uint8_t badchars[ALPHABET_SIZE]; Bs2BmBadchars(needle, needlelen, badchars); @@ -355,7 +355,7 @@ static uint8_t *Bs2bmWrapper(uint8_t *text, uint8_t *needle, int times) static uint8_t *Bs2bmNocaseWrapper(uint8_t *text, uint8_t *needle, int times) { uint32_t textlen = strlen((char *)text); - uint16_t needlelen = strlen((char *)needle); + uint16_t needlelen = (uint16_t)strlen((char *)needle); uint8_t badchars[ALPHABET_SIZE]; Bs2BmBadchars(needle, needlelen, badchars); @@ -375,7 +375,7 @@ static uint8_t *Bs2bmNocaseWrapper(uint8_t *text, uint8_t *needle, int times) static uint8_t *BoyerMooreWrapper(uint8_t *text, uint8_t *needle, int times) { uint32_t textlen = strlen((char *)text); - uint16_t needlelen = strlen((char *)needle); + uint16_t needlelen = (uint16_t)strlen((char *)needle); BmCtx *bm_ctx = BoyerMooreCtxInit(needle, needlelen); @@ -395,7 +395,7 @@ static uint8_t *BoyerMooreWrapper(uint8_t *text, uint8_t *needle, int times) static uint8_t *BoyerMooreNocaseWrapper(uint8_t *text, uint8_t *in_needle, int times) { uint32_t textlen = strlen((char *)text); - uint16_t needlelen = strlen((char *)in_needle); + uint16_t needlelen = (uint16_t)strlen((char *)in_needle); /* Make a copy of in_needle to be able to convert it to lowercase. */ uint8_t *needle = SCMalloc(needlelen); @@ -2631,7 +2631,7 @@ static int SpmSearchTest02(void) { uint16_t prefix; for (prefix = 0; prefix < 32; prefix++) { d.needle = needle; - d.needle_len = strlen(needle); + d.needle_len = (uint16_t)strlen(needle); uint16_t haystack_len = prefix + d.needle_len; char *haystack = SCMalloc(haystack_len); if (haystack == NULL) { diff --git a/src/util-unittest-helper.c b/src/util-unittest-helper.c index 7379af66d8..185f1996f6 100644 --- a/src/util-unittest-helper.c +++ b/src/util-unittest-helper.c @@ -656,13 +656,13 @@ int UTHCheckPacketMatchResults(Packet *p, uint32_t sids[], int i = 0; int res = 1; for (; i < numsids; i++) { - uint16_t r = PacketAlertCheck(p, sids[i]); + uint32_t r = PacketAlertCheck(p, sids[i]); if (r != results[i]) { - SCLogInfo("Sid %"PRIu32" matched %"PRIu16" times, and not %"PRIu32 - " as expected", sids[i], r, results[i]); + SCLogInfo("Sid %" PRIu32 " matched %" PRIu32 " times, and not %" PRIu32 " as expected", + sids[i], r, results[i]); res = 0; } else { - SCLogInfo("Sid %"PRIu32" matched %"PRIu16" times, as expected", sids[i], r); + SCLogInfo("Sid %" PRIu32 " matched %" PRIu32 " times, as expected", sids[i], r); } } return res;