]> sourceware.org Git - systemtap.git/commitdiff
session.cxx: make string params const
authorJonathan Lebon <jlebon@redhat.com>
Fri, 26 Jul 2013 19:31:49 +0000 (15:31 -0400)
committerJonathan Lebon <jlebon@redhat.com>
Fri, 26 Jul 2013 19:49:30 +0000 (15:49 -0400)
And change colorize() to take in a token pointer rather than a ref. This
is more in line with other funcs that take in a token and also ensures
that we don't have undefined behaviour if we're called with a
dereferenced NULL pointer (which coverity complained about).

session.cxx
session.h

index 0a15b9fa2d3fccf71c867f2cc06f1312bbcf1128..01a5f133b5b0848b994d88f358180f332bd824b2 100644 (file)
@@ -1835,7 +1835,7 @@ systemtap_session::print_token (ostream& o, const token* tok)
       o << ts;
     }
   else
-    o << colorize(*tok);
+    o << colorize(tok);
 
   last_token = tok;
 }
@@ -1998,12 +1998,12 @@ systemtap_session::print_error (const parse_error &pe,
 
   if (pe.tok || found_junk)
     {
-      cerr << _("\tat: ") << colorize(*tok) << endl;
+      cerr << _("\tat: ") << colorize(tok) << endl;
       print_error_source (cerr, align_parse_error, tok);
     }
   else if (tok) // "expected" type error
     {
-      cerr << _("\tsaw: ") << colorize(*tok) << endl;
+      cerr << _("\tsaw: ") << colorize(tok) << endl;
       print_error_source (cerr, align_parse_error, tok);
     }
   else
@@ -2014,7 +2014,7 @@ systemtap_session::print_error (const parse_error &pe,
   // print chained macro invocations
   while (tok && tok->chain) {
     tok = tok->chain;
-    cerr << _("\tin expansion of macro: ") << colorize(*tok) << endl;
+    cerr << _("\tin expansion of macro: ") << colorize(tok) << endl;
     print_error_source (cerr, align_parse_error, tok);
   }
 }
@@ -2096,7 +2096,7 @@ assert_no_interrupts()
 }
 
 std::string
-systemtap_session::colorize(std::string str, std::string type)
+systemtap_session::colorize(const std::string& str, const std::string& type)
 {
   if (str.empty() || !color_errors)
     return str;
@@ -2112,10 +2112,13 @@ systemtap_session::colorize(std::string str, std::string type)
 
 // Colorizes the path:row:col part of the token
 std::string
-systemtap_session::colorize(const token& tok)
+systemtap_session::colorize(const token* tok)
 {
+  if (tok == NULL)
+    return "";
+
   stringstream tmp;
-  tmp << tok;
+  tmp << *tok;
 
   if (!color_errors)
     return tmp.str(); // Might as well stop now to save time
@@ -2124,7 +2127,7 @@ systemtap_session::colorize(const token& tok)
 
     // Print token location, which is also the tail of ts
     stringstream loc;
-    loc << tok.location;
+    loc << tok->location;
 
     // Remove token location and re-add it colorized
     ts.erase(ts.size()-loc.str().size());
@@ -2140,7 +2143,7 @@ For example, the default setting would be:
 'error=01;31:warning=00;33:source=00;34:caret=01:token=01'
 */
 std::string
-systemtap_session::parse_stap_color(std::string type)
+systemtap_session::parse_stap_color(const std::string& type)
 {
   const char *key, *col, *eq;
   int n = type.size();
index c1e515b11ef735ce6a9003a4c5c2f5f862f8fe16..d1a86382566b3bfa6da3957f521756ba1318f193 100644 (file)
--- a/session.h
+++ b/session.h
@@ -395,9 +395,9 @@ public:
   // NB: It is very important for all of the above (and below) fields
   // to be cleared in the systemtap_session ctor (session.cxx).
 
-  std::string colorize(std::string str, std::string type);
-  std::string colorize(const token& tok);
-  std::string parse_stap_color(std::string type);
+  std::string colorize(const std::string& str, const std::string& type);
+  std::string colorize(const token* tok);
+  std::string parse_stap_color(const std::string& type);
 };
 
 struct exit_exception: public std::runtime_error
This page took 0.042339 seconds and 5 git commands to generate.