Browse Source

fixed getTimestamp() to avoid Wformat-overflow warning

master
Pete McNeil 4 years ago
parent
commit
a81ce5f3e8
1 changed files with 12 additions and 8 deletions
  1. 12
    8
      GBUdb.cpp

+ 12
- 8
GBUdb.cpp View File

} }


GBUdbDataset::GBUdbDataset(GBUdbDataset& Original) : // Copy constructor. GBUdbDataset::GBUdbDataset(GBUdbDataset& Original) : // Copy constructor.
DataArray(NULL), // The array pointer starts as NULL.
MyArraySize(Original.MyArraySize), // Copy the ArraySize
DataArray(NULL), // The array pointer starts as NULL.
MyArraySize(Original.MyArraySize), // Copy the ArraySize
MyFileName(Original.MyFileName) { // Copy the name pointer. MyFileName(Original.MyFileName) { // Copy the name pointer.
DataArray = new GBUdbRecord[MyArraySize]; // Allocate a new Array. DataArray = new GBUdbRecord[MyArraySize]; // Allocate a new Array.
memcpy(DataArray, Original.DataArray, sizeof(GBUdbRecord) * MyArraySize); // Copy the data wholesale. memcpy(DataArray, Original.DataArray, sizeof(GBUdbRecord) * MyArraySize); // Copy the data wholesale.
rename(TempFileName.c_str(), MyFileName.c_str()); // Then make our new file current. rename(TempFileName.c_str(), MyFileName.c_str()); // Then make our new file current.
} }
} }
const RuntimeCheck SaneFileSizeCheck("GBUdbDataset::load():SaneFileSizeCheck(SaneGBUdbFileSizeLimit <= FileSize)");
const RuntimeCheck SaneFileSizeCheck("GBUdbDataset::load():SaneFileSizeCheck(SaneGBUdbFileSizeLimit <= FileSize)");


void GBUdbDataset::load() { // Read the GBUdb from disk. void GBUdbDataset::load() { // Read the GBUdb from disk.


); );
} }


RuntimeCheck GoodTimestampLength("GBUdb.cpp:getTimestamp snprintf(...) != CorrectTimestampLength");
char* getTimestamp(char* TimestampBfr) { // Creates an ISO GMT timestamp. char* getTimestamp(char* TimestampBfr) { // Creates an ISO GMT timestamp.


time_t rawtime; // Get a timer and time_t rawtime; // Get a timer and
time(&rawtime); // Grab the current time and time(&rawtime); // Grab the current time and
gmt=gmtime(&rawtime); // convert it to GMT. gmt=gmtime(&rawtime); // convert it to GMT.


sprintf(TimestampBfr,"%04d%02d%02d%02d%02d%02d", // Format yyyymmddhhmmss
size_t l = snprintf(TimestampBfr,UTCBufferSize, "%04d%02d%02d%02d%02d%02d", // Format yyyymmddhhmmss
gmt->tm_year+1900, gmt->tm_year+1900,
gmt->tm_mon+1, gmt->tm_mon+1,
gmt->tm_mday, gmt->tm_mday,
gmt->tm_sec gmt->tm_sec
); );


const size_t CorrectTimestampLength = 4+2+2+2+2+2;
GoodTimestampLength(l == CorrectTimestampLength);

return TimestampBfr; return TimestampBfr;
} }


MyDataset = BuildCompressedDataset.New(); // Put the new dataset in place. MyDataset = BuildCompressedDataset.New(); // Put the new dataset in place.
delete BuildCompressedDataset.Old(); // Delete the old dataset. delete BuildCompressedDataset.Old(); // Delete the old dataset.
} // All done, so we're unlocked. } // All done, so we're unlocked.
int GBUdb::readIgnoreList(const char* FileName) { // setIgnore for a list of IPs int GBUdb::readIgnoreList(const char* FileName) { // setIgnore for a list of IPs
int IPCount = 0; // Keep track of the IPs we read. int IPCount = 0; // Keep track of the IPs we read.
try { // Capture any exceptions. try { // Capture any exceptions.
char IPLineBuffer[256]; // Create a line buffer.
char IPLineBuffer[256]; // Create a line buffer.
const int SafeBufferSize = sizeof(IPLineBuffer) - 1; // Safe size always leaves a NULL on the end. const int SafeBufferSize = sizeof(IPLineBuffer) - 1; // Safe size always leaves a NULL on the end.
ifstream ListFile(FileName, ios::in); // Open up the list file. ifstream ListFile(FileName, ios::in); // Open up the list file.
while(ListFile.good()) { // While we've got a good file (not eof) while(ListFile.good()) { // While we've got a good file (not eof)
char* cursor = IPLineBuffer; // Start on the first byte. char* cursor = IPLineBuffer; // Start on the first byte.


if('#' == *cursor) continue; // Lines that start with # are comments. if('#' == *cursor) continue; // Lines that start with # are comments.
while(0 < *cursor && isspace(*cursor)) ++cursor; // Eat any leading spaces.
while(0 < *cursor && isspace(*cursor)) ++cursor; // Eat any leading spaces.


// First octet. // First octet.



Loading…
Cancel
Save