fontforge/fontforge — pull request #1755 by tshinnic (2014-09-29 05:15:51+00:00)
Title: Guard against crashes when "Guide" layer active

This change implements checks against crashes in some vulnerable routines that can fail when the current displayed layer in CharView is the "Guide" aka 'grid' layer.

This addresses the internal code aspects of issue #1750 "Crash when clearing stem hints from Guide layer". In conjunction with PR #1754 this **should be good enough to close that issue**.

Testing of various UI actions revealed that the below routines would crash when using the layer index value -1, which is the 'grid' layer index:
```
fontforge/cvundoes.c SCPreserveHints()
fontforge/splinechar.c SCNumberPoints()
fontforge/autohint.c _SCClearHintMasks()
fontforge/stemdb.c GlyphDataInit()
fontforge/cvhints.c SCModifyHintMasksAdd()
```
Code was added to these routines to simply return if the layer value was outside the valid index range for the layers array.

During testing using Python scripts a further set of routines sensitive to layer values were identified in python.c and fixes applied.

Finally, the original source investigation found a number of places where code was using "magic numbers" that were equivalent to the `enum layer_type` values defined in splinefont.h. This obscured the intent of such code and enum definitions were used to replace those numbers (-1, -2, etc.)

Tested with debug printf()'s to demonstrate usefulness, with all these added checks being hit and preventing crashes.

"Doctor Doctor when I touch my head it hurts. When I touch my arm it hurts. When I touch my knees it hurts." The doctor replied, "You have a broken finger."