The second snippet is in the master branch as well as in the 5.4. I did a diff to src/modules/dialog/dlg_var.c and is identical in the two branches. And it is safer than the first snippet, if still crashes it is not from there net.
Or maybe you mixed the versions and what you wanted to write?