Merge pull request #75 from nickbroon/solve_clang_warnings

Solve clang warnings
master
Oliver Gasser 2017-12-08 16:33:21 +01:00 committed by GitHub
commit e1145d70b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 26 additions and 47 deletions

View File

@ -1588,7 +1588,7 @@ static int sctp_reconnect(ipfix_receiving_collector *collector){
switch (snp.sn_header.sn_type) {
case SCTP_ASSOC_CHANGE:
sac = &snp.sn_assoc_change;
if (!sac->sac_state==SCTP_COMM_UP) {
if (sac->sac_state!=SCTP_COMM_UP) {
msg(MSG_ERROR, "%sSCTP connection setup failed. "
"Received unexpected SCTP_ASSOC_CHANGE notification with state %d",
vrf_log, sac->sac_state);

View File

@ -65,7 +65,7 @@ int CfgBase::getInt(const std::string& name, int def, XMLElement* elem)
std::string str;
try {
str = _get(name, elem);
int res = strtol(str.c_str(), NULL, 10);
long res = strtol(str.c_str(), NULL, 10);
if (res==LONG_MIN || res==LONG_MAX) {
THROWEXCEPTION("failed to read integer %s in element %s in configuration (is it too large? or invalid?)", str.c_str(), name.c_str());
}

View File

@ -141,7 +141,7 @@ Edge* Graph::addEdge(Node* n1, Node* n2)
void Graph::removeEdge(Node* n1, Node* n2)
{
if (matrix[n1->getID()][n2->getID()] < 0)
if (matrix[n1->getID()][n2->getID()] == NULL)
throw std::runtime_error("No edge between the nodes");
Edge *e = matrix[n1->getID()][n2->getID()];

View File

@ -89,7 +89,7 @@ XMLDocument* XMLDocument::parse_file(const std::string& fileName)
if(ctx->errNo) {
exceptionMsg = "Can't parse the file; libxml inidicates error "
+ ctx->errNo;
+ std::to_string(ctx->errNo);
goto free;
}

View File

@ -25,7 +25,6 @@ private:
XMLDocument(xmlDocPtr doc);
xmlDocPtr xmlDocument;
xmlNodePtr xmlRootNode;
struct Initializer {
Initializer();

View File

@ -27,8 +27,8 @@
InstanceManager<Host> HostStatistics::hostManager("Host");
HostStatistics::HostStatistics(std::string ipSubnet, std::string addrFilter, std::string logPath, uint16_t logInt)
: ipSubnet(ipSubnet), addrFilter(addrFilter), logPath(logPath), logInt(logInt)
HostStatistics::HostStatistics(std::string ipSubnet, std::string addrFilter, std::string logPath)
: ipSubnet(ipSubnet), addrFilter(addrFilter), logPath(logPath)
{
// check if srcIP or dstIP in the subnet (1.1.1.1/16)
// split string at the '/'

View File

@ -30,7 +30,7 @@
class HostStatistics : public IpfixRecordDestination, public Module, public Source<NullEmitable*>
{
public:
HostStatistics(std::string ipSubnet, std::string addrFilter, std::string logPath, uint16_t logInt);
HostStatistics(std::string ipSubnet, std::string addrFilter, std::string logPath);
virtual ~HostStatistics();
void onDataRecord(IpfixDataRecord* record);
@ -44,7 +44,6 @@ private:
std::string ipSubnet;
std::string addrFilter;
std::string logPath;
uint16_t logInt;
uint32_t netAddr;
uint8_t netSize;
time_t logTimer;

View File

@ -27,7 +27,6 @@ HostStatisticsCfg::HostStatisticsCfg(XMLElement* elem) : CfgHelper<HostStatistic
ipSubnet = get("subnet");
addrFilter = get("addrFilter");
logPath = get("logPath");
logInt = (uint16_t)getInt("logInterval", 10);
} catch(IllegalEntry ie) {
THROWEXCEPTION("Illegal hostStatistics entry in config file");
}
@ -48,7 +47,7 @@ HostStatisticsCfg* HostStatisticsCfg::create(XMLElement* e)
HostStatistics* HostStatisticsCfg::createInstance()
{
if (!instance) {
instance = new HostStatistics(ipSubnet, addrFilter, logPath, logInt);
instance = new HostStatistics(ipSubnet, addrFilter, logPath);
}
return instance;
}

View File

@ -43,13 +43,11 @@ protected:
std::string getSubnet() { return ipSubnet; }
std::string getAddrFilter() { return addrFilter; }
std::string getLogPath() { return logPath; }
uint16_t getLogIntervall() { return logInt; }
private:
std::string ipSubnet;
std::string addrFilter;
std::string logPath;
uint16_t logInt;
};
#endif /* HOSTSTATISTICSCFG_H_ */

View File

@ -110,8 +110,9 @@ char ** get_filenames(const char * directory, int * num_of_files) {
while ( pDirEnt != NULL ) {
/* Skip hidden entries starting with dot */
if( pDirEnt->d_name[0] != '.' ) {
int fileNameSize = snprintf(filename, sizeof(filename), "%s/%s", directory, pDirEnt->d_name);
/* Skip non-regular files (e.g. directories) */
if ( (snprintf(filename, sizeof(filename), "%s/%s", directory, pDirEnt->d_name) < sizeof(filename))
if ( ((fileNameSize < (int)sizeof(filename)) && (fileNameSize > 0))
&& (stat(filename, &dirEntStat) == 0) && (S_ISREG(dirEntStat.st_mode)) ) {
//printf( "FOUND: %s\n", pDirEnt->d_name );
filecounter++;
@ -139,8 +140,9 @@ char ** get_filenames(const char * directory, int * num_of_files) {
//printf( "%s\n", pDirEnt->d_name );
/* Skip hidden entries starting with dot */
if( pDirEnt->d_name[0] != '.' ) {
/* Skip non-regular files (e.g. directories) */
if ( (snprintf(filename, sizeof(filename), "%s/%s", directory, pDirEnt->d_name) < sizeof(filename))
int fileNameSize = snprintf(filename, sizeof(filename), "%s/%s", directory, pDirEnt->d_name);
/* Skip non-regular files (e.g. directories) */
if ( ((fileNameSize < (int)sizeof(filename)) && (fileNameSize > 0))
&& (stat(filename, &dirEntStat) == 0) && (S_ISREG(dirEntStat.st_mode)) ) {
snprintf(filenames[i], MAX_SIZE_OF_FILENAME-1, "%s", pDirEnt->d_name);
//printf( "ADDED: %s\n", filenames[i] );

View File

@ -18,9 +18,9 @@ InstanceManager<IDMEFMessage> PacketIDMEFReporter::idmefManager("ReporterIDMEFMe
PacketIDMEFReporter::PacketIDMEFReporter(string idmeftemplate, string analyzerid, uint16_t snapshotoff, uint16_t snapshotlen)
PacketIDMEFReporter::PacketIDMEFReporter(string idmeftemplate, string analyzerid, uint16_t snapshotlen)
: analyzerId(analyzerid), idmefTemplate(idmeftemplate),
snapshotOffset(snapshotoff), snapshotLength(snapshotlen)
snapshotLength(snapshotlen)
{
}

View File

@ -27,7 +27,7 @@ public:
static const char* PAR_SNAPSHOT;
PacketIDMEFReporter(string idmeftemplate, string analyzerid, uint16_t snapshotoff, uint16_t snapshotlen);
PacketIDMEFReporter(string idmeftemplate, string analyzerid, uint16_t snapshotlen);
virtual ~PacketIDMEFReporter();
virtual void receive(Packet* p);
@ -35,7 +35,6 @@ public:
private:
string analyzerId; /**< analyzer id for IDMEF messages */
string idmefTemplate; /**< template file for IDMEF messages */
uint16_t snapshotOffset; /**< offset from start of payload where snapshot is taken */
uint16_t snapshotLength; /**< length of snapshot */
char snapshotBuffer[3000]; /**< buffer for holding hexdump of snapshot */

View File

@ -12,7 +12,7 @@ PacketIDMEFReporterCfg* PacketIDMEFReporterCfg::create(XMLElement* e)
PacketIDMEFReporterCfg::PacketIDMEFReporterCfg(XMLElement* elem)
: CfgHelper<PacketIDMEFReporter, PacketIDMEFReporterCfg>(elem, "packetIdmefReporter"),
snapshotOffset(0), snapshotLength(0)
snapshotLength(0)
{
if (!elem) return;
@ -22,9 +22,7 @@ PacketIDMEFReporterCfg::PacketIDMEFReporterCfg(XMLElement* elem)
it++) {
XMLElement* e = *it;
if (e->matches("snapshotoffset")) {
snapshotOffset = getInt("snapshotoffset");
} else if (e->matches("snapshotlength")) {
if (e->matches("snapshotlength")) {
snapshotLength = getInt("snapshotlength");
} else if (e->matches("analyzerid")) {
analyzerId = e->getFirstText();
@ -46,7 +44,7 @@ PacketIDMEFReporterCfg::~PacketIDMEFReporterCfg()
PacketIDMEFReporter* PacketIDMEFReporterCfg::createInstance()
{
instance = new PacketIDMEFReporter(idmefTemplate, analyzerId, snapshotOffset, snapshotLength);
instance = new PacketIDMEFReporter(idmefTemplate, analyzerId, snapshotLength);
return instance;
}

View File

@ -27,7 +27,6 @@ protected:
string analyzerId; /**< analyzer id for IDMEF messages */
string idmefTemplate; /**< template file for IDMEF messages */
uint16_t snapshotOffset; /**< offset from start of payload where snapshot is taken */
uint16_t snapshotLength; /**< length of snapshot */

View File

@ -28,8 +28,7 @@
IpfixCollectorCfg::IpfixCollectorCfg(XMLElement* elem)
: CfgHelper<IpfixCollector, IpfixCollectorCfg>(elem, "ipfixCollector"),
listener(NULL),
ipfixCollector(NULL)
listener(NULL)
{
if (!elem)
return;

View File

@ -53,7 +53,6 @@ private:
std::string caPath;
IpfixCollector* ipfixCollector;
int32_t udpTemplateLifetime;
};

View File

@ -68,7 +68,6 @@ class IpfixCsExporter : public Module, public Source<NullEmitable*>, public Ipfi
FILE *currentFile;
char currentFilename[512];
char currentTmpname[512];
uint16_t globalIterator;
uint32_t maxFileSize; /**< maximum filesize in KiB, i.e. maximumFilesize * 1024 == maximum filesize in bytes */
uint32_t maxChunkBufferTime; /**< maximum Chunk Buffer Time (in seconds) */
uint32_t maxChunkBufferRecords; /**< maximum Chunk Buffer Records (in records) */

View File

@ -50,8 +50,6 @@ class IpfixFileWriter : public IpfixSender
private:
std::string filenamePrefix;
std::string destinationPath;
//maximum filesize in KiB, i.e. maximumFilesize * 1024 == maximum filesize in bytes
uint32_t maximumFilesize;
};

View File

@ -97,7 +97,6 @@ private:
bool ignore_timestamps;
float stretchTime;
uint16_t stretchTimeInt;
int fh;
std::ifstream packetFile;
};

View File

@ -24,7 +24,6 @@
IpfixReceiverFileCfg::IpfixReceiverFileCfg(XMLElement* elem)
: CfgHelper<IpfixCollector,IpfixReceiverFileCfg>(elem, "ipfixReceiverFile"),
ipfixCollector(NULL),
packetFileBasename("ipfix.dump"),
packetFileDirectory("./"),
c_from(0),

View File

@ -39,8 +39,6 @@ public:
bool deriveFrom(IpfixReceiverFileCfg* old);
private:
IpfixCollector* ipfixCollector;
uint16_t observationDomainId;
std::string packetFileBasename;
std::string packetFileDirectory;
int c_from;

View File

@ -41,9 +41,8 @@
* Does SCTP/IPv4 specific initialization.
* @param port Port to listen on
*/
IpfixReceiverSctpIpV4::IpfixReceiverSctpIpV4(int port, std::string ipAddr, uint32_t buffer,
unsigned int moduleId)
: statReceivedPackets(0), moduleId(moduleId)
IpfixReceiverSctpIpV4::IpfixReceiverSctpIpV4(int port, std::string ipAddr, uint32_t buffer)
: statReceivedPackets(0)
{
receiverPort = port;

View File

@ -41,8 +41,7 @@
class IpfixReceiverSctpIpV4 : public IpfixReceiver, Sensor {
#ifdef SUPPORT_SCTP
public:
IpfixReceiverSctpIpV4(int port, std::string ipAddr = "", uint32_t buffer = 0,
unsigned int moduleId = 0);
IpfixReceiverSctpIpV4(int port, std::string ipAddr = "", uint32_t buffer = 0);
virtual ~IpfixReceiverSctpIpV4();
virtual void run();
@ -51,7 +50,6 @@ class IpfixReceiverSctpIpV4 : public IpfixReceiver, Sensor {
private:
int listen_socket;
uint32_t statReceivedPackets; /**< number of received packets */
unsigned int moduleId;
#else
public:
IpfixReceiverSctpIpV4(int port, std::string ipAddr, uint32_t buffer = 0) {

View File

@ -43,7 +43,7 @@
*/
IpfixReceiverTcpIpV4::IpfixReceiverTcpIpV4(int port, std::string ipAddr,
const uint32_t buffer, unsigned int moduleId)
: statReceivedMessages(0), moduleId(moduleId)
: statReceivedMessages(0)
{
receiverPort = port;

View File

@ -43,7 +43,6 @@ class IpfixReceiverTcpIpV4 : public IpfixReceiver, Sensor {
private:
int listen_socket;
uint32_t statReceivedMessages; /**< number of received messages */
unsigned int moduleId;
};
#endif

View File

@ -45,7 +45,7 @@ using namespace std;
*/
IpfixReceiverUdpIpV4::IpfixReceiverUdpIpV4(int port, std::string ipAddr,
const uint32_t buffer, unsigned int moduleId)
: statReceivedPackets(0), moduleId(moduleId)
: statReceivedPackets(0)
{
receiverPort = port;

View File

@ -43,7 +43,6 @@ class IpfixReceiverUdpIpV4 : public IpfixReceiver, Sensor {
private:
int listen_socket;
uint32_t statReceivedPackets; /**< number of received packets */
unsigned int moduleId;
};
#endif

View File

@ -119,7 +119,7 @@ PSAMPExporterModule* PSAMPExporterCfg::createInstance()
}
msg(MSG_DEBUG, "%sPsampExporter: adding collector %s://%s:%d on VRF %s",
vrf_log,
collectors[i]->getProtocol()==132?"SCTP":"UDP",
collectors[i]->getProtocol()==ipfix_transport_protocol::SCTP?"SCTP":"UDP",
collectors[i]->getIpAddress().c_str(),
collectors[i]->getPort(),
collectors[i]->getVrfName().c_str());