From 8b56eeea55c97890da0c19c94f894878e6741d41 Mon Sep 17 00:00:00 2001
From: an7s <an7s@git.zephyr-software.com>
Date: Thu, 12 May 2016 14:10:26 +0000
Subject: [PATCH] Remove static buffers

Former-commit-id: b38b2fe04cdb1e3922da22f0208cbfaaac7d5f40
---
 .../src/MEDS_FuncPrototypeAnnotation.cpp           | 14 +++++++-------
 .../src/MEDS_InstructionCheckAnnotation.cpp        | 14 ++++++++------
 2 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/libMEDSannotation/src/MEDS_FuncPrototypeAnnotation.cpp b/libMEDSannotation/src/MEDS_FuncPrototypeAnnotation.cpp
index d3213a81c..6276cd62c 100644
--- a/libMEDSannotation/src/MEDS_FuncPrototypeAnnotation.cpp
+++ b/libMEDSannotation/src/MEDS_FuncPrototypeAnnotation.cpp
@@ -28,8 +28,6 @@
 #include "MEDS_Register.hpp"
 #include "MEDS_FuncPrototypeAnnotation.hpp"
 
-#define MAX_BUF_SIZE 16000
-
 using namespace std;
 using namespace MEDS_Annotation;
 
@@ -77,13 +75,15 @@ void MEDS_FuncPrototypeAnnotation::parse()
 	VirtualOffset vo(m_rawInputLine);
 	m_virtualOffset = vo;
 
+	const int maxbufsize = m_rawInputLine.size()*2;
+
 	if (about_inargs)
 	{
 // 4046e0     71 FUNC INARGS    4  ARG0 1 ARG1 0 ARG2 0 ARG3 0
 		int numargs = 0;
-		char buf[MAX_BUF_SIZE];
-		strncpy(buf, m_rawInputLine.c_str(), MAX_BUF_SIZE-1);
-		buf[MAX_BUF_SIZE-1] = '\0';
+		char buf[maxbufsize]; bzero(buf, maxbufsize);
+		strncpy(buf, m_rawInputLine.c_str(), maxbufsize-1);
+		buf[maxbufsize-1] = '\0';
 		sscanf(buf, "%*x %*d %*s %*s %d %*s", &numargs);
 		for (int i = 0; i < numargs; ++i)
 		{
@@ -92,7 +92,7 @@ void MEDS_FuncPrototypeAnnotation::parse()
 			char *zarg = strstr(buf, arg);
 			if (zarg)
 			{
-				char tmp[MAX_BUF_SIZE];
+				char tmp[maxbufsize];
 				int meds_type;
 				sscanf(tmp,"%*s %d %*s", &meds_type);
 				MEDS_Arg marg(meds_type);
@@ -108,7 +108,7 @@ void MEDS_FuncPrototypeAnnotation::parse()
 	else if (about_return)
 	{
 		// 404740    697 FUNC RETURNTYPE RAX 1
-		char regbuf[MAX_BUF_SIZE];
+		char regbuf[maxbufsize]; bzero(regbuf, maxbufsize);
 		int meds_retType;
 		sscanf(m_rawInputLine.c_str(), "%*x %*d %*s %*s %s %d", regbuf, &meds_retType);
 		RegisterName reg = Register::getRegister(regbuf);
diff --git a/libMEDSannotation/src/MEDS_InstructionCheckAnnotation.cpp b/libMEDSannotation/src/MEDS_InstructionCheckAnnotation.cpp
index f525218ab..2a195b8ac 100644
--- a/libMEDSannotation/src/MEDS_InstructionCheckAnnotation.cpp
+++ b/libMEDSannotation/src/MEDS_InstructionCheckAnnotation.cpp
@@ -171,6 +171,8 @@ void MEDS_InstructionCheckAnnotation::parse()
 		m_isInfiniteLoop = true;
 	}
 
+	const int maxbufsize = m_rawInputLine.size()*2;
+
 	// get bit width information for overflow & underflow
 	if (m_isOverflow || m_isUnderflow)
 	{
@@ -180,8 +182,8 @@ void MEDS_InstructionCheckAnnotation::parse()
 	// 80483d5      3 INSTR CHECK UNDERFLOW SIGNED 16  CX ZZ sub     cx, ax
     // 804d51d      2 INSTR CHECK OVERFLOW UNSIGNED 32  EBX ZZ add     ebx, eax
 
-
-		char buf[1024] = "";
+		char buf[maxbufsize]; bzero(buf, maxbufsize);
+		
 		sscanf(m_rawInputLine.c_str(), "%*s %*d %*s %*s %*s %*s %d %s", &m_bitWidth, buf);
 		m_target = string(buf);
 		if (m_isNoFlag)
@@ -191,8 +193,8 @@ void MEDS_InstructionCheckAnnotation::parse()
 	}
 	else if (m_isTruncation) // get bid width from/to information for truncation
 	{
-		char buf[1024] = "";
-		char buf2[1024] = "";
+		char buf[maxbufsize]; bzero(buf, maxbufsize);
+		char buf2[maxbufsize]; bzero(buf2, maxbufsize);
 		// [ADDR] [SIZE] INSTR CHECK TRUNCATION UNKNOWNSIGN 32 EAX 16 AX ZZ mov     [esp+2Ah], ax
 		sscanf(m_rawInputLine.c_str(), "%*s %*d %*s %*s %*s %*s %d %s %d %s", &m_truncationFromWidth, buf, &m_truncationToWidth, buf2);
 
@@ -210,7 +212,7 @@ void MEDS_InstructionCheckAnnotation::parse()
 	} 
 	else if (m_isSignedness)
 	{
-		char buf[1024] = "";
+		char buf[maxbufsize]; bzero(buf, maxbufsize);
 		// [ADDR] [SIZE] INSTR CHECK SIGNEDNESS SIGNED 16 AX ZZ mov     [esp+28h], ax
 		// [ADDR] [SIZE] INSTR CHECK SIGNEDNESS UNSIGNED 16 AX ZZ mov   [esp+28h], ax
 		sscanf(m_rawInputLine.c_str(), "%*s %*d %*s %*s %*s %*s %d %s", &m_bitWidth, buf);
@@ -224,7 +226,7 @@ void MEDS_InstructionCheckAnnotation::parse()
 		// 8048293 3 INSTR MEMSET STACKOFFSET_ESP 12 SIZE 24 ZZ call memset
 		if (m_rawInputLine.find("STACKOFFSET")!=string::npos)
 		{
-			char buf[1024] = "";
+			char buf[maxbufsize]; bzero(buf, maxbufsize);
 			sscanf(m_rawInputLine.c_str(), "%*s %*d %*s %*s %*s %d %*s %d", &m_stackOffset, &m_objectSize);
 			if (m_rawInputLine.find("STACKOFFSET_EBP")!=string::npos)
 			{
-- 
GitLab