linux-next.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH next] Fix the build failed caused by -Wstringop-overflow
@ 2023-11-30 10:57 Wenyu Huang
  2023-11-30 15:52 ` Gustavo A. R. Silva
  0 siblings, 1 reply; 10+ messages in thread
From: Wenyu Huang @ 2023-11-30 10:57 UTC (permalink / raw)
  To: pmladek, rostedt
  Cc: andriy.shevchenko, linux, senozhatsky, akpm, linux-next, gustavoars

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@huawei.com>
---
 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


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-11-30 21:23 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-30 10:57 [PATCH next] Fix the build failed caused by -Wstringop-overflow Wenyu Huang
2023-11-30 15:52 ` Gustavo A. R. Silva
2023-11-30 17:48   ` Andy Shevchenko
2023-11-30 17:50     ` Andy Shevchenko
2023-11-30 18:04       ` Gustavo A. R. Silva
2023-11-30 18:06         ` Andy Shevchenko
2023-11-30 18:13           ` Gustavo A. R. Silva
2023-11-30 21:23         ` Andrew Morton
2023-11-30 17:56     ` Gustavo A. R. Silva
2023-11-30 18:05       ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).