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

Commit ae65b51

Browse files
author
Pasi Miettinen
committed
Replace asserts with invalid value returning
1 parent 5553330 commit ae65b51

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

include/libswiftnav/time.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,16 @@
7777
#define GPS_EPOCH 315964800
7878

7979
#define WN_UNKNOWN -1
80+
#define TOW_UNKNOWN -1
8081

8182
/** Structure representing a GPS time. */
8283
typedef struct __attribute__((packed)) {
8384
double tow; /**< Seconds since the GPS start of week. */
8485
s16 wn; /**< GPS week number. */
8586
} gps_time_t;
8687

88+
#define GPS_TIME_UNKNOWN ((gps_time_t){TOW_UNKNOWN, WN_UNKNOWN})
89+
8790
void normalize_gps_time(gps_time_t *t_gps);
8891

8992
time_t gps2time(const gps_time_t *t);

src/time.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,10 @@ gps_time_t glo_time2gps_time(u16 nt, u8 n4, s8 h, s8 m, s8 s)
144144
u8 j = 0;
145145
u16 day_of_year = 0;
146146
u32 glo_year = 0;
147-
gps_time_t gps_t = {0, 0};
147+
gps_time_t gps_t = GPS_TIME_UNKNOWN;
148148

149-
assert(n4 >= N4_MIN && n4 <= N4_MAX);
149+
if (n4 < N4_MIN || n4 > N4_MAX)
150+
return GPS_TIME_UNKNOWN;
150151

151152
if (nt >= GLO_NT_0_FLOOR && nt <= GLO_NT_0_CEILING) {
152153
j = 1;
@@ -165,7 +166,7 @@ gps_time_t glo_time2gps_time(u16 nt, u8 n4, s8 h, s8 m, s8 s)
165166
day_of_year = nt - LEAP_YEAR_DAYS - YEAR_DAYS * 2;
166167
}
167168
else
168-
assert(0 && "invalid nt");
169+
return GPS_TIME_UNKNOWN;
169170

170171
glo_year = 1996 + 4 * (n4 - 1) + (j - 1);
171172

0 commit comments

Comments
 (0)