Skip to content

Commit

Permalink
Fix #403, patches for older system compatibility
Browse files Browse the repository at this point in the history
Do not assume INTMAX_MAX or UINT64_C macros are available.
Notably, these are absent on VxWorks 6.9,
  • Loading branch information
jphickey committed Aug 16, 2023
1 parent d401933 commit a8d1c29
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 35 deletions.
9 changes: 7 additions & 2 deletions unit-test/cf_codec_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,17 @@ void Test_CF_CFDP_GetValueEncodedSize(void)
UtAssert_UINT32_EQ(CF_CFDP_GetValueEncodedSize(16777216), 4);
UtAssert_UINT32_EQ(CF_CFDP_GetValueEncodedSize(UINT32_MAX), 4);

#ifdef UINT64_C
/*
* This next case uses UINT64_C macro to force promotion so the +1 is done as 64-bit,
* otherwise the UINT32_MAX is a 32-bit value and +1 results in 0.
* otherwise the UINT32_MAX is a 32-bit value and +1 results in 0. Not all systems have
* UINT64_C so these will be skipped in that case.
*/
UtAssert_UINT32_EQ(CF_CFDP_GetValueEncodedSize(UINT32_MAX + UINT64_C(1)), 5);
#endif
#ifdef UINT64_MAX
UtAssert_UINT32_EQ(CF_CFDP_GetValueEncodedSize(UINT64_MAX), 8);
#endif
}

void Test_CF_EncodeIntegerInSize(void)
Expand Down Expand Up @@ -1305,4 +1310,4 @@ void UtTest_Setup(void)

Add_CF_Encode_tests();
Add_CF_Decode_tests();
}
}
32 changes: 0 additions & 32 deletions unit-test/utilities/cf_test_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,38 +448,6 @@ int Any_int_Except(int exception)
return random_val;
}

int Any_int_GreaterThan(int floor) /* NOTE: INTMAX_MAX will fail, and is invalid value */
{
int random_val;
bool coin_toss;

if (floor > 0)
{
random_val = (int)(rand() % (INTMAX_MAX - floor - 1)); /* -1 for greater than */

random_val += floor + 1;
}
else
{
coin_toss = rand() % 2;

if (coin_toss == HEADS)
{
random_val = (int)(rand() % (-floor)); /* floor is negative, -floor inverts to positive */
/* 0 to INTMAX_MAX becomes -1 to INTMAX_MIN */
random_val *= -1; /* flip sign */
random_val += -1; /* subtract 1, 0 becomes -1 */
}
else
{
random_val = (int)(rand() % (INTMAX_MAX)); /* floor is negative, random will be positive so any positive (or
zero) will work */
}
}

return random_val;
}

int Any_int_Negative(void)
{
return ((rand() % MAX_INT) * -1) - 1; /* *-1 flips sign, -1 for 0 and MIN_INT */
Expand Down
1 change: 0 additions & 1 deletion unit-test/utilities/cf_test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ uint64 Any_uint64_Except(uint64 exception);
unsigned int Any_unsigned_int(void);
int Any_int(void);
int Any_int_Except(int exception);
int Any_int_GreaterThan(int floor);
int Any_int_Negative(void);
int Any_int_Positive(void);
int Any_int_PositiveExcept(int exception);
Expand Down

0 comments on commit a8d1c29

Please sign in to comment.