Browse Source

Adjusted tests

Sergey Lyubka 11 years ago
parent
commit
2e7585400c
2 changed files with 8 additions and 3 deletions
  1. 7 2
      frozen.c
  2. 1 1
      unit_test.c

+ 7 - 2
frozen.c

@@ -406,7 +406,9 @@ int json_emit_va(char *s, int s_len, const char *fmt, va_list ap) {
     switch (*fmt) {
       case '[': case ']': case '{': case '}': case ',': case ':':
       case ' ': case '\r': case '\n': case '\t':
-        if (s < end) *s = *fmt;
+        if (s < end) {
+          *s = *fmt;
+        }
         s++;
         break;
       case 'i':
@@ -448,7 +450,10 @@ int json_emit_va(char *s, int s_len, const char *fmt, va_list ap) {
     fmt++;
   }
 
-  if (s < end) *s = '\0';
+  // Best-effort to 0-terminate generated string
+  if (s < end) {
+    *s = '\0';
+  }
 
   return s - orig;
 }

+ 1 - 1
unit_test.c

@@ -217,7 +217,7 @@ static const char *test_emit(void) {
 
   ASSERT(json_emit(buf, sizeof(buf), "{v:[i,f,V]}",
          "foo", 3, (long) -123, 1.23, "true", 4) > 0);
-  ASSERT(json_emit(buf, 4, "{S:i}", "a", 12345) < 0);
+  ASSERT(json_emit(buf, 4, "{S:i}", "a", 12345) > 4);
   ASSERT(json_emit(buf, sizeof(buf), "{S:d}", "a", 12345) == 0);
 
   ASSERT(json_emit(buf, sizeof(buf), "{s:[i,T, F,N]}", "foo", (long) -7) > 0);