From: Niels Möller Date: Sat, 28 Sep 2002 16:04:16 +0000 (+0200) Subject: (sexp_iterator_assoc): Return 0 for missing or duplicate keys. X-Git-Tag: nettle_1.6_release_20021003~68 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e9d6f612e9d7a4180599c0e5315144e004e3a010;p=thirdparty%2Fnettle.git (sexp_iterator_assoc): Return 0 for missing or duplicate keys. Rev: src/nettle/sexp.c:1.3 --- diff --git a/sexp.c b/sexp.c index 194e23cf..bd60e29c 100644 --- a/sexp.c +++ b/sexp.c @@ -192,9 +192,19 @@ sexp_iterator_assoc(struct sexp_iterator *iterator, const struct sexp_assoc_key *keys, struct sexp_iterator *values) { + int *found; + unsigned nfound; + unsigned i; + if (!sexp_iterator_enter_list(iterator)) return 0; + found = alloca(nkeys * sizeof(*found)); + for (i = 0; idisplay) { /* Compare to the given keys */ - unsigned i; for (i = 0; iatom_length && !memcmp(keys[i].name, iterator->atom, keys[i].length)) { + if (found[i]) + /* We don't allow duplicates */ + return 0; + + found[i] = 1; + nfound++; + /* Record this position. */ values[i] = *iterator; @@ -234,7 +250,8 @@ sexp_iterator_assoc(struct sexp_iterator *iterator, break; case SEXP_END: - return sexp_iterator_exit_list(iterator); + return sexp_iterator_exit_list(iterator) + && (nfound == nkeys); default: abort();