Fix application of sizeof to pointer
Subsystems (2)
PATCH 1/1 Fix application of sizeof to pointer
From: David Yang <[email protected]>
The coccinelle check report:
"./tools/testing/selftests/vm/split_huge_page_test.c:344:36-42:
ERROR: application of sizeof to pointer"
Using the "strlen" to fix it.
--- tools/testing/selftests/vm/split_huge_page_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/vm/split_huge_page_test.c +1 -1
@@ -341,7 +341,7 @@ void split_file_backed_thp(void) }/* write something to the file, so a file-backed THP can be allocated */ - num_written =write (fd, tmpfs_loc,sizeof (tmpfs_loc)); + num_written =write (fd, tmpfs_loc,strlen (tmpfs_loc) +1 );close (fd);if (num_written <1 ) {
Signature · 1 line
2.30.2
Quoted 19 lines · On 12.10.21 05:01, [email protected] wrote:
From: David Yang <[email protected]>
The coccinelle check report:
"./tools/testing/selftests/vm/split_huge_page_test.c:344:36-42:
ERROR: application of sizeof to pointer"
Using the "strlen" to fix it.Reported-by Zeal Robot <[email protected]>Signed-off-by David Yang <[email protected]>--- tools/testing/selftests/vm/split_huge_page_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/testing/selftests/vm/split_huge_page_test.c +0
-0
tools/testing/selftests/vm/split_huge_page_test.c void split_file_backed_thp(void) · line 347
Quoted 8 lines
tools/testing/selftests/vm/split_huge_page_test.c +1
-1@@ -341,7 +341,7 @@ void split_file_backed_thp(void) }/* write something to the file, so a file-backed THP can be allocated */ - num_written =write (fd, tmpfs_loc,sizeof (tmpfs_loc)); + num_written =write (fd, tmpfs_loc,strlen (tmpfs_loc) +1 );close (fd);if (num_written <1 ) {
I think the code really just wants to write anything to the file that will be >= 1, which is also the case with this weird usage of sizeof.
As an alternative, I think we can just write anything else to the file
num_written = write(fd, (void *)&fd, sizeof(fd));
or
num_written = write(fd, "1", 1);
If I am not wrong/
Signature · 3 lines
Thanks, David / dhildenb