Skip to content

Commit 5df892e

Browse files
authored
Merge pull request #404 from jphickey/fix-403-intmax
Fix #403, patches for older system compatibility
2 parents d401933 + a8d1c29 commit 5df892e

File tree

3 files changed

+7
-35
lines changed

3 files changed

+7
-35
lines changed

unit-test/cf_codec_tests.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,17 @@ void Test_CF_CFDP_GetValueEncodedSize(void)
5454
UtAssert_UINT32_EQ(CF_CFDP_GetValueEncodedSize(16777216), 4);
5555
UtAssert_UINT32_EQ(CF_CFDP_GetValueEncodedSize(UINT32_MAX), 4);
5656

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

6570
void Test_CF_EncodeIntegerInSize(void)
@@ -1305,4 +1310,4 @@ void UtTest_Setup(void)
13051310

13061311
Add_CF_Encode_tests();
13071312
Add_CF_Decode_tests();
1308-
}
1313+
}

unit-test/utilities/cf_test_utils.c

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -448,38 +448,6 @@ int Any_int_Except(int exception)
448448
return random_val;
449449
}
450450

451-
int Any_int_GreaterThan(int floor) /* NOTE: INTMAX_MAX will fail, and is invalid value */
452-
{
453-
int random_val;
454-
bool coin_toss;
455-
456-
if (floor > 0)
457-
{
458-
random_val = (int)(rand() % (INTMAX_MAX - floor - 1)); /* -1 for greater than */
459-
460-
random_val += floor + 1;
461-
}
462-
else
463-
{
464-
coin_toss = rand() % 2;
465-
466-
if (coin_toss == HEADS)
467-
{
468-
random_val = (int)(rand() % (-floor)); /* floor is negative, -floor inverts to positive */
469-
/* 0 to INTMAX_MAX becomes -1 to INTMAX_MIN */
470-
random_val *= -1; /* flip sign */
471-
random_val += -1; /* subtract 1, 0 becomes -1 */
472-
}
473-
else
474-
{
475-
random_val = (int)(rand() % (INTMAX_MAX)); /* floor is negative, random will be positive so any positive (or
476-
zero) will work */
477-
}
478-
}
479-
480-
return random_val;
481-
}
482-
483451
int Any_int_Negative(void)
484452
{
485453
return ((rand() % MAX_INT) * -1) - 1; /* *-1 flips sign, -1 for 0 and MIN_INT */

unit-test/utilities/cf_test_utils.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ uint64 Any_uint64_Except(uint64 exception);
261261
unsigned int Any_unsigned_int(void);
262262
int Any_int(void);
263263
int Any_int_Except(int exception);
264-
int Any_int_GreaterThan(int floor);
265264
int Any_int_Negative(void);
266265
int Any_int_Positive(void);
267266
int Any_int_PositiveExcept(int exception);

0 commit comments

Comments
 (0)