diff --git a/src/xpdev/filewrap.c b/src/xpdev/filewrap.c
index ab415341271073d8810679b9736ded429bfa36dc..7b9b7cc0bc6a7868b68fad8ef01e4b675cc1858e 100644
--- a/src/xpdev/filewrap.c
+++ b/src/xpdev/filewrap.c
@@ -306,8 +306,8 @@ static int expandtofit(char **linep, size_t len, size_t *linecapp)
 	if(len+1 >= LONG_MAX)
 		return -1;
 	if(len > *linecapp) {
-		if(len == LONG_MAX + 1)
-			newcap = LONG_MAX + 1;
+		if(len == LONG_MAX)
+			newcap = LONG_MAX;
 		else
 			newcap = p2roundup(len);
 		newline = (char *)realloc(*linep, newcap);