Fix casting error (bug #3681, take 2)