diff --git a/src/xpdev/dirwrap.c b/src/xpdev/dirwrap.c
index aed79886b33b1fa4a0b32040eb0829fba6e3e6c4..26df7d5528cfb78b7391cca1ddde664110b063f0 100644
--- a/src/xpdev/dirwrap.c
+++ b/src/xpdev/dirwrap.c
@@ -968,8 +968,8 @@ char * DLLCALL _fullpath(char *target, const char *path, size_t size)  {
 	if(sb.st_mode&S_IFDIR)
 		strcat(target,"/"); */
 
-	for(;*out;out++)  {
-		while(*out=='/')  {
+	for(;*out;out++) {
+		while(*out=='/') {
 			if(*(out+1)=='/')
 				memmove(out,out+1,strlen(out));
 			else if(*(out+1)=='.' && (*(out+2)=='/' || *(out+2)==0))
@@ -986,6 +986,8 @@ char * DLLCALL _fullpath(char *target, const char *path, size_t size)  {
 				out++;
 			}
 		}
+		if (!*out)
+			break;
 	}
 	return(target);
 }