ソースを参照

2007-08-02 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

	Merged Dan's patch:
	* src/ByteArrayDiskWriter.cc: ios_base -> ios

	Use va_copy to avoid core dump on amd64:
	* src/SimpleLogger.cc
Tatsuhiro Tsujikawa 18 年 前
コミット
54be1cbc4f
3 ファイル変更23 行追加4 行削除
  1. 8 0
      ChangeLog
  2. 3 3
      src/ByteArrayDiskWriter.cc
  3. 12 1
      src/SimpleLogger.cc

+ 8 - 0
ChangeLog

@@ -1,3 +1,11 @@
+2007-08-02  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	Merged Dan's patch:
+	* src/ByteArrayDiskWriter.cc: ios_base -> ios
+
+	Use va_copy to avoid core dump on amd64:
+	* src/SimpleLogger.cc
+
 2007-08-01  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 
 	Make a2netcompat.h include a2io.h to fix compilation error:

+ 3 - 3
src/ByteArrayDiskWriter.cc

@@ -67,18 +67,18 @@ void ByteArrayDiskWriter::openExistingFile(const string& filename,
 
 void ByteArrayDiskWriter::writeData(const char* data, int32_t dataLength, int64_t position) {
   if(size() < position) {
-    buf.seekg(0, ios_base::end);
+    buf.seekg(0, ios::end);
     for(int32_t i = size(); i < position; ++i) {
       buf.put('\0');
     }
   } else {
-    buf.seekg(position, ios_base::beg);
+    buf.seekg(position, ios::beg);
   }
   buf.write(data, dataLength);
 }
 
 int32_t ByteArrayDiskWriter::readData(char* data, int32_t len, int64_t position) {
-  buf.seekg(position, ios_base::beg);
+  buf.seekg(position, ios::beg);
   buf.read(data, len);
   // TODO we have to call buf.clear() here? YES
   buf.clear();

+ 12 - 1
src/SimpleLogger.cc

@@ -41,6 +41,14 @@
 #include <stdarg.h>
 #include <errno.h>
 
+#if !defined(va_copy)
+# if defined(__va_copy)
+#  define va_copy(dest, src) __va_copy(dest, src)
+# else
+#  define va_copy(dest, src) (dest = src)
+# endif
+#endif
+
 #define WRITE_LOG(LEVEL, MSG) \
 va_list ap;\
 va_start(ap, MSG);\
@@ -89,6 +97,8 @@ void SimpleLogger::writeHeader(FILE* file, string date, string level) const {
 
 void SimpleLogger::writeLog(FILE* file, Logger::LEVEL level, const char* msg, va_list ap, Exception* e, bool printHeader) const
 {
+  va_list apCopy;
+  va_copy(apCopy, ap);
   string levelStr;
   switch(level) {
   case Logger::DEBUG:
@@ -117,7 +127,7 @@ void SimpleLogger::writeLog(FILE* file, Logger::LEVEL level, const char* msg, va
   if(printHeader) {
     writeHeader(file, datestr, levelStr);
   }
-  vfprintf(file, string(Util::replace(msg, "\r", "")+"\n").c_str(), ap);
+  vfprintf(file, string(Util::replace(msg, "\r", "")+"\n").c_str(), apCopy);
   for(Exception* nestedEx = e; nestedEx; nestedEx = nestedEx->getCause()) {
     // TODO a quick hack not to print header in console
     if(printHeader) {
@@ -126,6 +136,7 @@ void SimpleLogger::writeLog(FILE* file, Logger::LEVEL level, const char* msg, va
     fprintf(file, "exception: %s\n", Util::replace(nestedEx->getMsg(), "\r", "").c_str());
   }
   fflush(file);
+  va_end(apCopy);
 }
 
 void SimpleLogger::writeFile(Logger::LEVEL level, const char* msg, va_list ap, Exception* e) const {