issue-644: fix possible out-of-bounds access in GetenvBeforeMain

As suggested by user Ivan L.