Replace potentially zero-length VLAs in selection_iter.c with arrays from lib/generic
Over the weekend I was playing with undefined behavior sanitizer (i.e. compiling with -fsanitize=undefined) and ran Deckard with it.
While most of the errors point to member access within misaligned address type '(const)? struct entry_h', which requires 4 byte alignment in lib/cache (which are false positives I suppose, I don't understand the cache implementation enough), there is also this one:
lib/selection_iter.c:243:16: runtime error: variable length array bound evaluates to non-positive value 0
The code in question is in the iter_choose_transport function and prepares a VLA for flattening of a trie for easier manipulation.
struct choice choices[trie_weight(local_state->addresses)];
/* We may try to resolve A and AAAA record for each name, so therefore
* 2*trie_weight(…) is here. */
struct to_resolve resolvable[2 * trie_weight(local_state->names)];
trie_weight however can be 0 which leads to undefined behavior.
Replacing these with arrays from lib/generic should be easy and would maybe even lead to nicer code since they include a length field which is needed later down the line.
Furthermore coverage from Deckard probably isn't that great so we may consider running more tests with -fsanitize=undefined .