redo pull #1179
test case output
fix seg fault
Merge pull request #1526 from WalterBright/b23

Redo of pull #1179