Core: defensive programming

Defensively set return-by-reference value to -1 in error condition