Ticket #4229: foo.patch

File foo.patch, 4.1 KB (added by mansour, 8 years ago)
  • src/common/container.c

    diff --git a/src/common/container.c b/src/common/container.c
    index 56eadee..b956baf 100644
    a b smartlist_string_isin(const smartlist_t *sl, const char *element) 
    184184  return 0;
    185185}
    186186
    187 /** If <b>element</b> is equal to an element of <b>sl</b>, return that
    188  * element's index.  Otherwise, return -1. */
     187/** If <b>element</b> is equal to an element of <b>sl</b>,
     188 * store that element's index in *<b>idxp</b> and return 0.
     189 * Otherwise, return -1. */
    189190int
    190 smartlist_string_pos(const smartlist_t *sl, const char *element)
     191smartlist_string_pos(const smartlist_t *sl, const char *element,
     192                     size_t *const idxp)
    191193{
    192   int i;
     194  size_t i;
     195  tor_assert(idxp);
    193196  if (!sl) return -1;
    194197  for (i=0; i < sl->num_used; i++)
    195     if (strcmp((const char*)sl->list[i],element)==0)
    196       return i;
     198    if (strcmp((const char*)sl->list[i],element)==0) {
     199      *idxp = i;
     200      return 0;
     201    }
    197202  return -1;
    198203}
    199204
  • src/common/container.h

    diff --git a/src/common/container.h b/src/common/container.h
    index b4b9db6..fe6e8a5 100644
    a b void smartlist_string_remove(smartlist_t *sl, const char *element); 
    3838int smartlist_isin(const smartlist_t *sl, const void *element) ATTR_PURE;
    3939int smartlist_string_isin(const smartlist_t *sl, const char *element)
    4040  ATTR_PURE;
    41 int smartlist_string_pos(const smartlist_t *, const char *elt) ATTR_PURE;
     41int smartlist_string_pos(const smartlist_t *sl, const char *element,
     42                         size_t *const idxp) ATTR_PURE;
    4243int smartlist_string_isin_case(const smartlist_t *sl, const char *element)
    4344  ATTR_PURE;
    4445int smartlist_string_num_isin(const smartlist_t *sl, int num) ATTR_PURE;
  • src/or/dirvote.c

    diff --git a/src/or/dirvote.c b/src/or/dirvote.c
    index bf34c62..64bec71 100644
    a b networkstatus_compute_consensus(smartlist_t *votes, 
    15851585                     * is the same flag as votes[j]->known_flags[b]. */
    15861586    int *named_flag; /* Index of the flag "Named" for votes[j] */
    15871587    int *unnamed_flag; /* Index of the flag "Unnamed" for votes[j] */
    1588     int chosen_named_idx;
     1588    int chosen_named;
     1589    size_t chosen_named_idx;
    15891590
    15901591    strmap_t *name_to_id_map = strmap_new();
    15911592    char conflict[DIGEST_LEN];
    networkstatus_compute_consensus(smartlist_t *votes, 
    16021603    unnamed_flag = tor_malloc_zero(sizeof(int) * smartlist_len(votes));
    16031604    for (i = 0; i < smartlist_len(votes); ++i)
    16041605      unnamed_flag[i] = named_flag[i] = -1;
    1605     chosen_named_idx = smartlist_string_pos(flags, "Named");
     1606    chosen_named = smartlist_string_pos(flags, "Named", &chosen_named_idx);
    16061607
    16071608    /* Build the flag index. */
    16081609    SMARTLIST_FOREACH(votes, networkstatus_t *, v,
    networkstatus_compute_consensus(smartlist_t *votes, 
    16111612                           sizeof(int)*smartlist_len(v->known_flags));
    16121613      SMARTLIST_FOREACH(v->known_flags, const char *, fl,
    16131614      {
    1614         int p = smartlist_string_pos(flags, fl);
    1615         tor_assert(p >= 0);
     1615        size_t p;
     1616        tor_assert(smartlist_string_pos(flags, fl, &p) >= 0);
    16161617        flag_map[v_sl_idx][fl_sl_idx] = p;
    16171618        ++n_flag_voters[p];
    16181619        if (!strcmp(fl, "Named"))
    networkstatus_compute_consensus(smartlist_t *votes, 
    17811782      }
    17821783
    17831784      if (consensus_method == 1) {
    1784         is_named = chosen_named_idx >= 0 &&
     1785        is_named = chosen_named >= 0 &&
    17851786          (!naming_conflict && flag_counts[chosen_named_idx]);
    17861787      } else {
    17871788        const char *d = strmap_get_lc(name_to_id_map, rs_out.nickname);
  • src/or/routerparse.c

    diff --git a/src/or/routerparse.c b/src/or/routerparse.c
    index 6fd8db2..99f3c1f 100644
    a b routerstatus_parse_entry_from_string(memarea_t *area, 
    20412041    int i;
    20422042    vote_rs->flags = 0;
    20432043    for (i=0; i < tok->n_args; ++i) {
    2044       int p = smartlist_string_pos(vote->known_flags, tok->args[i]);
    2045       if (p >= 0) {
     2044      size_t p;
     2045      if (smartlist_string_pos(vote->known_flags, tok->args[i], &p) >= 0) {
    20462046        vote_rs->flags |= (1<<p);
    20472047      } else {
    20482048        log_warn(LD_DIR, "Flags line had a flag %s not listed in known_flags.",