Fixed Infinite Loop in dictGetHierarchy Function

Fixed an infinite loop in the dictGetHierarchy() function if there is some invalid data in the dictionary.