There are several problems with data types, casts, and checks in
getlocalbase(). This attempts to fix them
miblen is currently uninitialised before the call; presumably it works because it's reading random garbage on the stack that's most likely >= 2. You should probably also be checking the return value here.