after you change to a do {} while (0); construct,  this can be merged  down below . you do have to pop_stack before returning error I believe.