Skip to content

Commit

Permalink
alternatives: first read member is always the best one
Browse files Browse the repository at this point in the history
, so don't segfault
  • Loading branch information
lnykryn committed May 21, 2024
1 parent 664d76b commit fcbacfa
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions alternatives.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ static int readConfig(struct alternativeSet *set, const char *title,
set->alts = NULL;
set->numAlts = 0;
set->mode = AUTO;
set->best = 0;
set->best = -1;
set->current = -1;

path = alloca(strlen(stateDir) + strlen(title) + 2);
Expand Down Expand Up @@ -485,7 +485,7 @@ static int readConfig(struct alternativeSet *set, const char *title,
newAlt.followers[i - 1].target = (line && strlen(line)) ? strsteal(&line) : NULL;
}

if (newAlt.priority > set->alts[set->best].priority)
if (set->best == -1 || newAlt.priority > set->alts[set->best].priority)
set->best = set->numAlts;

set->alts = realloc(set->alts, (set->numAlts + 1) * sizeof(*set->alts));
Expand Down

0 comments on commit fcbacfa

Please sign in to comment.