Check whether we got valid result before trying to use it

Signed-off-by: Michal Čihař <michal@cihar.com>