Fixes #2626 and #2698 (strings size limits were hardcoded in sscanf call)

Replaces pull #714 (for redmine #2626).
Simplifies the implementation of sscanf parsing.