[PATCH next] Fix the build failed caused by -Wstringop-overflow

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

 



gcc version: gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0

I use this version of gcc to compile, and the compilation fails. It said
that "error: writing 1 byte into a region of size 0
[-Werror=stringop-overflow=]".

This patch is to fix it to build successfully.

Fixes: 89741e7e42f6 ("Makefile: Enable -Wstringop-overflow globally")
Signed-off-by: Wenyu Huang <huangwenyu5@xxxxxxxxxx>
---
 lib/vsprintf.c | 4 ++++
 mm/mempolicy.c | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 3e3733a7084f..7a247cfecd61 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -2887,12 +2887,14 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
 	}
 
 out:
+#pragma GCC diagnostic ignored "-Wstringop-overflow"
 	if (size > 0) {
 		if (str < end)
 			*str = '\0';
 		else
 			end[-1] = '\0';
 	}
+#pragma GCC diagnostic pop
 
 	/* the trailing null byte doesn't count towards the total */
 	return str-buf;
@@ -3385,12 +3387,14 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
 	} /* while(*fmt) */
 
 out:
+#pragma GCC diagnostic ignored "-Wstringop-overflow"
 	if (size > 0) {
 		if (str < end)
 			*str = '\0';
 		else
 			end[-1] = '\0';
 	}
+#pragma GCC diagnostic pop
 
 #undef get_arg
 
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 10a590ee1c89..6c8433228c71 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -3000,6 +3000,7 @@ int mpol_parse_str(char *str, struct mempolicy **mpol)
 	err = 0;
 
 out:
+#pragma GCC diagnostic ignored "-Wstringop-overflow"
 	/* Restore string for error message */
 	if (nodelist)
 		*--nodelist = ':';
@@ -3008,6 +3009,7 @@ int mpol_parse_str(char *str, struct mempolicy **mpol)
 	if (!err)
 		*mpol = new;
 	return err;
+#pragma GCC diagnostic pop
 }
 #endif /* CONFIG_TMPFS */
 
-- 
2.34.1





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

  Powered by Linux