search.c: fix warnings and shorten a little code