Yes, I agree that proper test coverage is needed here. Will think about how to accomplish this.
Tried to apply this patch to current master branch and the build was ok, however it crashed during initdb with a message like below.
"performing post-bootstrap initialization ... Segmentation fault (core dumped)"
If I remove this patch and recompile again, then "initdb -D $PGDATA" works. Thanks, David