[Jay] Fix memory corruptions: out-of-bounds and uninitialized value.
Merge pull request #1032 from miguelzf/master

[Jay] Fix memory corruptions: out-of-bounds and uninitialized value.