HH-95 Changes from code review.
- Validate all interesting params
- cast return value to unsigned
- avoid possible null ptr manipulation
- Provide better error logging

Signed-off-by: rpastrana <rodrigo.pastrana@lexisnexis.com>