Silence compiler's suggestions about marking functions with printf-attribute.
I was getting these compiler warnings: src/s3log.cpp: In function ‘void _LogMessage(const char*, __va_list_tag*)’: src/s3log.cpp:17:42: warning: function might be possible candidate for ‘gnu_printf’ format attribute [-Wsuggest-attribute=format] vsnprintf(buf, sizeof(buf), fmt, args); ^ src/s3log.cpp: In function ‘void _send_to_remote(const char*, __va_list_tag*)’: src/s3log.cpp:27:55: warning: function might be possible candidate for ‘gnu_printf’ format attribute [-Wsuggest-attribute=format] size_t len = vsnprintf(buf, sizeof(buf), fmt, args); ^ src/s3log.cpp: In function ‘void LogMessage(LOGLEVEL, const char*, ...)’: src/s3log.cpp:41:39: warning: function might be possible candidate for ‘gnu_printf’ format attribute [-Wsuggest-attribute=format] vfprintf(stderr, fmt, args); ^ Those are good suggestions. I couldn't figure out the correct way to mark the _LogMessage() and _send_to_remote() local functions, so I decided to inline them into the caller, LogMessage(), instead. They were almost one-liners, and LogMessage() is still very small, too, so I don't think there's any significant loss to readability. A few format strings in debugging messages were treating pthread_self() as a pointer, while others were treating it as a wrong kind of integer. Harmonize by casting it to "uint64_t", and using PRIX64 as the format string. This isn't totally portable: pthread_t can be an arithmetic type, or a struct, and casting a struct to unsigned int won't work. In principle, that was a problem before this patch already, but now you should get a compiler error, if you try to compile on a platform where pthread_t is not an arithmetic type. I think that's better than silent type confusion. Reviewed-by: NPaul Guo <pguo@pivotal.io> Reviewed-by: NDaniel Gustafsson <dgustafsson@pivotal.io>
Showing
想要评论请 注册 或 登录