Skip to content
This repository was archived by the owner on Apr 13, 2021. It is now read-only.

Commit 9c9fea3

Browse files
author
Dmitry Tatarinov
committed
Update per review
1 parent 8ac9a1c commit 9c9fea3

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/nav_msg_glo.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
#include <libswiftnav/logging.h>
1919
#include <libswiftnav/bits.h>
2020

21+
#ifdef UNIT_TEST
22+
#undef log_error
23+
#define log_error(...)
24+
#endif
25+
2126
/* Word Ft (accuracy of measurements), refer to GLO ICD, Table 4.4 */
2227
const float f_t[] = { 1.0f, 2.0f, 2.5f, 4.0f, 5.0f, 7.0f, 10.0f, 12.0f, 14.0f,
2328
16.0f, 32.0f, 64.0f, 128.0f, 256.0f, 512.0f, -1.0f };
@@ -131,8 +136,15 @@ s8 error_detection_glo(const nav_msg_glo_t *n)
131136
*/
132137
static u32 extract_word_glo(const nav_msg_glo_t *n, u16 bit_index, u8 n_bits)
133138
{
134-
assert(n_bits <= 32 && n_bits > 0);
135-
assert(bit_index <= GLO_STR_LEN && bit_index > 0);
139+
if (bit_index > GLO_STR_LEN || !bit_index) {
140+
log_error("Incorrect bit index %d\n", bit_index);
141+
return 0;
142+
}
143+
144+
if (n_bits > 32 || !n_bits ) {
145+
log_error("Incorrect number of bits to be extracted %d\n", n_bits);
146+
return 0;
147+
}
136148

137149
/* Extract a word of n_bits length (n_bits <= 32) at position bit_index into
138150
* the GLO string.*/

tests/check_glo_decoder.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
1111
*/
1212
//#define DEBUG 1
13+
#define UNIT_TEST
1314

1415
#include <stdio.h>
1516
#include <check.h>
@@ -138,6 +139,11 @@ START_TEST(test_extract_glo_word)
138139
fail_unless(ret == 0x87654321, "9. %x, expected %x", ret, 0x87654321);
139140
ret = extract_word_glo(&n, 49, 16);
140141
fail_unless(ret == 0x4321, "10. %x, expected %x", ret, 0x4321);
142+
143+
fail_unless(extract_word_glo(&n, 0, 1) == 0, "Expected 0");
144+
fail_unless(extract_word_glo(&n, 86, 1) == 0, "Expected 0");
145+
fail_unless(extract_word_glo(&n, 1, 0) == 0, "Expected 0");
146+
fail_unless(extract_word_glo(&n, 1, 33) == 0, "Expected 0");
141147
}
142148
END_TEST
143149

0 commit comments

Comments
 (0)