This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] gcc/c-family/c-cppbuiltin.c: Add two bytes for avoiding memory overflow issue


When 'is_str' is true, need consider about 2 '"' for the extra space, or
will cause memory overflow.

2014-11-16  Chen Gang  <gang.chen.5i5j@gmail.com>

	* c-family/c-cppbuiltin.c (builtin_define_with_value): Add two
	bytes for avoiding memory overflow issue.
---
 gcc/c-family/c-cppbuiltin.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c
index 8e8cec4..cc3d90b 100644
--- a/gcc/c-family/c-cppbuiltin.c
+++ b/gcc/c-family/c-cppbuiltin.c
@@ -1282,7 +1282,7 @@ builtin_define_with_value (const char *macro, const char *expansion, int is_str)
   char *buf;
   size_t mlen = strlen (macro);
   size_t elen = strlen (expansion);
-  size_t extra = 2;  /* space for an = and a NUL */
+  size_t extra = 4;  /* space for an =, a NUL, and 2 '"' when is_str is true */
 
   if (is_str)
     {
-- 
1.9.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]