Permalink
Browse files

fixed buffer in FileLogger::pushIntoQueue

git-svn-id: https://svn.opensource.yandex.net/xscript/trunk@732 b01ef89b-65f2-463d-9415-e8412542ae63
  • Loading branch information...
1 parent ea935e3 commit d6cd743b93dfeb9aa53d28705ca312deaa27631b lmovsesjan committed Feb 4, 2009
Showing with 18 additions and 8 deletions.
  1. +8 −0 debian/changelog
  2. +1 −1 library/details/file_logger.h
  3. +9 −7 library/file_logger.cpp
View
8 debian/changelog
@@ -1,3 +1,11 @@
+xscript (5.53-3) unstable; urgency=low
+
+ * xpointer expression "/.." optimized
+ * added show all elapsed times functionality for all threaded blocks
+ * fixed buffer in FileLogger::pushIntoQueue
+
+ -- Leonid A. Movsesjan <lmovsesjan@yandex-team.ru> Wed, 04 Feb 2009 16:14:47 +0300
+
xscript (5.53-2) unstable; urgency=low
* lua print fixed
View
2 library/details/file_logger.h
@@ -65,7 +65,7 @@ class FileLogger : public Logger {
void openFile();
- void prepareFormat(char * buf, const char* type, const char* format);
+ static void prepareFormat(char * buf, size_t size, const char* type, const char* format);
void pushIntoQueue(const char* type, const char* format, va_list args);
void writingThread();
View
16 library/file_logger.cpp
@@ -19,7 +19,7 @@
#include <dmalloc.h>
#endif
-const size_t BUF_SIZE = 512;
+const size_t BUF_SIZE = 5120;
namespace xscript {
@@ -117,28 +117,30 @@ FileLogger::pushIntoQueue(const char* type, const char* format, va_list args) {
return;
char fmt[BUF_SIZE];
- prepareFormat(fmt, type, format);
+ prepareFormat(fmt, sizeof(fmt), type, format);
char buf[BUF_SIZE];
- int size = vsnprintf(buf, BUF_SIZE, fmt, args);
+ int size = vsnprintf(buf, BUF_SIZE - 1, fmt, args);
if (size > 0) {
+ buf[BUF_SIZE - 1] = '\0';
boost::mutex::scoped_lock lock(queueMutex_);
queue_.push_back(buf);
queueCondition_.notify_one();
}
}
void
-FileLogger::prepareFormat(char * buf, const char* type, const char* format) {
+FileLogger::prepareFormat(char * buf, size_t size, const char* type, const char* format) {
time_t t;
struct tm tm;
time(&t);
localtime_r(&t, &tm);
- char timestr[BUF_SIZE];
- strftime(timestr, BUF_SIZE, "[%Y/%m/%d %T]", &tm);
+ char timestr[64];
+ strftime(timestr, sizeof(timestr) - 1, "[%Y/%m/%d %T]", &tm);
- snprintf(buf, BUF_SIZE, "%s %s: %s\n", timestr, type, format);
+ snprintf(buf, size - 1, "%s %s: %s\n", timestr, type, format);
+ buf[size - 1] = '\0';
}
void

0 comments on commit d6cd743

Please sign in to comment.