null+****@clear*****
null+****@clear*****
2012年 5月 1日 (火) 11:33:51 JST
Susumu Yata 2012-05-01 11:33:51 +0900 (Tue, 01 May 2012)
New Revision: 597400cba62c3c0a77dd6441ca37f2e5df22154b
Log:
Fix format strings and their arguments.
Cast precisions to int.
Cast ssize_t to long long int and use GRN_FMT_LLD.
Cast size_t to unsigned long long int and use GRN_FMT_LLU.
Define GRN_FMT_INTXXD(U) for (u)intXX_t.
Use "%p" for pointers.
Modified files:
lib/com.c
lib/ctx.c
lib/ctx.h
lib/groonga_in.h
Modified: lib/com.c (+2 -2)
===================================================================
--- lib/com.c 2012-05-01 10:16:57 +0900 (52d2a39)
+++ lib/com.c 2012-05-01 11:33:51 +0900 (c65a53f)
@@ -729,8 +729,8 @@ grn_com_send(grn_ctx *ctx, grn_com *cs,
}
}
if (ret != whole_size) {
- GRN_LOG(ctx, GRN_LOG_ERROR, "sendmsg(%d): %d < %u",
- cs->fd, (int)ret, (unsigned int)whole_size);
+ GRN_LOG(ctx, GRN_LOG_ERROR, "sendmsg(%d): %" GRN_FMT_LLD " < %" GRN_FMT_LLU,
+ cs->fd, (long long int)ret, (unsigned long long int)whole_size);
}
return ctx->rc;
}
Modified: lib/ctx.c (+6 -4)
===================================================================
--- lib/ctx.c 2012-05-01 10:16:57 +0900 (1995d2b)
+++ lib/ctx.c 2012-05-01 11:33:51 +0900 (7b384d8)
@@ -1281,7 +1281,7 @@ grn_ctx_qe_exec(grn_ctx *ctx, const char *str, uint32_t str_len)
grn_text_unesc_tok(ctx, &buf, str, str + str_len, &tok_type);
if (GRN_TEXT_LEN(&buf)) {
ERR(GRN_INVALID_ARGUMENT, "invalid command name: %.*s",
- GRN_TEXT_LEN(&buf), GRN_TEXT_VALUE(&buf));
+ (int)GRN_TEXT_LEN(&buf), GRN_TEXT_VALUE(&buf));
}
}
exit :
@@ -1365,7 +1365,7 @@ grn_ctx_send(grn_ctx *ctx, const char *str, unsigned int str_len, int flags)
ctx->impl->mime_type = "application/json";
ctx->impl->output_type = GRN_CONTENT_JSON;
grn_timeval_now(ctx, &ctx->impl->tv);
- GRN_LOG(ctx, GRN_LOG_NONE, "%08x|>%.*s", (intptr_t)ctx, str_len, str);
+ GRN_LOG(ctx, GRN_LOG_NONE, "%p|>%.*s", ctx, str_len, str);
if (str_len && *str == '/') {
expr = grn_ctx_qe_exec_uri(ctx, str + 1, str_len - 1);
} else {
@@ -1819,7 +1819,7 @@ grn_ctx_free(grn_ctx *ctx, void *ptr,
int32_t *header = &((int32_t *)ptr)[-2];
if (header[0] >= GRN_CTX_N_SEGMENTS) {
- ERR(GRN_INVALID_ARGUMENT,"invalid ptr passed. ptr=%p seg=%zu", ptr, *header);
+ ERR(GRN_INVALID_ARGUMENT,"invalid ptr passed. ptr=%p seg=%d", ptr, *header);
goto exit;
}
/*
@@ -2116,7 +2116,9 @@ grn_calloc_default(grn_ctx *ctx, size_t size, const char* file, int line, const
grn_alloc_info_add(res);
} else {
if (!(res = calloc(size, 1))) {
- MERR("calloc fail (%d)=%p (%s:%d) <%d>", size, res, file, line, alloc_count);
+ MERR("calloc fail (%" GRN_FMT_LLU ")=%p (%s:%d) <%" GRN_FMT_LLU ">",
+ (unsigned long long int)size, res, file, line,
+ (unsigned long long int)alloc_count);
} else {
GRN_ADD_ALLOC_COUNT(1);
grn_alloc_info_add(res);
Modified: lib/ctx.h (+2 -1)
===================================================================
--- lib/ctx.h 2012-05-01 10:16:57 +0900 (eebea10)
+++ lib/ctx.h 2012-05-01 11:33:51 +0900 (6a58323)
@@ -410,7 +410,8 @@ extern grn_timeval grn_starttime;
grn_timeval_now(ctx, &tv);\
et = (uint64_t)(tv.tv_sec - ctx->impl->tv.tv_sec) * GRN_TIME_NSEC_PER_SEC\
+ (tv.tv_nsec - ctx->impl->tv.tv_nsec);\
- GRN_LOG(ctx, GRN_LOG_NONE, "%08x|" prefix "%015llu " format, (intptr_t)ctx, et, __VA_ARGS__);\
+ GRN_LOG(ctx, GRN_LOG_NONE, "%p|" prefix "%015" GRN_FMT_INT64U " " format,\
+ ctx, et, __VA_ARGS__);\
} while (0)
GRN_API grn_rc grn_timeval_now(grn_ctx *ctx, grn_timeval *tv);
Modified: lib/groonga_in.h (+28 -7)
===================================================================
--- lib/groonga_in.h 2012-05-01 10:16:57 +0900 (16455e4)
+++ lib/groonga_in.h 2012-05-01 11:33:51 +0900 (521aa20)
@@ -392,13 +392,34 @@ typedef int grn_cond;
#endif /* HAVE_PTHREAD_H */
/* format string for printf */
-#ifdef WIN32
-#define GRN_FMT_LLD "I64d"
-#define GRN_FMT_LLU "I64u"
-#else /* WIN32 */
-#define GRN_FMT_LLD "lld"
-#define GRN_FMT_LLU "llu"
-#endif /* WIN32 */
+#ifdef HAVE_INTTYPES_H
+# include <inttypes.h>
+# define GRN_FMT_INT32D PRId32
+# define GRN_FMT_INT32U PRIu32
+# define GRN_FMT_INT64D PRId64
+# define GRN_FMT_INT64U PRIu64
+# define GRN_FMT_LLD "lld"
+# define GRN_FMT_LLU "llu"
+#else /* HAVE_INTTYPES_H */
+# ifdef WIN32
+# define GRN_FMT_INT32D "I32d"
+# define GRN_FMT_INT32U "I32u"
+# define GRN_FMT_INT64D "I64d"
+# define GRN_FMT_INT64U "I64u"
+# define GRN_FMT_LLD "I64d"
+# define GRN_FMT_LLU "I64u"
+# else /* WIN32 */
+# define GRN_FMT_INT32D "d"
+# define GRN_FMT_INT32U "u"
+# ifdef __x86_64__
+# define GRN_FMT_INT64D "ld"
+# define GRN_FMT_INT64U "lu"
+# else /* __x86_64__ */
+# define GRN_FMT_INT64D "lld"
+# define GRN_FMT_INT64U "llu"
+# endif /* __x86_64__ */
+# endif /* WIN32 */
+#endif /* HAVE_INTTYPES_H */
#ifdef __GNUC__
# if (defined(__i386__) || defined(__x86_64__)) /* ATOMIC ADD */