]> www.infradead.org Git - users/willy/pagecache.git/commitdiff
selftests/mm: fix strncpy() length
authorKevin Brodsky <kevin.brodsky@arm.com>
Mon, 9 Dec 2024 09:50:08 +0000 (09:50 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 14 Jan 2025 06:40:54 +0000 (22:40 -0800)
GCC complains (with -O2) that the length is equal to the destination size,
which is indeed invalid.  Subtract 1 from the size of the array to leave
room for '\0'.

Link: https://lkml.kernel.org/r/20241209095019.1732120-4-kevin.brodsky@arm.com
Signed-off-by: Kevin Brodsky <kevin.brodsky@arm.com>
Cc: Aruna Ramakrishna <aruna.ramakrishna@oracle.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Joey Gouly <joey.gouly@arm.com>
Cc: Keith Lucas <keith.lucas@oracle.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
tools/testing/selftests/mm/write_to_hugetlbfs.c

index 1289d311efd7054bbf23db8c50ab0a485516d91b..34c91f7e6128a1fb56cbd06f872e06fcc1fe7d10 100644 (file)
@@ -89,7 +89,7 @@ int main(int argc, char **argv)
                        size = atoi(optarg);
                        break;
                case 'p':
-                       strncpy(path, optarg, sizeof(path));
+                       strncpy(path, optarg, sizeof(path) - 1);
                        break;
                case 'm':
                        if (atoi(optarg) >= MAX_METHOD) {