lib: posix: fix out-of-bound write

Ensure that write is in buffer limits

Coverity-CID: 186491

Signed-off-by: Paras Jain <parasjain2000@gmail.com>
diff --git a/lib/posix/fs.c b/lib/posix/fs.c
index 460de8d..6ffc8f3 100644
--- a/lib/posix/fs.c
+++ b/lib/posix/fs.c
@@ -293,7 +293,7 @@
 	}
 
 	rc = strlen(fdirent.name);
-	rc = (rc <= PATH_MAX) ? rc : PATH_MAX;
+	rc = (rc < PATH_MAX) ? rc : (PATH_MAX - 1);
 	memcpy(pdirent.d_name, fdirent.name, rc);
 
 	/* Make sure the name is NULL terminated */