[Groonga-commit] groonga/groonga at 4e835ea [master] windows: use _snprintf_s() on Windows

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Apr 16 00:11:57 JST 2015


Kouhei Sutou	2015-04-16 00:11:57 +0900 (Thu, 16 Apr 2015)

  New Revision: 4e835eaa281b243ec64de2d6cfbd00d9157a26b6
  https://github.com/groonga/groonga/commit/4e835eaa281b243ec64de2d6cfbd00d9157a26b6

  Message:
    windows: use _snprintf_s() on Windows

  Modified files:
    include/groonga/portability.h
    lib/ii.c
    lib/str.c
    lib/util.c

  Modified: include/groonga/portability.h (+8 -0)
===================================================================
--- include/groonga/portability.h    2015-04-16 00:03:24 +0900 (0d6686a)
+++ include/groonga/portability.h    2015-04-16 00:11:57 +0900 (bd76b5b)
@@ -105,4 +105,12 @@
   strncpy((dest), (src), (n))
 #endif /* WIN32 */
 
+#ifdef WIN32
+# define grn_snprintf(dest, dest_size, n, format, ...)          \
+  _snprintf_s((dest), (dest_size), (n), (format), __VA_ARGS__)
+#else /* WIN32 */
+# define grn_snprintf(dest, dest_size, n, format, ...)          \
+  snprintf((dest), (n), (format), __VA_ARGS__)
+#endif /* WIN32 */
+
 #endif /* GROONGA_PORTABILITY_H */

  Modified: lib/ii.c (+12 -3)
===================================================================
--- lib/ii.c    2015-04-16 00:03:24 +0900 (0904bc7)
+++ lib/ii.c    2015-04-16 00:11:57 +0900 (591b113)
@@ -2780,7 +2780,10 @@ buffer_merge(grn_ctx *ctx, grn_ii *ii, uint32_t seg, grn_hash *h,
 
           if (sb->header.chunk_size + S_SEGMENT <= (dcp - dc) + encsize) {
             int i;
-            char buf[255], *bufp;
+#define BUF_SIZE 255
+            char buf[BUF_SIZE], *bufp, *buf_end;
+            buf_end = buf + BUF_SIZE;
+#undef BUF_SIZE
             GRN_LOG(ctx, GRN_LOG_NOTICE,
                     "cs(%d)+(%d)=(%d)<=(%" GRN_FMT_LLD ")+(%d)=(%" GRN_FMT_LLD ")",
                     sb->header.chunk_size, S_SEGMENT, sb->header.chunk_size + S_SEGMENT,
@@ -2789,7 +2792,10 @@ buffer_merge(grn_ctx *ctx, grn_ii *ii, uint32_t seg, grn_hash *h,
               GRN_LOG(ctx, GRN_LOG_NOTICE, "rdv[%d] data_size=%d, flags=%d",
                       j, rdv[j].data_size, rdv[j].flags);
               for (i = 0, bufp = buf; i < rdv[j].data_size;) {
-                bufp += sprintf(bufp, " %d", rdv[j].data[i]);
+                bufp += grn_snprintf(bufp,
+                                     buf_end - buf,
+                                     buf_end - buf,
+                                     " %d", rdv[j].data[i]);
                 i++;
                 if (!(i % 32) || i == rdv[j].data_size) {
                   GRN_LOG(ctx, GRN_LOG_NOTICE, "rdv[%d].data[%d]%s", j, i, buf);
@@ -2802,7 +2808,10 @@ buffer_merge(grn_ctx *ctx, grn_ii *ii, uint32_t seg, grn_hash *h,
               GRN_LOG(ctx, GRN_LOG_NOTICE, "dv[%d] data_size=%d, flags=%d",
                       j, dv[j].data_size, dv[j].flags);
               for (i = 0, bufp = buf; i < dv[j].data_size;) {
-                bufp += sprintf(bufp, " %d", dv[j].data[i]);
+                bufp += grn_snprintf(bufp,
+                                     buf_end - buf,
+                                     buf_end - buf,
+                                     " %d", dv[j].data[i]);
                 i++;
                 if (!(i % 32) || i == dv[j].data_size) {
                   GRN_LOG(ctx, GRN_LOG_NOTICE, "dv[%d].data[%d]%s", j, i, buf);

  Modified: lib/str.c (+4 -1)
===================================================================
--- lib/str.c    2015-04-16 00:03:24 +0900 (e1f35fa)
+++ lib/str.c    2015-04-16 00:11:57 +0900 (b55ed23)
@@ -2087,7 +2087,10 @@ ftoa_(grn_ctx *ctx, grn_obj *buf, double d)
 #define DIGIT_NUMBER 15
   grn_bulk_reserve(ctx, buf, DIGIT_NUMBER + 1);
   curr = GRN_BULK_CURR(buf);
-  len = sprintf(curr, "%#.*g", DIGIT_NUMBER, d);
+  len = grn_snprintf(curr,
+                     DIGIT_NUMBER + 1,
+                     DIGIT_NUMBER + 1,
+                     "%#.*g", DIGIT_NUMBER, d);
 #undef DIGIT_NUMBER
   if (curr[len - 1] == '.') {
     GRN_BULK_INCR_LEN(buf, len);

  Modified: lib/util.c (+7 -2)
===================================================================
--- lib/util.c    2015-04-16 00:03:24 +0900 (767b7c2)
+++ lib/util.c    2015-04-16 00:11:57 +0900 (6ef00f5)
@@ -212,8 +212,13 @@ grn_inspect_type(grn_ctx *ctx, grn_obj *buf, unsigned char type)
     break;
   default:
     {
-      char type_in_hex[5]; /* "0xXX" */
-      sprintf(type_in_hex, "%#02x", type);
+#define TYPE_IN_HEX_SIZE 5 /* "0xXX" */
+      char type_in_hex[TYPE_IN_HEX_SIZE];
+      grn_snprintf(type_in_hex,
+                   TYPE_IN_HEX_SIZE,
+                   TYPE_IN_HEX_SIZE,
+                   "%#02x", type);
+#undef TYPE_IN_HEX_SIZE
       GRN_TEXT_PUTS(ctx, buf, "(unknown: ");
       GRN_TEXT_PUTS(ctx, buf, type_in_hex);
       GRN_TEXT_PUTS(ctx, buf, ")");
-------------- next part --------------
HTML����������������������������...
다운로드 



More information about the Groonga-commit mailing list
Back to archive index