diff --git a/src/ebusd/bushandler.h b/src/ebusd/bushandler.h index be93e07e..6e333737 100644 --- a/src/ebusd/bushandler.h +++ b/src/ebusd/bushandler.h @@ -146,7 +146,7 @@ class PollRequest : public BusRequest { * Constructor. * @param message the associated @a Message. */ - PollRequest(Message* message) + explicit PollRequest(Message* message) : BusRequest(m_master, true), m_message(message), m_index(0) {} /** diff --git a/src/ebusd/datahandler.h b/src/ebusd/datahandler.h index c1ce33b0..3a51abab 100644 --- a/src/ebusd/datahandler.h +++ b/src/ebusd/datahandler.h @@ -128,7 +128,7 @@ class DataSource : virtual public DataHandler { * Constructor. * @param busHandler the @a BusHandler instance. */ - DataSource(BusHandler* busHandler) + explicit DataSource(BusHandler* busHandler) : m_busHandler(busHandler) {} /** diff --git a/src/ebusd/mainloop.cpp b/src/ebusd/mainloop.cpp index abfc1150..240a1343 100644 --- a/src/ebusd/mainloop.cpp +++ b/src/ebusd/mainloop.cpp @@ -1047,17 +1047,19 @@ string MainLoop::executeFind(vector &args) { if (verbosity == (OF_NAMES|OF_UNITS|OF_COMMENTS)) { unsigned char dstAddress = message->getDstAddress(); if (dstAddress != SYN) { - sprintf(str, "%02x", dstAddress); + snprintf(str, sizeof(str), "%02x", dstAddress); } else if (lastup != 0 && message->getLastMasterData().size() > 1) { - sprintf(str, "%02x", message->getLastMasterData()[1]); + snprintf(str, sizeof(str), "%02x", message->getLastMasterData()[1]); } else { - sprintf(str, "any"); + snprintf(str, sizeof(str), "any"); } if (lastup != 0) { - struct tm* td = localtime(&lastup); - sprintf(str+strlen(str), ", lastup=%04d-%02d-%02d %02d:%02d:%02d", - td->tm_year+1900, td->tm_mon+1, td->tm_mday, - td->tm_hour, td->tm_min, td->tm_sec); + struct tm td; + localtime_r(&lastup, &td); + size_t len = strlen(str); + snprintf(str+len, sizeof(str)-len, ", lastup=%04d-%02d-%02d %02d:%02d:%02d", + td.tm_year+1900, td.tm_mon+1, td.tm_mday, + td.tm_hour, td.tm_min, td.tm_sec); } result << " [ZZ=" << str; if (message->isPassive()) { @@ -1187,7 +1189,7 @@ string MainLoop::executeScan(vector &args) { string MainLoop::executeLog(vector &args) { if (args.size() == 1) { ostringstream ret; - char str[32]; + char str[48]; if (getLogFacilities(str)) { ret << str << ' '; } diff --git a/src/ebusd/network.h b/src/ebusd/network.h index aa0e0029..5ff91d13 100644 --- a/src/ebusd/network.h +++ b/src/ebusd/network.h @@ -44,7 +44,7 @@ class NetMessage { * Constructor. * @param isHttp whether this is a HTTP message. */ - NetMessage(const bool isHttp) + explicit NetMessage(const bool isHttp) : m_isHttp(isHttp), m_resultSet(false), m_disconnect(false), m_listening(false), m_listenSince(0) { pthread_mutex_init(&m_mutex, NULL); pthread_cond_init(&m_cond, NULL); @@ -94,7 +94,7 @@ class NetMessage { if (sscanf("%1x%1x", m_request.c_str()+pos+1, &value1, &value2) < 2) { break; } - m_request[pos] = static_cast(((value1&0x0f)<<4) | (value2&0x0f)); + m_request[pos] = static_cast(((value1&0x0f) << 4) | (value2&0x0f)); m_request.erase(pos+1, 2); } } else if (pos+1 == m_request.length()) { diff --git a/src/lib/ebus/contrib/tem.cpp b/src/lib/ebus/contrib/tem.cpp index adec6d55..70212851 100644 --- a/src/lib/ebus/contrib/tem.cpp +++ b/src/lib/ebus/contrib/tem.cpp @@ -129,9 +129,9 @@ result_t TemParamDataType::writeSymbols(istringstream& input, return RESULT_ERR_OUT_OF_RANGE; // value out of range } if (isMaster) { - value = grp | (num<<8); // grp in bits 0...5, num in bits 8...13 + value = grp | (num << 8); // grp in bits 0...5, num in bits 8...13 } else { - value = (grp<<7) | num; // grp in bits 7...11, num in bits 0...6 + value = (grp << 7) | num; // grp in bits 7...11, num in bits 0...6 } } if (value < getMinValue() || value > getMaxValue()) { diff --git a/src/lib/ebus/contrib/tem.h b/src/lib/ebus/contrib/tem.h index 5f412cfe..41a2b09d 100644 --- a/src/lib/ebus/contrib/tem.h +++ b/src/lib/ebus/contrib/tem.h @@ -46,7 +46,7 @@ class TemParamDataType : public NumberDataType { * Constructs a new instance. * @param id the type identifier. */ - TemParamDataType(const string id) + explicit TemParamDataType(const string id) : NumberDataType(id, 16, 0, 0xffff, 0, 0xffff, 0) {} // @copydoc diff --git a/src/lib/ebus/datatype.h b/src/lib/ebus/datatype.h index 3d4608e5..229b6ae3 100644 --- a/src/lib/ebus/datatype.h +++ b/src/lib/ebus/datatype.h @@ -410,7 +410,7 @@ class NumberDataType : public DataType { */ NumberDataType(const string id, const unsigned char bitCount, const uint16_t flags, const unsigned int replacement, const int16_t firstBit, const int divisor) - : DataType(id, bitCount, flags|NUM, replacement), m_minValue(0), m_maxValue((1<::iterator& it, const vector::ite unsigned char dstAddress = *it; string useCircuit = circuit; if (multiple) { - sprintf(num, ".%d", index); + snprintf(num, sizeof(num), ".%d", index); useCircuit = useCircuit + num; } Message* message; diff --git a/src/lib/ebus/message.h b/src/lib/ebus/message.h index 4baa25f4..2b131801 100644 --- a/src/lib/ebus/message.h +++ b/src/lib/ebus/message.h @@ -1136,7 +1136,7 @@ class MessageMap : public FileReader { * Construct a new instance. * @param addAll whether to add all messages, even if duplicate. */ - MessageMap(const bool addAll = false) : FileReader::FileReader(true), + explicit MessageMap(const bool addAll = false) : FileReader::FileReader(true), m_addAll(addAll), m_maxIdLength(0), m_messageCount(0), m_conditionalMessageCount(0), m_passiveMessageCount(0) { m_scanMessage = Message::createScanMessage(); } diff --git a/src/lib/ebus/symbol.h b/src/lib/ebus/symbol.h index c43b6dbf..9789a6e6 100644 --- a/src/lib/ebus/symbol.h +++ b/src/lib/ebus/symbol.h @@ -84,7 +84,7 @@ class SymbolString { * Creates a new empty escaped or unescaped instance. * @param escaped whether to create an escaped instance. */ - SymbolString(const bool escaped = true) : m_unescapeState(escaped ? 0 : 1), m_crc(0) {} + explicit SymbolString(const bool escaped = true) : m_unescapeState(escaped ? 0 : 1), m_crc(0) {} /** * Add all symbols from the other @a SymbolString and the calculated CRC if escaped. diff --git a/src/lib/utils/log.cpp b/src/lib/utils/log.cpp index 49cc25ab..7fa7de45 100644 --- a/src/lib/utils/log.cpp +++ b/src/lib/utils/log.cpp @@ -68,7 +68,7 @@ bool setLogFacilities(const char* facilities) { if (val == lf_COUNT) { newFacilites = LF_ALL; } else { - newFacilites |= 1<= level); } void logWrite(const char* facility, const char* level, const char* message, va_list ap) { struct timespec ts; - struct tm* tm; + struct tm td; clockGettime(&ts); - tm = localtime(&ts.tv_sec); + localtime_r(&ts.tv_sec, &td); char* buf; if (vasprintf(&buf, message, ap) >= 0 && buf) { fprintf(s_logFile, "%04d-%02d-%02d %02d:%02d:%02d.%03ld [%s %s] %s\n", - tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, - tm->tm_hour, tm->tm_min, tm->tm_sec, ts.tv_nsec/1000000, + td.tm_year+1900, td.tm_mon+1, td.tm_mday, + td.tm_hour, td.tm_min, td.tm_sec, ts.tv_nsec/1000000, facility, level, buf); fflush(s_logFile); } diff --git a/src/lib/utils/log.h b/src/lib/utils/log.h index 6bec2829..024be767 100644 --- a/src/lib/utils/log.h +++ b/src/lib/utils/log.h @@ -32,7 +32,7 @@ enum LogFacility { }; /** macro for enabling all log facilities. */ -#define LF_ALL ((1<tm_year+1900, tm->tm_mon+1, tm->tm_mday, - tm->tm_hour, tm->tm_min, tm->tm_sec, ts.tv_nsec/1000000, + td.tm_year+1900, td.tm_mon+1, td.tm_mday, + td.tm_hour, td.tm_min, td.tm_sec, ts.tv_nsec/1000000, received ? '<' : '>'); for (unsigned int pos = 0; pos < size; pos++) { fprintf(m_stream, "%2.2x ", value[pos]);