Merge pull request #93 from tumi8/fix_GCC_warnings

Fix gcc warnings
master
Oliver Gasser 2017-12-22 12:36:02 +01:00 committed by GitHub
commit 7ac609d7da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 82 additions and 13 deletions

View File

@ -153,5 +153,34 @@
*/
#define DISABLE_ALIGNMENT __attribute__((packed));
/*
* wrapper around GCC's fallthrough attribute, which is not supported by clang.
* clang defines __clang__ besides __GNUC__ / __GNUG__
*/
#if defined(__clang__)
#if defined(__GNUG__)
// clang++
#define __FALLTHROUGH__ [[clang::fallthrough]]
#elif defined(__GNUC__)
// clang C
#define __FALLTHROUGH__
#endif // defined(__GNUG__)
#else
#if defined(__GNUG__)
// g++
#define __FALLTHROUGH__ [[gnu::fallthrough]]
#elif defined(__GNUC__)
// gcc
#define __FALLTHROUGH__ __attribute__((fallthrough))
#else
// something else
#define __FALLTHROUGH__
#endif // defined(__GNUG__)
#endif // defined(__clang__)
#endif /*DEFS_H*/

View File

@ -179,12 +179,14 @@ bool SSL_CTX_wrapper::loadCert(
} else if (!privateKeyFile.empty())
THROWEXCEPTION("It makes no sense specifying a private key file without "
"specifying a file that contains the corresponding certificate.");
#ifdef DEBUG
if (have_cert)
DPRINTF("We successfully loaded our certificate.");
else
DPRINTF("We do NOT have a certificate. This means that we can only use "
"the anonymous modes of DTLS. This also implies that we can not "
"authenticate the client (exporter).");
#endif
return have_cert;
}

View File

