Skip to content

Commit

Permalink
util: fix int warnings in unit tests
Browse files Browse the repository at this point in the history
Ticket: 4516
  • Loading branch information
catenacyber committed Jan 14, 2022
1 parent fa3b2ee commit 1057399
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 164 deletions.
72 changes: 36 additions & 36 deletions src/util-action.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -497,8 +497,8 @@ static int UtilActionTest08(void)
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;
Expand Down Expand Up @@ -573,10 +573,10 @@ static int UtilActionTest09(void)
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",
Expand Down Expand Up @@ -640,10 +640,10 @@ static int UtilActionTest10(void)
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;
Expand Down Expand Up @@ -718,8 +718,8 @@ static int UtilActionTest11(void)
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",
Expand Down Expand Up @@ -781,8 +781,8 @@ static int UtilActionTest12(void)
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;
Expand Down Expand Up @@ -856,8 +856,8 @@ static int UtilActionTest13(void)
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;
Expand Down Expand Up @@ -930,8 +930,8 @@ static int UtilActionTest14(void)
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,
Expand Down Expand Up @@ -994,8 +994,8 @@ static int UtilActionTest15(void)
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,
Expand Down Expand Up @@ -1058,8 +1058,8 @@ static int UtilActionTest16(void)
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,
Expand Down Expand Up @@ -1122,8 +1122,8 @@ static int UtilActionTest17(void)
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;
Expand Down Expand Up @@ -1197,8 +1197,8 @@ static int UtilActionTest18(void)
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;
Expand Down Expand Up @@ -1272,8 +1272,8 @@ static int UtilActionTest19(void)
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;
Expand Down Expand Up @@ -1341,8 +1341,8 @@ static int UtilActionTest20(void)
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;
Expand Down Expand Up @@ -1416,8 +1416,8 @@ static int UtilActionTest21(void)
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;
Expand Down Expand Up @@ -1491,8 +1491,8 @@ static int UtilActionTest22(void)
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;
Expand Down
40 changes: 20 additions & 20 deletions src/util-byte.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
10 changes: 5 additions & 5 deletions src/util-macset.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down
Loading

0 comments on commit 1057399

Please sign in to comment.