From: Miroslav Lichvar Date: Mon, 8 Jun 2015 09:48:29 +0000 (+0200) Subject: sources: fix marking of non-preferred selectable sources X-Git-Tag: 2.1-pre1~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4253075a97141edfa62043ab71bd0673587e6629;p=thirdparty%2Fchrony.git sources: fix marking of non-preferred selectable sources When reducing the list of selectable sources to sources with the prefer option, sources before the first preferred source were left with the SRC_OK status, which triggered an assertion failure in the next selection. --- diff --git a/sources.c b/sources.c index 8817649f..1ba2a740 100644 --- a/sources.c +++ b/sources.c @@ -872,16 +872,18 @@ SRC_SelectSource(SRC_Instance updated_inst) /* If there are any sources with prefer option, reduce the list again only to the preferred sources */ - for (i = j = 0; i < n_sel_sources; i++) { + for (i = 0; i < n_sel_sources; i++) { if (sources[sel_sources[i]]->sel_option == SRC_SelectPrefer) - sel_sources[j++] = sel_sources[i]; + break; } - - if (j > 0) { - for (i = 0; i < n_sel_sources; i++) { + if (i < n_sel_sources) { + for (i = j = 0; i < n_sel_sources; i++) { if (sources[sel_sources[i]]->sel_option != SRC_SelectPrefer) sources[sel_sources[i]]->status = SRC_NONPREFERRED; + else + sel_sources[j++] = sel_sources[i]; } + assert(j > 0); n_sel_sources = j; sel_prefer = 1; } else {