[Groonga-commit] groonga/groonga at 2f4eb82 [master] Support formatted size is larger case

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Apr 16 00:35:09 JST 2015


Kouhei Sutou	2015-04-16 00:35:09 +0900 (Thu, 16 Apr 2015)

  New Revision: 2f4eb82d4f845a187b3af6190b02abd64307e1c4
  https://github.com/groonga/groonga/commit/2f4eb82d4f845a187b3af6190b02abd64307e1c4

  Message:
    Support formatted size is larger case

  Modified files:
    lib/str.c

  Modified: lib/str.c (+12 -3)
===================================================================
--- lib/str.c    2015-04-16 00:13:18 +0900 (b55ed23)
+++ lib/str.c    2015-04-16 00:35:09 +0900 (85f633a)
@@ -2085,12 +2085,21 @@ ftoa_(grn_ctx *ctx, grn_obj *buf, double d)
   char *curr;
   size_t len;
 #define DIGIT_NUMBER 15
-  grn_bulk_reserve(ctx, buf, DIGIT_NUMBER + 1);
+#define FIRST_BUFFER_SIZE (DIGIT_NUMBER + 3)
+  grn_bulk_reserve(ctx, buf, FIRST_BUFFER_SIZE);
   curr = GRN_BULK_CURR(buf);
   len = grn_snprintf(curr,
-                     DIGIT_NUMBER + 1,
-                     DIGIT_NUMBER + 1,
+                     FIRST_BUFFER_SIZE,
+                     FIRST_BUFFER_SIZE,
                      "%#.*g", DIGIT_NUMBER, d);
+  if (len >= FIRST_BUFFER_SIZE) {
+    grn_bulk_reserve(ctx, buf, len + 1);
+    curr = GRN_BULK_CURR(buf);
+    len = grn_snprintf(curr,
+                       len + 1,
+                       len + 1,
+                       "%#.*g", DIGIT_NUMBER, d);
+  }
 #undef DIGIT_NUMBER
   if (curr[len - 1] == '.') {
     GRN_BULK_INCR_LEN(buf, len);
-------------- next part --------------
HTML����������������������������...
Download 



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