@ -158,7 +158,7 @@ void report::f_post(vector<treeRecord*>& p_treeRecords,uint32_t index,report_enu
list<treeNode*>::iterator iter = specNodes.begin();
uint32_t lastindex = (index - 1 + p_treeRecords.capacity()) % p_treeRecords.capacity();
double change_global;
double change_global = .0;
if (p_treeRecords[lastindex] != NULL)
{
change_global = (double) (numTotal * 100) / (double) p_treeRecords[lastindex]->root->data.m_attributes[attribute]->numCount - 100.0;

View File

@ -144,7 +144,7 @@ char ** get_filenames(const char * directory, int * num_of_files) {
/* 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);
snprintf(filenames[i], MAX_SIZE_OF_FILENAME, "%s", pDirEnt->d_name);
//printf( "ADDED: %s\n", filenames[i] );
i++;
}

View File

@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <string.h> /* memcmp,strlen */
#include <stddef.h> /* ptrdiff_t */
#include "common/defs.h" /* __FALLTHROUGH__ */
#ifndef UTHASH_H
#define UTHASH_H
@ -337,15 +338,25 @@ do { \
hash += keylen; \
switch ( k ) { \
case 11: hash += ( (unsigned)key[10] << 24 ); \
__FALLTHROUGH__; \
case 10: hash += ( (unsigned)key[9] << 16 ); \
__FALLTHROUGH__; \
case 9: hash += ( (unsigned)key[8] << 8 ); \
__FALLTHROUGH__; \
case 8: j += ( (unsigned)key[7] << 24 ); \
__FALLTHROUGH__; \
case 7: j += ( (unsigned)key[6] << 16 ); \
__FALLTHROUGH__; \
case 6: j += ( (unsigned)key[5] << 8 ); \
__FALLTHROUGH__; \
case 5: j += key[4]; \
__FALLTHROUGH__; \
case 4: i += ( (unsigned)key[3] << 24 ); \
__FALLTHROUGH__; \
case 3: i += ( (unsigned)key[2] << 16 ); \
__FALLTHROUGH__; \
case 2: i += ( (unsigned)key[1] << 8 ); \
__FALLTHROUGH__; \
case 1: i += key[0]; \
} \
HASH_JEN_MIX(i, j, hash); \

View File

@ -20,7 +20,6 @@
*/
#include "IpfixPrinter.hpp"
#include "common/Time.h"
#include "common/Misc.h"
#include "Connection.h"
@ -267,7 +266,7 @@ void PrintHelpers::printFieldData(InformationElement::IeInfo type, IpfixRecord::
case IPFIX_TYPEID_flowEndNanoseconds:
hbnum = ntohll(*(uint64_t*)pattern);
if (hbnum>0) {
t = timentp64(*((ntp64*)(&hbnum)));
t = timentp64(u64_to_ntp64(hbnum));
fprintf(fh, "%u.%06d seconds", (int32_t)t.tv_sec, (int32_t)t.tv_usec);
} else {
fprintf(fh, "no value (only zeroes in field)");
@ -289,7 +288,7 @@ void PrintHelpers::printFieldData(InformationElement::IeInfo type, IpfixRecord::
case IPFIX_TYPEID_flowEndNanoseconds:
hbnum = ntohll(*(uint64_t*)pattern);
if (hbnum>0) {
t = timentp64(*((ntp64*)(&hbnum)));
t = timentp64(u64_to_ntp64(hbnum));
fprintf(fh, "%u.%06d seconds", (int32_t)t.tv_sec, (int32_t)t.tv_usec);
} else {
fprintf(fh, "no value (only zeroes in field)");
@ -323,6 +322,20 @@ void PrintHelpers::printFrontPayload(InformationElement::IeInfo type, IpfixRecor
fprintf(fh, "'");
}
/**
* Converts an u64 value to ntp64
* Attention: little endianess is assumed
* @param number The u64 value to be converted
* @return The value in ntp64 format
*/
ntp64 PrintHelpers::u64_to_ntp64(const uint64_t &number)
{
ntp64 ntp64_number;
ntp64_number.lower = (uint32_t)( number & 0x00000000FFFFFFFFull );
ntp64_number.upper = (uint32_t)( (uint64_t)(number & 0xFFFFFFFF00000000ull) >> 32 );
return ntp64_number;
}
/**
* Creates a new IpfixPrinter. Do not forget to call @c startIpfixPrinter() to begin printing
@ -521,7 +534,7 @@ void IpfixPrinter::printOneLineRecord(IpfixDataRecord* record)
if (fi != NULL) {
timetype = IPFIX_TYPEID_flowStartNanoseconds;
uint64_t t2 = ntohll(*reinterpret_cast<uint64_t*>(record->data+fi->offset));
timeval t = timentp64(*((ntp64*)(&t2)));
timeval t = timentp64(u64_to_ntp64(t2));
tm = localtime(&t.tv_sec);
strftime(buf, 50, "%F %T", tm);
starttime = t.tv_sec;
@ -559,7 +572,7 @@ void IpfixPrinter::printOneLineRecord(IpfixDataRecord* record)
fi = dataTemplateInfo->getFieldInfo(IPFIX_TYPEID_flowEndNanoseconds, 0);
if (fi != NULL) {
uint64_t t2 = ntohll(*reinterpret_cast<uint64_t*>(record->data+fi->offset));
timeval t = timentp64(*((ntp64*)(&t2)));
timeval t = timentp64(u64_to_ntp64(t2));
dur = t.tv_sec*1000+t.tv_usec/1000 - starttime;
}
}

View File

@ -23,6 +23,7 @@
#include "core/Module.h"
#include "common/Time.h"
#include "IpfixRecordDestination.h"
class PrintHelpers
@ -43,6 +44,7 @@ class PrintHelpers
protected:
FILE* fh;
ntp64 u64_to_ntp64(const uint64_t &number);
};
/**

View File

@ -315,7 +315,11 @@ int IpfixReceiverDtlsUdpIpV4::DtlsConnection::accept() {
char buf[512];
ret = SSL_accept(ssl);
if (SSL_get_shared_ciphers(ssl,buf,sizeof buf) != NULL)
DPRINTF("Shared ciphers:%s",buf);
#ifdef DEBUG
DPRINTF("Shared ciphers:%s",buf);
#else
{ /* do nothing */ }
#endif
if (ret==1) {
state = CONNECTED;
DPRINTF("SSL_accept() succeeded.");
@ -351,14 +355,19 @@ int IpfixReceiverDtlsUdpIpV4::DtlsConnection::accept() {
}
void IpfixReceiverDtlsUdpIpV4::DtlsConnection::shutdown() {
int ret, error;
int ret;
#ifdef DEBUG
int error;
#endif
ret = SSL_shutdown(ssl);
if (ret == 0) {
DPRINTF("Calling SSL_shutdown a second time.");
ret = SSL_shutdown(ssl);
}
#ifdef DEBUG
error = SSL_get_error(ssl,ret);
DPRINTF("SSL_shutdown() returned: %d, error: %d, strerror: %s",ret,error,strerror(errno));
#endif
state = SHUTDOWN;
}

View File

@ -27,6 +27,7 @@
#include "common/msg.h"
#include "common/Time.h"
#include "common/defs.h"
#include "core/Timer.h"
#include <sstream>
@ -69,10 +70,12 @@ IpfixSender::IpfixSender(uint32_t observationDomainId, uint32_t maxRecordRate,
maxRecordRate(maxRecordRate),
export_protocol(export_protocol)
{
#ifdef SUPPORT_DTLS
const char *certificate_chain_file = NULL;
const char *private_key_file = NULL;
const char *ca_file = NULL;
const char *ca_path = NULL;
#endif
ipfix_exporter** exporterP = &this->ipfixExporter;
@ -91,21 +94,19 @@ IpfixSender::IpfixSender(uint32_t observationDomainId, uint32_t maxRecordRate,
ipfix_set_template_transmission_timer(ipfixExporter, templateRefreshInterval);
#ifdef SUPPORT_DTLS
if ( ! certificateChainFile.empty())
certificate_chain_file = certificateChainFile.c_str();
if ( ! privateKeyFile.empty())
private_key_file = privateKeyFile.c_str();
/* Private key will be searched for in the certificate chain file if
* no private key file is set */
#ifdef SUPPORT_DTLS
if (certificate_chain_file || private_key_file)
ipfix_set_dtls_certificate(&ipfixExporter->certificate,
certificate_chain_file, private_key_file);
#endif
if ( ! caFile.empty() ) ca_file = caFile.c_str();
if ( ! caPath.empty() ) ca_path = caPath.c_str();
#ifdef SUPPORT_DTLS
if (ca_file || ca_path)
ipfix_set_ca_locations(&ipfixExporter->certificate, ca_file, ca_path);
#endif
@ -216,6 +217,7 @@ void IpfixSender::addCollector(const char *ip, uint16_t port,
case TCP:
msg(MSG_INFO, "%sIpfixSender: adding TCP://%s:%d to exporter",
vrf_log, ip, port);
__FALLTHROUGH__;
default:
THROWEXCEPTION("invalid protocol (%d) given!", proto);
break;

View File

@ -250,6 +250,7 @@ int FlowHashtable::aggregateField(TemplateInfo::FieldInfo* basefi, TemplateInfo:
if (*((uint32_t*)baseData)==0) {
*((uint32_t*)baseData) = *((uint32_t*)deltaData);
}
return 0;
case IPFIX_ETYPEID_maxPacketGap:
*(uint32_t*)baseData = greaterUint32Nbo(*(uint32_t*)baseData, *(uint32_t*)deltaData);

View File

@ -148,7 +148,7 @@ ThreadCPUInterface::SystemInfo ThreadCPUInterface::getSystemInfo()
si.freeMemory = mem;
if (fscanf(f, "Buffers: %u kB\n", &mem) != 1) {
// Linux 3.14 introduces an additional line in the /proc/meminfo output
fscanf(f, "MemAvailable: %*u kB\n");
if (fscanf(f, "MemAvailable: %*u kB\n")) {} // optional, so just ignore the result
if (fscanf(f, "Buffers: %u kB\n", &mem) != 1)
THROWEXCEPTION("failed to parse file '%s' 3", procfile.c_str());
}