Avoid crash when weight is NULL

review1171003
issue3433
(transplanted from e9b490ba230159872772c6bd7c231c87e3ce11f6)

--HG--
extra : transplant_source : %E9%B4%90%BA%23%01Y%87%27r%C6%BD%7C%23%1C%87%E3%CE%11%F6