Fix potential issues caused by implicit narrowing conversion.
Might fix issue #8596.