Re: [PATCH v2 1/1] fs: proc: Fix build with GCC 15 due to -Werror=unterminated-string-initialization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 02.10.2024 14:48, Andrew Morton wrote:
> If we do remove the party trick (as you have done) then this:
> 
> 		if (vma->vm_flags & (1UL << i)) {
> 			seq_putc(m, mnemonics[i][0]);
> 			seq_putc(m, mnemonics[i][1]);
> 			seq_putc(m, ' ');
> 		}
> 
> can be simplified (and probably sped up) with
> 
> 		
> 		if (vma->vm_flags & (1UL << i))
> 			seq_printf(m, "%s ", mnemonics[i]);
> 
> yes?
> 

Hi Andrew, Hi Stephen,

With Andrew's suggestion I came up with something like this, would love
some feedback.

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 72f14fd59c2d..c7b6ce4f30c3 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -909,8 +909,15 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma)
 {
 	/*
 	 * Don't forget to update Documentation/ on changes.
+	 *
+	 * The length of the second argument of mnemonics[]
+	 * needs to be 3 instead of previously set 2
+	 * (i.e. from [BITS_PER_LONG][2] to [BITS_PER_LONG][3])
+	 * to avoid spurious
+	 * -Werror=unterminated-string-initialization warning
+	 *  with GCC 15
 	 */
-	static const char mnemonics[BITS_PER_LONG][2] = {
+	static const char mnemonics[BITS_PER_LONG][3] = {
 		/*
 		 * In case if we meet a flag we don't know about.
 		 */
@@ -985,13 +992,10 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma)
 
 	seq_puts(m, "VmFlags: ");
 	for (i = 0; i < BITS_PER_LONG; i++) {
-		if (!mnemonics[i][0])
+		if (strcmp(mnemonics[i], "") == 0)
 			continue;
-		if (vma->vm_flags & (1UL << i)) {
-			seq_putc(m, mnemonics[i][0]);
-			seq_putc(m, mnemonics[i][1]);
-			seq_putc(m, ' ');
-		}
+		if (vma->vm_flags & (1UL << i))
+			seq_printf(m, "%s ", mnemonics[i]);
 	}
 	seq_putc(m, '\n');
 }
-- 
Regards,
listout




[Index of Archives]     [Linux Kernel]     [Linux USB Development]     [Yosemite News]     [Linux SCSI]

  Powered by Linux