Fix a potential crash when CWD is too long