Przeglądaj źródła

Bug Fix: Updated Timestamp() to use C++ stringstream and to handle possible null pointer from gmtime()

git-svn-id: https://svn.microneil.com/svn/SNFMulti/trunk@48 dc71a809-1921-45c4-985c-09c81d0142d9
wx
madscientist 10 lat temu
rodzic
commit
f17433ad6c
1 zmienionych plików z 20 dodań i 12 usunięć
  1. 20
    12
      snfLOGmgr.cpp

+ 20
- 12
snfLOGmgr.cpp Wyświetl plik

@@ -8,7 +8,9 @@
#include "snfLOGmgr.hpp"
#include "../CodeDweller/threading.hpp"
#include "../CodeDweller/timing.hpp"
#include <unistd.h>
#include <unistd.h>
#include <sstream>
#include <iomanip>

using namespace std;

@@ -1734,18 +1736,24 @@ time_t snfLOGmgr::Timestamp() {
}

string snfLOGmgr::Timestamp(time_t t) { // Convert time_t to a timestamp s.
char TimestampBfr[20]; // Create a small buffer.
stringstream TimestampBfr;
const string EmptyTimestamp = "00000000000000";
string theTimeStamp = EmptyTimestamp;
tm* gmt; // Get a ptr to a tm structure.
gmt = gmtime(&t); // Fill it with UTC.
sprintf(TimestampBfr,"%04d%02d%02d%02d%02d%02d", // Format yyyymmddhhmmss
gmt->tm_year+1900,
gmt->tm_mon+1,
gmt->tm_mday,
gmt->tm_hour,
gmt->tm_min,
gmt->tm_sec
);
return string(TimestampBfr); // Return a string.
gmt = gmtime(&t); // Fill it with UTC.
bool isValidGMT = (0 != gmt);
if(isValidGMT) {
TimestampBfr
<< setw(4) << (gmt->tm_year+1900)
<< setw(2) << setfill('0')
<< (gmt->tm_mon+1)
<< (gmt->tm_mday)
<< (gmt->tm_hour)
<< (gmt->tm_min)
<< (gmt->tm_sec);
theTimeStamp = TimestampBfr.str();
}
return theTimeStamp; // Return a string.
}



Ładowanie…
Anuluj
Zapisz