cleaned up lots of not-so-niceties and a few bugs
I built everything with clang (hackishly in some areas) and it spit out a bunch
of warnings.
diff --git a/aos/common/logging/logging.h b/aos/common/logging/logging.h
index 114007b..6487b64 100644
--- a/aos/common/logging/logging.h
+++ b/aos/common/logging/logging.h
@@ -33,27 +33,20 @@
// Not static const size_t for C code.
#define LOG_MESSAGE_LEN 400
-#ifdef __VXWORKS__
-// We're using ancient glibc, so sticking to just what the syscall can handle is
-// probably safer.
-#define LOG_PRINTF_FORMAT_TYPE printf
-#else
-#define LOG_PRINTF_FORMAT_TYPE gnu_printf
-#endif
#ifdef __cplusplus
extern "C" {
#endif
// Actually implements the basic logging call.
// Does not check that level is valid.
void log_do(log_level level, const char *format, ...)
- __attribute__((format(LOG_PRINTF_FORMAT_TYPE, 2, 3)));
+ __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 2, 3)));
void log_cork(int line, const char *function, const char *format, ...)
- __attribute__((format(LOG_PRINTF_FORMAT_TYPE, 3, 4)));
+ __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 3, 4)));
// Implements the uncork logging call.
void log_uncork(int line, const char *function, log_level level,
const char *file, const char *format, ...)
- __attribute__((format(LOG_PRINTF_FORMAT_TYPE, 5, 6)));
+ __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 5, 6)));
#ifdef __cplusplus
}
#endif
diff --git a/aos/common/logging/logging_impl.cc b/aos/common/logging/logging_impl.cc
index 5c5dfc4..714aaf1 100644
--- a/aos/common/logging/logging_impl.cc
+++ b/aos/common/logging/logging_impl.cc
@@ -25,6 +25,7 @@
LOG(FATAL, "can't have a next logger from here\n");
}
+ __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 3, 0)))
virtual void DoLog(log_level level, const char *format, va_list ap) {
LogMessage message;
internal::FillInMessage(level, format, ap, &message);
diff --git a/aos/common/logging/logging_impl.h b/aos/common/logging/logging_impl.h
index 440e3fe..57f09ec 100644
--- a/aos/common/logging/logging_impl.h
+++ b/aos/common/logging/logging_impl.h
@@ -15,10 +15,11 @@
#include "aos/common/logging/logging.h"
#include "aos/common/type_traits.h"
#include "aos/common/mutex.h"
+#include "aos/common/macros.h"
namespace aos {
-class MessageType;
+struct MessageType;
} // namespace aos
@@ -101,16 +102,19 @@
// Takes a message and logs it. It will set everything up and then call DoLog
// for the current LogImplementation.
-void VLog(log_level level, const char *format, va_list ap);
+void VLog(log_level level, const char *format, va_list ap)
+ __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 2, 0)));
// Adds to the saved up message.
-void VCork(int line, const char *format, va_list ap);
+void VCork(int line, const char *function, const char *format, va_list ap)
+ __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 3, 0)));
// Actually logs the saved up message.
-void VUnCork(int line, log_level level, const char *file,
- const char *format, va_list ap);
+void VUnCork(int line, const char *function, log_level level, const char *file,
+ const char *format, va_list ap)
+ __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 5, 0)));
// Will call VLog with the given arguments for the next logger in the chain.
void LogNext(log_level level, const char *format, ...)
- __attribute__((format(LOG_PRINTF_FORMAT_TYPE, 2, 3)));
+ __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 2, 3)));
// Takes a structure and log it.
template <class T>
@@ -140,7 +144,9 @@
private:
// Actually logs the given message. Implementations should somehow create a
// LogMessage and then call internal::FillInMessage.
+ __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 3, 0)))
virtual void DoLog(log_level level, const char *format, va_list ap) = 0;
+ __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 3, 4)))
void DoLogVariadic(log_level level, const char *format, ...) {
va_list ap;
va_start(ap, format);
@@ -167,7 +173,8 @@
// These functions call similar methods on the "current" LogImplementation or
// Die if they can't find one.
// levels is how many LogImplementations to not use off the stack.
- static void DoVLog(log_level, const char *format, va_list ap, int levels);
+ static void DoVLog(log_level, const char *format, va_list ap, int levels)
+ __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 2, 0)));
// This one is implemented in queue_logging.cc.
static void DoLogStruct(log_level level, const ::std::string &message,
size_t size, const MessageType *type,
@@ -195,6 +202,7 @@
StreamLogImplementation(FILE *stream);
private:
+ __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 3, 0)))
virtual void DoLog(log_level level, const char *format, va_list ap);
FILE *const stream_;
@@ -297,8 +305,10 @@
// Fills in *message according to the given inputs (with type kString).
// Used for implementing LogImplementation::DoLog.
void FillInMessage(log_level level, const char *format, va_list ap,
- LogMessage *message);
+ LogMessage *message)
+ __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 2, 0)));
+__attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 3, 4)))
static inline void FillInMessageVarargs(log_level level, LogMessage *message,
const char *format, ...) {
va_list ap;
@@ -313,7 +323,8 @@
// Prints format (with ap) into output and correctly deals with the result
// being too long etc.
size_t ExecuteFormat(char *output, size_t output_size, const char *format,
- va_list ap);
+ va_list ap)
+ __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 3, 0)));
// Runs the given function with the current LogImplementation (handles switching
// it out while running function etc).
diff --git a/aos/common/logging/logging_impl_test.cc b/aos/common/logging/logging_impl_test.cc
index dea1815..f472bef 100644
--- a/aos/common/logging/logging_impl_test.cc
+++ b/aos/common/logging/logging_impl_test.cc
@@ -16,6 +16,7 @@
namespace testing {
class TestLogImplementation : public LogImplementation {
+ __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 3, 0)))
virtual void DoLog(log_level level, const char *format, va_list ap) {
internal::FillInMessage(level, format, ap, &message_);