[rtems-tools commit] Remove input buffer global variables

Joel Sherrill joel at rtems.org
Tue Aug 3 21:00:44 UTC 2021


Module:    rtems-tools
Branch:    master
Commit:    d5178b8dc53d1130a4c564a6cf233bc29fe82931
Changeset: http://git.rtems.org/rtems-tools/commit/?id=d5178b8dc53d1130a4c564a6cf233bc29fe82931

Author:    Ryan Long <ryan.long at oarcorp.com>
Date:      Wed Jul 28 09:23:14 2021 -0400

Remove input buffer global variables

- Removed input buffers from app_common and added them as a local variable
  to functions where inputBuffer was being used
  - Added #define for MAX_LINE_LENGTH in files where it is used
- Changed Explanations::load to use a string instead of a C-string

---

 tester/covoar/Explanations.cc       | 20 +++++++++-----------
 tester/covoar/ObjdumpProcessor.cc   |  3 +++
 tester/covoar/TraceReaderLogQEMU.cc |  3 +++
 tester/covoar/app_common.cc         |  2 --
 tester/covoar/app_common.h          |  4 ----
 tester/covoar/covoar.cc             |  3 +++
 6 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/tester/covoar/Explanations.cc b/tester/covoar/Explanations.cc
index 681ffd6..0371666 100644
--- a/tester/covoar/Explanations.cc
+++ b/tester/covoar/Explanations.cc
@@ -31,7 +31,6 @@ namespace Coverage {
     const char* const explanations
   )
   {
-    #define MAX_LINE_LENGTH 512
     std::ifstream  explain;
     Explanation    e;
     int            line = 1;
@@ -46,44 +45,44 @@ namespace Coverage {
       throw rld::error( what, "Explanations::load" );
     }
 
+    std::string input_line;
     while ( 1 ) {
       // Read the starting line of this explanation and
       // skip blank lines between
       do {
-        inputBuffer[0] = '\0';
-        explain.getline( inputBuffer, MAX_LINE_LENGTH );
+        std::getline( explain, input_line );
         if (explain.fail()) {
           return;
         }
         line++;
-      } while ( inputBuffer[0] == '\0' );
+      } while ( input_line.empty() );
 
       // Have we already seen this one?
-      if (set.find( inputBuffer ) != set.end()) {
+      if (set.find( input_line ) != set.end()) {
         std::ostringstream what;
         what << "line " << line
              << "contains a duplicate explanation ("
-             << inputBuffer << ")";
+             << input_line << ")";
         throw rld::error( what, "Explanations::load" );
       }
 
       // Add the starting line and file
-      e.startingPoint = std::string(inputBuffer);
+      e.startingPoint = input_line;
       e.found = false;
 
       // Get the classification
-      explain.getline( inputBuffer, MAX_LINE_LENGTH );
+      std::getline( explain, input_line );
       if (explain.fail()) {
         std::ostringstream what;
         what << "line " << line
              << "out of sync at the classification";
         throw rld::error( what, "Explanations::load" );
       }
-      e.classification = inputBuffer;
+      e.classification = input_line;
       line++;
 
       // Get the explanation
-      for (std::string input_line; std::getline( explain, input_line ); ) {
+      while ( std::getline( explain, input_line ) ) {
         line++;
 
         const std::string delimiter = "+++";
@@ -105,7 +104,6 @@ namespace Coverage {
       set[ e.startingPoint ] = e;
     }
 
-    #undef MAX_LINE_LENGTH
   }
 
   const Explanation *Explanations::lookupExplanation(
diff --git a/tester/covoar/ObjdumpProcessor.cc b/tester/covoar/ObjdumpProcessor.cc
index 2bf1685..d324440 100644
--- a/tester/covoar/ObjdumpProcessor.cc
+++ b/tester/covoar/ObjdumpProcessor.cc
@@ -24,6 +24,8 @@
 #include "rld.h"
 #include "rld-process.h"
 
+#define MAX_LINE_LENGTH 512
+
 namespace Coverage {
 
   void finalizeSymbol(
@@ -136,6 +138,7 @@ namespace Coverage {
     FILE*        loadAddressFile = NULL;
     char*        cStatus;
     uint32_t     offset;
+    char         inputBuffer[MAX_LINE_LENGTH];
 
     // This method should only be call for a dynamic library.
     if (!theExecutable->hasDynamicLibrary())
diff --git a/tester/covoar/TraceReaderLogQEMU.cc b/tester/covoar/TraceReaderLogQEMU.cc
index 0a61ea5..37952a3 100644
--- a/tester/covoar/TraceReaderLogQEMU.cc
+++ b/tester/covoar/TraceReaderLogQEMU.cc
@@ -61,6 +61,8 @@
 #define OPEN fopen
 #endif
 
+#define MAX_LINE_LENGTH 512
+
 namespace Trace {
 
   TraceReaderLogQEMU::TraceReaderLogQEMU()
@@ -85,6 +87,7 @@ namespace Trace {
     int                 status;
     FILE*               logFile;
     int                 result;
+    char                inputBuffer[MAX_LINE_LENGTH];
 
     //
     // Verify that the log file has a non-zero size.
diff --git a/tester/covoar/app_common.cc b/tester/covoar/app_common.cc
index 6f88f4b..53b5284 100644
--- a/tester/covoar/app_common.cc
+++ b/tester/covoar/app_common.cc
@@ -59,8 +59,6 @@
 Coverage::DesiredSymbols*   SymbolsToAnalyze    = NULL;
 bool                        BranchInfoAvailable = false;
 Target::TargetBase*         TargetInfo          = NULL;
-char                        inputBuffer[MAX_LINE_LENGTH];
-char                        inputBuffer2[MAX_LINE_LENGTH];
 
 
 bool FileIsNewer(
diff --git a/tester/covoar/app_common.h b/tester/covoar/app_common.h
index 473d259..4f3b798 100644
--- a/tester/covoar/app_common.h
+++ b/tester/covoar/app_common.h
@@ -16,10 +16,6 @@ extern Coverage::DesiredSymbols*    SymbolsToAnalyze;
 extern bool                         BranchInfoAvailable;
 extern Target::TargetBase*          TargetInfo;
 
-#define MAX_LINE_LENGTH             512
-extern char                         inputBuffer[MAX_LINE_LENGTH];
-extern char                         inputBuffer2[MAX_LINE_LENGTH];
-
 
 bool FileIsNewer( const char *f1, const char *f2 );
 bool FileIsReadable( const char *f1 );
diff --git a/tester/covoar/covoar.cc b/tester/covoar/covoar.cc
index 2d161aa..8ee3eb8 100644
--- a/tester/covoar/covoar.cc
+++ b/tester/covoar/covoar.cc
@@ -34,6 +34,8 @@
   #define kill(p,s) raise(s)
 #endif
 
+#define MAX_LINE_LENGTH 512
+
 typedef std::list<std::string> CoverageNames;
 typedef std::list<Coverage::ExecutableInfo*> Executables;
 typedef std::string option_error;
@@ -174,6 +176,7 @@ int covoar(
   std::string                   symbolSet;
   std::string                   option;
   int                           opt;
+  char                          inputBuffer[MAX_LINE_LENGTH];
   Coverage::Explanations        allExplanations;
   Coverage::ObjdumpProcessor    objdumpProcessor;
   bool                          verbose = false;



More information about the vc mailing list