aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar Jan Tattermusch <jtattermusch@users.noreply.github.com>2016-06-14 19:31:05 -0700
committerGravatar GitHub <noreply@github.com>2016-06-14 19:31:05 -0700
commit8fb6c924b54775be2d9fea52a39cc930460558de (patch)
treea7c19431afc9a724772f3a8309a8dc5095ec5fb0 /include
parentb4fc876dbb0307c2d07d087fa80a5ee3c514d389 (diff)
parent289dcb1b68c236d11a8f5a89827e95af94a7df12 (diff)
Merge pull request #6875 from y-zeng/log_check
Add format check for gpr_log and gpr_asprintf, add gpr_strpad
Diffstat (limited to 'include')
-rw-r--r--include/grpc/impl/codegen/log.h3
-rw-r--r--include/grpc/impl/codegen/port_platform.h9
-rw-r--r--include/grpc/support/string_util.h3
3 files changed, 13 insertions, 2 deletions
diff --git a/include/grpc/impl/codegen/log.h b/include/grpc/impl/codegen/log.h
index aa86fc4c17..e5010c29da 100644
--- a/include/grpc/impl/codegen/log.h
+++ b/include/grpc/impl/codegen/log.h
@@ -34,6 +34,7 @@
#ifndef GRPC_IMPL_CODEGEN_LOG_H
#define GRPC_IMPL_CODEGEN_LOG_H
+#include <inttypes.h>
#include <stdarg.h>
#include <stdlib.h> /* for abort() */
@@ -74,7 +75,7 @@ const char *gpr_log_severity_string(gpr_log_severity severity);
/* Log a message. It's advised to use GPR_xxx above to generate the context
* for each message */
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity,
- const char *format, ...);
+ const char *format, ...) GPRC_PRINT_FORMAT_CHECK(4, 5);
GPRAPI void gpr_log_message(const char *file, int line,
gpr_log_severity severity, const char *message);
diff --git a/include/grpc/impl/codegen/port_platform.h b/include/grpc/impl/codegen/port_platform.h
index 7fff36cb78..9640ab6008 100644
--- a/include/grpc/impl/codegen/port_platform.h
+++ b/include/grpc/impl/codegen/port_platform.h
@@ -434,6 +434,15 @@ typedef unsigned __int64 uint64_t;
#endif
#endif
+#ifndef GPRC_PRINT_FORMAT_CHECK
+#ifdef __GNUC__
+#define GPRC_PRINT_FORMAT_CHECK(FORMAT_STR, ARGS) \
+ __attribute__((format(printf, FORMAT_STR, ARGS)))
+#else
+#define GPRC_PRINT_FORMAT_CHECK(FORMAT_STR, ARGS)
+#endif
+#endif /* GPRC_PRINT_FORMAT_CHECK */
+
#if GPR_FORBID_UNREACHABLE_CODE
#define GPR_UNREACHABLE_CODE(STATEMENT)
#else
diff --git a/include/grpc/support/string_util.h b/include/grpc/support/string_util.h
index f981bc0db0..952cbfc26b 100644
--- a/include/grpc/support/string_util.h
+++ b/include/grpc/support/string_util.h
@@ -54,7 +54,8 @@ GPRAPI char *gpr_strdup(const char *src);
On error, returns -1 and sets *strp to NULL. If the format string is bad,
the result is undefined. */
-GPRAPI int gpr_asprintf(char **strp, const char *format, ...);
+GPRAPI int gpr_asprintf(char **strp, const char *format, ...)
+ GPRC_PRINT_FORMAT_CHECK(2, 3);
#ifdef __cplusplus
}