Skip to content

Commit 50142a7

Browse files
committed
time BUGFIX use initialized vars
1 parent fdcf059 commit 50142a7

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

src/plugins_types/time.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ lyplg_type_compare_time(const struct ly_ctx *UNUSED(ctx), const struct lyd_value
219219
{
220220
struct lyd_value_time *v1, *v2;
221221
struct lyd_value_time_nz *vn1, *vn2;
222+
const char *fr1, *fr2;
222223

223224
if (!strcmp(val1->realtype->name, "time")) {
224225
LYD_VALUE_GET(val1, v1);
@@ -228,6 +229,9 @@ lyplg_type_compare_time(const struct ly_ctx *UNUSED(ctx), const struct lyd_value
228229
if ((v1->seconds != v2->seconds) || (v1->unknown_tz != v2->unknown_tz)) {
229230
return LY_ENOT;
230231
}
232+
233+
fr1 = v1->fractions_s;
234+
fr2 = v2->fractions_s;
231235
} else {
232236
LYD_VALUE_GET(val1, vn1);
233237
LYD_VALUE_GET(val2, vn2);
@@ -236,11 +240,13 @@ lyplg_type_compare_time(const struct ly_ctx *UNUSED(ctx), const struct lyd_value
236240
if (vn1->seconds != vn2->seconds) {
237241
return LY_ENOT;
238242
}
243+
244+
fr1 = vn1->fractions_s;
245+
fr2 = vn2->fractions_s;
239246
}
240247

241248
/* compare second fractions */
242-
if ((!v1->fractions_s && !v2->fractions_s) ||
243-
(v1->fractions_s && v2->fractions_s && !strcmp(v1->fractions_s, v2->fractions_s))) {
249+
if ((!fr1 && !fr2) || (fr1 && fr2 && !strcmp(fr1, fr2))) {
244250
return LY_SUCCESS;
245251
}
246252
return LY_ENOT;
@@ -315,8 +321,8 @@ lyplg_type_sort_by_fractions(char *f1, char *f2)
315321
static int
316322
lyplg_type_sort_time(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1, const struct lyd_value *val2)
317323
{
318-
struct lyd_value_time *v1, *v2;
319-
struct lyd_value_time_nz *vn1, *vn2;
324+
struct lyd_value_time *v1 = NULL, *v2;
325+
struct lyd_value_time_nz *vn1 = NULL, *vn2;
320326
double dt;
321327

322328
if (!strcmp(val1->realtype->name, "time")) {
@@ -337,7 +343,11 @@ lyplg_type_sort_time(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *v
337343
}
338344

339345
/* compare second fractions */
340-
return lyplg_type_sort_by_fractions(v1->fractions_s, v2->fractions_s);
346+
if (v1) {
347+
return lyplg_type_sort_by_fractions(v1->fractions_s, v2->fractions_s);
348+
} else {
349+
return lyplg_type_sort_by_fractions(vn1->fractions_s, vn2->fractions_s);
350+
}
341351
}
342352

343353
/**

0 commit comments

Comments
 (0)