Guarding against adding more non-zeroes than it is the size of the problem

Refs #4230
Merge pull request #3 from andrsd/realloc_4230

Guarding against adding more non-zeroes than it is the size of the probl...