Skip to content

Commit af7724e

Browse files
Ron EldorRon Eldor
authored andcommitted
Fix endianity issue when reading uint32
The uint32 is given as a bigendian stream, in the tests, however, the char buffer that collected the stream read it as is, without converting it. Add a temporary buffer, to call `greentea_getc()` 8 times, and then put it in the correct endianity for input to `unhexify()`.
1 parent 635888b commit af7724e

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

tests/suites/target_test.function

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ uint8_t receive_byte()
7575
c[1] = greentea_getc();
7676
c[2] = '\0';
7777

78-
assert( unhexify( &byte, c ) != 2 );
78+
TEST_HELPER_ASSERT( unhexify( &byte, c ) != 2 );
7979
return( byte );
8080
}
8181

@@ -90,18 +90,19 @@ uint8_t receive_byte()
9090
uint32_t receive_uint32()
9191
{
9292
uint32_t value;
93-
const uint8_t c[9] = { greentea_getc(),
94-
greentea_getc(),
95-
greentea_getc(),
96-
greentea_getc(),
97-
greentea_getc(),
98-
greentea_getc(),
99-
greentea_getc(),
100-
greentea_getc(),
101-
'\0'
102-
};
103-
assert( unhexify( &value, c ) != 8 );
104-
return( (uint32_t)value );
93+
uint8_t c_be[8] = { greentea_getc(),
94+
greentea_getc(),
95+
greentea_getc(),
96+
greentea_getc(),
97+
greentea_getc(),
98+
greentea_getc(),
99+
greentea_getc(),
100+
greentea_getc()
101+
};
102+
const uint8_t c[9] = { c_be[6], c_be[7], c_be[4], c_be[5], c_be[2],
103+
c_be[3], c_be[0], c_be[1], '\0' };
104+
TEST_HELPER_ASSERT( unhexify( (uint8_t*)&value, c ) != 8 );
105+
return( value );
105106
}
106107

107108
/**

0 commit comments

Comments
 (0)