From: Jeff Dike Date: Fri, 30 Jun 2006 08:55:55 +0000 (-0700) Subject: [PATCH] uml: fix off-by-one bug in VM file creation X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=190f4939222b8c07cd62a20e1ce0c7a97fffde99;p=deliverable%2Flinux.git [PATCH] uml: fix off-by-one bug in VM file creation Fix an off-by-one bug in temp file creation. Seeking to the desired length and writing a byte resulted in the file being one byte longer than expected. Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/arch/um/os-Linux/mem.c b/arch/um/os-Linux/mem.c index d24d1a960523..560c8063c77c 100644 --- a/arch/um/os-Linux/mem.c +++ b/arch/um/os-Linux/mem.c @@ -210,8 +210,11 @@ int create_tmp_file(unsigned long long len) exit(1); } - if (lseek64(fd, len, SEEK_SET) < 0) { - perror("os_seek_file"); + /* Seek to len - 1 because writing a character there will + * increase the file size by one byte, to the desired length. + */ + if (lseek64(fd, len - 1, SEEK_SET) < 0) { + perror("os_seek_file"); exit(1); }