Fix ticket #4922 (segmentation fault upon invalid code).
Merge pull request #157 from simartin/ticket_4922

Fix ticket #4922 by checking the return value of string::find().