Branch Coverage

json-create-perl.c
Criterion Covered Total %
branch 325 982 33.1


line true false branch
174 2 13 if (jc->fatal_errors) {
196 0 79 if (jc->length == 0) {
197 0 0 if (jc->output == 0) {
204 79 0 if (! jc->output) {
225 0 1278 CHECKLENGTH;
0 0 CHECKLENGTH;
0 0 CHECKLENGTH;
0 0 CHECKLENGTH;
262 0 73 if (slen < MARGIN || slen < BUFSIZE - jc->length) {
0 0 if (slen < MARGIN || slen < BUFSIZE - jc->length) {
263 314 73 for (i = 0; i < slen; i++) {
267 0 73 CHECKLENGTH;
0 0 CHECKLENGTH;
0 0 CHECKLENGTH;
0 0 CHECKLENGTH;
272 0 0 for (i = 0; i < slen; i++) {
273 0 0 CALL (add_char (jc, (unsigned char) s[i]));
0 0 CALL (add_char (jc, (unsigned char) s[i]));
0 0 CALL (add_char (jc, (unsigned char) s[i]));
294 6 39 if (jc->unicode_upper) {
309 0 45 CHECKLENGTH;
0 0 CHECKLENGTH;
0 0 CHECKLENGTH;
0 0 CHECKLENGTH;
318 9 12 if (u > 0xffff) {
322 0 9 if (status != UNICODE_OK) {
323 0 0 if (JCEH) {
330 0 9 CALL (add_one_u (jc, hi));
0 0 CALL (add_one_u (jc, hi));
0 0 CALL (add_one_u (jc, hi));
465 0 62 CALL (add_char (jc, '"'));
0 0 CALL (add_char (jc, '"'));
0 0 CALL (add_char (jc, '"'));
466 112 59 for (i = 0; i < keylen; ) {
471 0 5 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
0 2 ASCII;
0 0 ASCII;
0 0 ASCII;
0 1 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
0 1 ASCII;
0 0 ASCII;
0 0 ASCII;
0 100 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
480 0 59 CALL (add_char (jc, '"'));
0 0 CALL (add_char (jc, '"'));
0 0 CALL (add_char (jc, '"'));
493 0 131 CALL (add_char (jc, '"'));
0 0 CALL (add_char (jc, '"'));
0 0 CALL (add_char (jc, '"'));
494 396 130 for (i = 0; i < keylen; ) {
500 0 2 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
0 2 ASCII;
0 0 ASCII;
0 0 ASCII;
0 1 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
0 1 ASCII;
0 0 ASCII;
0 0 ASCII;
0 320 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
4 8 ASCII;
0 4 ASCII;
0 0 ASCII;
0 0 ASCII;
0 8 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
0 0 ASCII;
503 2 1 BADUTF8;
0 2 BADUTF8;
0 0 BADUTF8;
0 0 BADUTF8;
509 5 0 if (d < 0x80 || d > 0xBF) {
0 5 if (d < 0x80 || d > 0xBF) {
510 0 0 BADUTF8;
0 0 BADUTF8;
0 0 BADUTF8;
0 0 BADUTF8;
514 4 1 if (jc->unicode_escape_all) {
518 0 4 CALL (add_u (jc, u));
0 0 CALL (add_u (jc, u));
0 0 CALL (add_u (jc, u));
521 0 1 CALL (add_str_len (jc, (const char *) key + i, 2));
0 0 CALL (add_str_len (jc, (const char *) key + i, 2));
0 0 CALL (add_str_len (jc, (const char *) key + i, 2));
530 35 0 if (d < 0x80 || d > 0xBF ||
35 0 if (d < 0x80 || d > 0xBF ||
35 0 if (d < 0x80 || d > 0xBF ||
531 0 35 e < 0x80 || e > 0xBF) {
532 0 0 BADUTF8;
0 0 BADUTF8;
0 0 BADUTF8;
0 0 BADUTF8;
536 33 2 if (! jc->no_javascript_safe &&
10 23 if (! jc->no_javascript_safe &&
537 8 2 c == 0xe2 && d == 0x80 &&
4 4 c == 0xe2 && d == 0x80 &&
538 4 0 (e == 0xa8 || e == 0xa9)) {
539 0 8 CALL (add_one_u (jc, 0x2028 + e - 0xa8));
0 0 CALL (add_one_u (jc, 0x2028 + e - 0xa8));
0 0 CALL (add_one_u (jc, 0x2028 + e - 0xa8));
542 8 19 if (jc->unicode_escape_all) {
547 0 8 CALL (add_u (jc, u));
0 0 CALL (add_u (jc, u));
0 0 CALL (add_u (jc, u));
550 0 19 CALL (add_str_len (jc, (const char *) key + i, 3));
0 0 CALL (add_str_len (jc, (const char *) key + i, 3));
0 0 CALL (add_str_len (jc, (const char *) key + i, 3));
561 15 0 if (
566 15 0 (c < 0xf4 &&
567 15 0 (d < 0x80 || d > 0xBF ||
15 0 (d < 0x80 || d > 0xBF ||
568 15 0 e < 0x80 || e > 0xBF ||
15 0 e < 0x80 || e > 0xBF ||
569 15 0 f < 0x80 || f > 0xBF))
570 0 15 ||
572 0 0 (c == 0xf4 &&
573 0 0 (d < 0x80 || d > 0x8F ||
0 0 (d < 0x80 || d > 0x8F ||
574 0 0 e < 0x80 || e > 0xBF ||
0 0 e < 0x80 || e > 0xBF ||
575 0 0 f < 0x80 || f > 0xBF))
577 0 0 BADUTF8;
0 0 BADUTF8;
0 0 BADUTF8;
0 0 BADUTF8;
581 9 6 if (jc->unicode_escape_all) {
592 0 6 CALL (add_str_len (jc, (const char *) key + i, 4));
0 0 CALL (add_str_len (jc, (const char *) key + i, 4));
0 0 CALL (add_str_len (jc, (const char *) key + i, 4));
599 0 130 CALL (add_char (jc, '"'));
0 0 CALL (add_char (jc, '"'));
0 0 CALL (add_char (jc, '"'));
608 64 0 istring = SvPV (input, ilength);
609 19 45 if (SvUTF8 (input)) {
616 17 28 else if (jc->strict) {
639 93 0 iv = SvIV (sv);
649 10 83 if (iv < 0) {
654 32 61 if (iv < 10) {
659 7 54 else if (iv < 100) {
666 6 48 else if (iv < 1000) {
676 8 40 else if (iv < 10000) {
687 6 34 else if (iv < 100000) {
699 6 28 else if (iv < 1000000) {
713 12 16 else if (iv < 10000000) {
729 6 10 else if (iv < 100000000) {
747 8 2 else if (iv < 1000000000) {
771 0 2 if (ivlen >= MARGIN) {
772 0 0 if (JCEH) {
773 0 0 (*JCEH) (__FILE__, __LINE__,
782 0 93 CHECKLENGTH;
0 0 CHECKLENGTH;
0 0 CHECKLENGTH;
0 0 CHECKLENGTH;
802 0 2 PUSHMARK (SP);
803 0 2 XPUSHs (sv_2mortal (newSVsv (json)));
807 2 0 FREETMPS;
810 0 2 if (! error) {
813 0 2 if (SvOK (error) && SvCUR (error) > 0) {
0 0 if (SvOK (error) && SvCUR (error) > 0) {
0 0 if (SvOK (error) && SvCUR (error) > 0) {
1 1 if (SvOK (error) && SvCUR (error) > 0) {
814 1 0 json_create_user_message (jc, json_create_invalid_user_json,
1 0 json_create_user_message (jc, json_create_invalid_user_json,
834 0 14 PUSHMARK (SP);
836 0 14 XPUSHs (sv_2mortal (newRV (r)));
841 14 0 FREETMPS;
844 3 11 if (! SvOK (json)) {
3 0 if (! SvOK (json)) {
3 0 if (! SvOK (json)) {
851 0 11 if (SvUTF8 (json)) {
856 11 0 jsonc = SvPV (json, jsonl);
857 2 9 if (jc->validate) {
858 1 1 CALL (json_create_validate_user_json (jc, json));
1 0 CALL (json_create_validate_user_json (jc, json));
0 0 CALL (json_create_validate_user_json (jc, json));
864 0 10 CALL (add_str_len (jc, jsonc, jsonl));
0 0 CALL (add_str_len (jc, jsonc, jsonl));
0 0 CALL (add_str_len (jc, jsonc, jsonl));
874 84 0 fv = SvNV (sv);
875 75 9 if (isfinite (fv)) {
876 57 18 if (jc->fformat) {
883 0 75 if (fvlen >= MARGIN) {
887 0 75 CHECKLENGTH;
0 0 CHECKLENGTH;
0 0 CHECKLENGTH;
0 0 CHECKLENGTH;
890 3 6 if (jc->non_finite_handler) {
891 0 3 CALL (json_create_call_to_json (jc, jc->non_finite_handler, sv));
0 0 CALL (json_create_call_to_json (jc, jc->non_finite_handler, sv));
0 0 CALL (json_create_call_to_json (jc, jc->non_finite_handler, sv));
894 3 3 if (jc->strict) {
899 1 2 if (isnan (fv)) {
900 0 1 ADD ("\"nan\"");
0 0 ADD ("\"nan\"");
0 0 ADD ("\"nan\"");
902 2 0 else if (isinf (fv)) {
903 1 1 if (fv < 0.0) {
904 0 1 ADD ("\"-inf\"");
0 0 ADD ("\"-inf\"");
0 0 ADD ("\"-inf\"");
907 0 1 ADD ("\"inf\"");
0 0 ADD ("\"inf\"");
0 0 ADD ("\"inf\"");
928 1 0 s = SvPV (r, rlen);
933 1 0 if (s[0] == '0' && rlen > 1 && isdigit (s[1])) {
1 0 if (s[0] == '0' && rlen > 1 && isdigit (s[1])) {
1 0 if (s[0] == '0' && rlen > 1 && isdigit (s[1])) {
934 0 1 CALL (add_char (jc, '"'));
0 0 CALL (add_char (jc, '"'));
0 0 CALL (add_char (jc, '"'));
935 0 1 CALL (add_str_len (jc, s, (unsigned int) rlen));
0 0 CALL (add_str_len (jc, s, (unsigned int) rlen));
0 0 CALL (add_str_len (jc, s, (unsigned int) rlen));
936 0 1 CALL (add_char (jc, '"'));
0 0 CALL (add_char (jc, '"'));
0 0 CALL (add_char (jc, '"'));
968 0 55 CALL (add_char (jc, '{'));
0 0 CALL (add_char (jc, '{'));
0 0 CALL (add_char (jc, '{'));
970 129 46 for (i = 0; i < n_keys; i++) {
982 75 54 COMMA;
0 75 COMMA;
0 0 COMMA;
0 0 COMMA;
983 0 129 if (HeUTF8 (he)) {
4 125 if (HeUTF8 (he)) {
985 0 4 CALL (json_create_add_key_len (jc, (const unsigned char *) key,
0 0 CALL (json_create_add_key_len (jc, (const unsigned char *) key,
0 0 CALL (json_create_add_key_len (jc, (const unsigned char *) key,
988 45 80 else if (jc->strict) {
989 2 43 CALL (json_create_add_ascii_key_len (jc, (unsigned char *) key,
2 0 CALL (json_create_add_ascii_key_len (jc, (unsigned char *) key,
0 0 CALL (json_create_add_ascii_key_len (jc, (unsigned char *) key,
993 0 80 CALL (json_create_add_key_len (jc, (const unsigned char *) key,
0 0 CALL (json_create_add_key_len (jc, (const unsigned char *) key,
0 0 CALL (json_create_add_key_len (jc, (const unsigned char *) key,
996 0 127 CALL (add_char (jc, ':'));
0 0 CALL (add_char (jc, ':'));
0 0 CALL (add_char (jc, ':'));
1000 7 120 CALL (json_create_recursively (jc, value));
7 0 CALL (json_create_recursively (jc, value));
0 0 CALL (json_create_recursively (jc, value));
1002 0 46 CALL (add_char (jc, '}'));
0 0 CALL (add_char (jc, '}'));
0 0 CALL (add_char (jc, '}'));
1020 0 27 CALL (add_char (jc, '['));
0 0 CALL (add_char (jc, '['));
0 0 CALL (add_char (jc, '['));
1028 137 26 for (i = 0; i < n_keys; i++) {
1032 110 27 COMMA;
0 110 COMMA;
0 0 COMMA;
0 0 COMMA;
1037 137 0 if (avv) {
1046 1 136 CALL (json_create_recursively (jc, value));
1 0 CALL (json_create_recursively (jc, value));
0 0 CALL (json_create_recursively (jc, value));
1051 0 26 CALL (add_char (jc, ']'));
0 0 CALL (add_char (jc, ']'));
0 0 CALL (add_char (jc, ']'));
1059 2 3 if (jc->type_handler) {
1060 1 1 CALL (json_create_call_to_json (jc, jc->type_handler, r));
1 0 CALL (json_create_call_to_json (jc, jc->type_handler, r));
0 0 CALL (json_create_call_to_json (jc, jc->type_handler, r));
1091 1 26 CALL (json_create_add_array (jc, (AV *) r));
1 0 CALL (json_create_add_array (jc, (AV *) r));
0 0 CALL (json_create_add_array (jc, (AV *) r));
1098 9 46 CALL (json_create_add_object (jc, (HV *) r));
9 0 CALL (json_create_add_object (jc, (HV *) r));
0 0 CALL (json_create_add_object (jc, (HV *) r));
1106 0 0 STRICT_NO_SCALAR;
1107 0 0 CALL (json_create_add_float (jc, r));
0 0 CALL (json_create_add_float (jc, r));
0 0 CALL (json_create_add_float (jc, r));
1115 1 1 STRICT_NO_SCALAR;
1116 0 1 CALL (json_create_add_integer (jc, r));
0 0 CALL (json_create_add_integer (jc, r));
0 0 CALL (json_create_add_integer (jc, r));
1120 1 1 STRICT_NO_SCALAR;
1121 0 1 CALL (json_create_add_string (jc, r));
0 0 CALL (json_create_add_string (jc, r));
0 0 CALL (json_create_add_string (jc, r));
1125 0 2 STRICT_NO_SCALAR;
1128 0 2 if (SvIOK (r)) {
1129 0 0 CALL (json_create_add_integer (jc, r));
0 0 CALL (json_create_add_integer (jc, r));
0 0 CALL (json_create_add_integer (jc, r));
1131 0 2 else if (SvNOK (r)) {
1132 0 0 CALL (json_create_add_float (jc, r));
0 0 CALL (json_create_add_float (jc, r));
0 0 CALL (json_create_add_float (jc, r));
1135 0 2 CALL (json_create_add_string (jc, r));
0 0 CALL (json_create_add_string (jc, r));
0 0 CALL (json_create_add_string (jc, r));
1141 4 1 CALL (json_create_handle_unknown_type (jc, r));
4 0 CALL (json_create_handle_unknown_type (jc, r));
0 0 CALL (json_create_handle_unknown_type (jc, r));
1169 18 0 if (objtype) {
1170 1 17 if (jc->obj_handler) {
1171 1 0 CALL (json_create_call_to_json (jc, jc->obj_handler, r));
1 0 CALL (json_create_call_to_json (jc, jc->obj_handler, r));
0 0 CALL (json_create_call_to_json (jc, jc->obj_handler, r));
1181 17 0 if (sv_ptr) {
1184 9 8 pv = SvPV (*sv_ptr, pvlen);
1188 9 8 if (pvlen == strlen ("bool") &&
9 0 if (pvlen == strlen ("bool") &&
1190 9 0 if (SvTRUE (r)) {
0 9 if (SvTRUE (r)) {
0 0 if (SvTRUE (r)) {
1 8 if (SvTRUE (r)) {
1 0 if (SvTRUE (r)) {
0 1 if (SvTRUE (r)) {
1 7 if (SvTRUE (r)) {
1 0 if (SvTRUE (r)) {
0 1 if (SvTRUE (r)) {
0 0 if (SvTRUE (r)) {
0 0 if (SvTRUE (r)) {
1 0 if (SvTRUE (r)) {
7 0 if (SvTRUE (r)) {
7 0 if (SvTRUE (r)) {
2 5 if (SvTRUE (r)) {
0 2 if (SvTRUE (r)) {
0 0 if (SvTRUE (r)) {
5 2 if (SvTRUE (r)) {
0 0 if (SvTRUE (r)) {
1191 0 6 ADD ("true");
0 0 ADD ("true");
0 0 ADD ("true");
1194 0 3 ADD ("false");
0 0 ADD ("false");
0 0 ADD ("false");
1197 8 0 else if (SvROK (*sv_ptr)) {
1200 8 0 switch (SvTYPE (what)) {
1202 2 6 CALL (json_create_call_to_json (jc, what, r));
2 0 CALL (json_create_call_to_json (jc, what, r));
0 0 CALL (json_create_call_to_json (jc, what, r));
1213 0 0 if (JCEH) {
1241 0 0 if (jc->strict) {
1244 0 0 CALL (json_create_handle_ref (jc, input));
0 0 CALL (json_create_handle_ref (jc, input));
0 0 CALL (json_create_handle_ref (jc, input));
1261 6 352 if (! SvOK (input)) {
6 0 if (! SvOK (input)) {
6 0 if (! SvOK (input)) {
1267 0 6 ADD ("null");
0 0 ADD ("null");
0 0 ADD ("null");
1272 2 350 if (input == &PL_sv_yes) {
1276 0 2 ADD ("true");
0 0 ADD ("true");
0 0 ADD ("true");
1279 2 348 if (input == &PL_sv_no) {
1283 0 2 ADD ("false");
0 0 ADD ("false");
0 0 ADD ("false");
1286 110 238 if (SvROK (input)) {
1292 23 87 if (sv_isobject (input)) {
1293 6 17 if (jc->handlers || jc->obj_handler) {
1 5 if (jc->handlers || jc->obj_handler) {
1294 3 15 CALL (json_create_handle_object (jc, input));
3 0 CALL (json_create_handle_object (jc, input));
0 0 CALL (json_create_handle_object (jc, input));
1296 1 4 else if (jc->strict) {
1303 0 4 CALL (json_create_handle_ref (jc, input));
0 0 CALL (json_create_handle_ref (jc, input));
0 0 CALL (json_create_handle_ref (jc, input));
1310 14 73 CALL (json_create_handle_ref (jc, input));
14 0 CALL (json_create_handle_ref (jc, input));
0 0 CALL (json_create_handle_ref (jc, input));
1324 0 0 ADD ("null");
0 0 ADD ("null");
0 0 ADD ("null");
1332 0 59 CALL (json_create_add_string (jc, r));
0 0 CALL (json_create_add_string (jc, r));
0 0 CALL (json_create_add_string (jc, r));
1339 0 92 CALL (json_create_add_integer (jc, r));
0 0 CALL (json_create_add_integer (jc, r));
0 0 CALL (json_create_add_integer (jc, r));
1347 3 74 CALL (json_create_add_float (jc, r));
3 0 CALL (json_create_add_float (jc, r));
0 0 CALL (json_create_add_float (jc, r));
1359 0 7 CALL (json_create_add_float (jc, r));
0 0 CALL (json_create_add_float (jc, r));
0 0 CALL (json_create_add_float (jc, r));
1368 0 1 CALL (json_create_add_stringified (jc, r));
0 0 CALL (json_create_add_stringified (jc, r));
0 0 CALL (json_create_add_stringified (jc, r));
1372 0 0 CALL (json_create_handle_unknown_type (jc, r));
0 0 CALL (json_create_handle_unknown_type (jc, r));
0 0 CALL (json_create_handle_unknown_type (jc, r));
1420 13 79 FINALCALL (json_create_recursively (jc, input));
13 0 FINALCALL (json_create_recursively (jc, input));
0 0 FINALCALL (json_create_recursively (jc, input));
0 13 FINALCALL (json_create_recursively (jc, input));
1422 0 79 FINALCALL (json_create_buffer_fill (jc));
0 0 FINALCALL (json_create_buffer_fill (jc));
0 0 FINALCALL (json_create_buffer_fill (jc));
0 0 FINALCALL (json_create_buffer_fill (jc));
1424 18 61 if (jc->unicode && ! jc->downgrade_utf8) {
18 0 if (jc->unicode && ! jc->downgrade_utf8) {
1425 0 18 if (jc->utf8_dangerous) {
1426 0 0 if (is_utf8_string ((U8 *) SvPV_nolen (jc->output), SvCUR (jc->output))) {
0 0 if (is_utf8_string ((U8 *) SvPV_nolen (jc->output), SvCUR (jc->output))) {
1489 2 20 if (jc->fformat) {
1504 0 4 CALL (json_create_free_fformat (jc));
0 0 CALL (json_create_free_fformat (jc));
0 0 CALL (json_create_free_fformat (jc));
1505 4 0 if (! SvTRUE (fformat)) {
0 4 if (! SvTRUE (fformat)) {
0 0 if (! SvTRUE (fformat)) {
0 4 if (! SvTRUE (fformat)) {
0 0 if (! SvTRUE (fformat)) {
0 0 if (! SvTRUE (fformat)) {
2 2 if (! SvTRUE (fformat)) {
2 0 if (! SvTRUE (fformat)) {
0 2 if (! SvTRUE (fformat)) {
0 0 if (! SvTRUE (fformat)) {
0 0 if (! SvTRUE (fformat)) {
0 2 if (! SvTRUE (fformat)) {
2 0 if (! SvTRUE (fformat)) {
2 0 if (! SvTRUE (fformat)) {
2 0 if (! SvTRUE (fformat)) {
0 2 if (! SvTRUE (fformat)) {
0 0 if (! SvTRUE (fformat)) {
2 0 if (! SvTRUE (fformat)) {
0 0 if (! SvTRUE (fformat)) {
1510 2 0 ff = SvPV (fformat, fflen);
1511 0 2 if (! strchr (ff, '%')) {
1516 8 2 for (i = 0; i < fflen; i++) {
1527 5 13 if (jc->handlers) {
1538 2 18 if (jc->type_handler) {
1549 1 18 if (jc->obj_handler) {
1560 1 18 if (jc->non_finite_handler) {
1571 0 18 CALL (json_create_free_fformat (jc));
0 0 CALL (json_create_free_fformat (jc));
0 0 CALL (json_create_free_fformat (jc));
1572 0 18 CALL (json_create_remove_handlers (jc));
0 0 CALL (json_create_remove_handlers (jc));
0 0 CALL (json_create_remove_handlers (jc));
1573 0 18 CALL (json_create_remove_type_handler (jc));
0 0 CALL (json_create_remove_type_handler (jc));
0 0 CALL (json_create_remove_type_handler (jc));
1574 0 18 CALL (json_create_remove_obj_handler (jc));
0 0 CALL (json_create_remove_obj_handler (jc));
0 0 CALL (json_create_remove_obj_handler (jc));
1575 0 18 CALL (json_create_remove_non_finite_handler (jc));
0 0 CALL (json_create_remove_non_finite_handler (jc));
0 0 CALL (json_create_remove_non_finite_handler (jc));
1580 0 18 if (jc->n_mallocs != 0) {