Fix to #650,  http://bugs.mariadb.com/show_bug.cgi?id=650

Added checks.