move when appropriate.
Message-ID: <5981b814.buUROqiU3UsuPPY8%sp(a)mathias-kettner.de>
User-Agent: Heirloom mailx 12.5 6/20/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Module: check_mk
Branch: master
Commit: 746e09389c6c6d249c240b18c29d6e4e8ab7ce55
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=746e09389c6c6d…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Wed Aug 2 13:05:49 2017 +0200
Sanitize signatures: Pass string values around, and use std::move when appropriate.
Change-Id: I982b6a4ae21a18d7dcd4cd64cf1802567f194a6a
---
livestatus/src/LogEntry.cc | 6 +++---
livestatus/src/LogEntry.h | 2 +-
livestatus/src/Logfile.cc | 7 +++----
livestatus/src/Logfile.h | 2 +-
4 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/livestatus/src/LogEntry.cc b/livestatus/src/LogEntry.cc
index a81d923..c59d059 100644
--- a/livestatus/src/LogEntry.cc
+++ b/livestatus/src/LogEntry.cc
@@ -36,9 +36,9 @@ using std::unordered_map;
// TODO(sp) Fix classifyLogMessage() below to always set all fields and remove
// this set-me-to-zero-to-be-sure-block.
-LogEntry::LogEntry(MonitoringCore *mc, unsigned lineno, const char *line)
+LogEntry::LogEntry(MonitoringCore *mc, unsigned lineno, string line)
: _lineno(lineno)
- , _complete(line)
+ , _complete(std::move(line))
, _state(0)
, _attempt(0)
, _host(nullptr)
@@ -69,7 +69,7 @@ LogEntry::LogEntry(MonitoringCore *mc, unsigned lineno, const char
*line)
return; // ignore invalid lines silently
}
- classifyLogMessage(line + timestamp_prefix_length);
+ classifyLogMessage(&_complete[timestamp_prefix_length]);
applyWorkarounds();
updateReferences(mc);
}
diff --git a/livestatus/src/LogEntry.h b/livestatus/src/LogEntry.h
index 24771a7..f45f23d 100644
--- a/livestatus/src/LogEntry.h
+++ b/livestatus/src/LogEntry.h
@@ -99,7 +99,7 @@ public:
Command _command;
// NOTE: line gets modified!
- LogEntry(MonitoringCore *mc, unsigned lineno, const char *line);
+ LogEntry(MonitoringCore *mc, unsigned lineno, std::string line);
unsigned updateReferences(MonitoringCore *mc);
static ServiceState parseServiceState(const std::string &str);
static HostState parseHostState(const std::string &str);
diff --git a/livestatus/src/Logfile.cc b/livestatus/src/Logfile.cc
index 66a596e..71625f9 100644
--- a/livestatus/src/Logfile.cc
+++ b/livestatus/src/Logfile.cc
@@ -174,8 +174,7 @@ void Logfile::loadRange(FILE *file, unsigned missing_types, LogCache
*logcache,
}
}
if (processLogLine(_lineno, &linebuffer[0], missing_types)) {
- logcache->handleNewMessage(this, since, until,
- logclasses); // memory management
+ logcache->handleNewMessage(this, since, until, logclasses);
}
}
}
@@ -200,9 +199,9 @@ long Logfile::freeMessages(unsigned logclasses) {
return freed;
}
-bool Logfile::processLogLine(uint32_t lineno, const char *line,
+bool Logfile::processLogLine(uint32_t lineno, string line,
unsigned logclasses) {
- auto entry = make_unique<LogEntry>(_mc, lineno, line);
+ auto entry = make_unique<LogEntry>(_mc, lineno, std::move(line));
// ignored invalid lines
if (entry->_logclass == LogEntry::Class::invalid) {
return false;
diff --git a/livestatus/src/Logfile.h b/livestatus/src/Logfile.h
index 0b1567d..5fc5663 100644
--- a/livestatus/src/Logfile.h
+++ b/livestatus/src/Logfile.h
@@ -93,7 +93,7 @@ public:
private:
void loadRange(FILE *file, unsigned missing_types, LogCache *, time_t since,
time_t until, unsigned logclasses);
- bool processLogLine(uint32_t lineno, const char *line, unsigned logclasses);
+ bool processLogLine(uint32_t lineno, std::string line, unsigned logclasses);
uint64_t makeKey(time_t, unsigned);
Logger *logger() const;
};