Branch Coverage

deps/libgit2/src/buffer.c
Criterion Covered Total %
branch 213 594 35.8


line true false branch
32 33829 0 ENSURE_SIZE(buf, initial_size);
46 33783 ENSURE_SIZE(buf, initial_size);
0 46 ENSURE_SIZE(buf, initial_size);
43 0 28187 if (buf->ptr == git_buf__oom)
46 22433 5754 if (buf->asize == 0 && buf->size != 0) {
0 22433 if (buf->asize == 0 && buf->size != 0) {
51 2 28185 if (!target_size)
54 418 27769 if (target_size <= buf->asize)
57 22431 5338 if (buf->asize == 0) {
68 1039 4299 if ((new_size = (new_size << 1) - (new_size >> 1)) < target_size)
76 0 27769 if (new_size < buf->size) {
77 0 0 if (mark_oom) {
78 0 0 if (buf->ptr && buf->ptr != git_buf__initbuf)
0 0 if (buf->ptr && buf->ptr != git_buf__initbuf)
89 0 27769 if (!new_ptr) {
90 0 0 if (mark_oom) {
91 0 0 if (buf->ptr && (buf->ptr != git_buf__initbuf))
0 0 if (buf->ptr && (buf->ptr != git_buf__initbuf))
102 0 27769 if (buf->size >= buf->asize)
118 0 18 if (GIT_ADD_SIZET_OVERFLOW(&newsize, buffer->size, additional_size)) {
0 18 if (GIT_ADD_SIZET_OVERFLOW(&newsize, buffer->size, additional_size)) {
128 584 29858 if (!buf) return;
130 19555 10303 if (buf->asize > 0 && buf->ptr != NULL && buf->ptr != git_buf__oom)
19555 0 if (buf->asize > 0 && buf->ptr != NULL && buf->ptr != git_buf__oom)
19555 0 if (buf->asize > 0 && buf->ptr != NULL && buf->ptr != git_buf__oom)
143 41 326 if (buf->ptr == NULL) {
144 41 0 assert(buf->size == 0 && buf->asize == 0);
0 41 assert(buf->size == 0 && buf->asize == 0);
146 71 255 } else if (buf->asize > buf->size)
154 647 13403 if (!buf->ptr) {
159 7997 6053 if (buf->asize > 0)
167 6891 11 if (len == 0 || data == NULL) {
0 6891 if (len == 0 || data == NULL) {
170 5828 1063 if (data != buf->ptr) {
171 0 5828 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, len, 1);
0 5828 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, len, 1);
172 5828 0 ENSURE_SIZE(buf, alloclen);
3229 2599 ENSURE_SIZE(buf, alloclen);
0 3229 ENSURE_SIZE(buf, alloclen);
177 6891 0 if (buf->asize > buf->size)
196 2839 0 return git_buf_set(buf, string, string ? strlen(string) : 0);
202 0 18389 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, 2);
0 18389 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, 2);
203 18389 0 ENSURE_SIZE(buf, new_size);
1902 16487 ENSURE_SIZE(buf, new_size);
0 1902 ENSURE_SIZE(buf, new_size);
212 0 16 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len);
0 16 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len);
213 0 16 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
0 16 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
214 16 0 ENSURE_SIZE(buf, new_size);
1 15 ENSURE_SIZE(buf, new_size);
0 1 ENSURE_SIZE(buf, new_size);
223 13464 636 if (len) {
226 0 13464 assert(data);
228 0 13464 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len);
0 13464 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len);
229 0 13464 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
0 13464 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
230 13464 0 ENSURE_SIZE(buf, new_size);
6047 7417 ENSURE_SIZE(buf, new_size);
0 6047 ENSURE_SIZE(buf, new_size);
240 0 7733 assert(string);
254 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&blocks, blocks, 1);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&blocks, blocks, 1);
255 0 0 GIT_ERROR_CHECK_ALLOC_MULTIPLY(&alloclen, blocks, 4);
0 0 GIT_ERROR_CHECK_ALLOC_MULTIPLY(&alloclen, blocks, 4);
256 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, buf->size);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, buf->size);
258 0 0 ENSURE_SIZE(buf, alloclen);
0 0 ENSURE_SIZE(buf, alloclen);
0 0 ENSURE_SIZE(buf, alloclen);
262 0 0 for (len -= extra; len > 0; len -= 3) {
273 0 0 if (extra > 0) {
275 0 0 b = (extra > 1) ? *read++ : 0;
279 0 0 *write++ = (extra > 1) ? base64_encode[(b & 0x0f) << 2] : '=';
315 0 0 if (len % 4) {
320 0 0 assert(len % 4 == 0);
321 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, (len / 4 * 3), buf->size);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, (len / 4 * 3), buf->size);
322 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
323 0 0 ENSURE_SIZE(buf, new_size);
0 0 ENSURE_SIZE(buf, new_size);
0 0 ENSURE_SIZE(buf, new_size);
325 0 0 for (i = 0; i < len; i += 4) {
326 0 0 if ((a = base64_decode[(unsigned char)base64[i]]) < 0 ||
0 0 if ((a = base64_decode[(unsigned char)base64[i]]) < 0 ||
327 0 0 (b = base64_decode[(unsigned char)base64[i+1]]) < 0 ||
328 0 0 (c = base64_decode[(unsigned char)base64[i+2]]) < 0 ||
353 0 2 GIT_ERROR_CHECK_ALLOC_MULTIPLY(&alloclen, blocks, 5);
0 2 GIT_ERROR_CHECK_ALLOC_MULTIPLY(&alloclen, blocks, 5);
354 0 2 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, buf->size);
0 2 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, buf->size);
355 0 2 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1);
0 2 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1);
357 2 0 ENSURE_SIZE(buf, alloclen);
0 2 ENSURE_SIZE(buf, alloclen);
0 0 ENSURE_SIZE(buf, alloclen);
359 8 2 while (len) {
364 32 6 for (i = 24; i >= 0; i -= 8) {
368 2 30 if (--len == 0)
372 40 8 for (i = 4; i >= 0; i--) {
379 40 8 for (i = 0; i < 5; i++)
416 0 0 if (base85_len % 5 ||
0 0 if (base85_len % 5 ||
422 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, output_len, buf->size);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, output_len, buf->size);
423 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
424 0 0 ENSURE_SIZE(buf, new_size);
0 0 ENSURE_SIZE(buf, new_size);
0 0 ENSURE_SIZE(buf, new_size);
426 0 0 while (output_len) {
433 0 0 if (--de < 0)
437 0 0 } while (--cnt);
440 0 0 if (--de < 0)
444 0 0 if (0xffffffff / 85 < acc ||
0 0 if (0xffffffff / 85 < acc ||
450 0 0 cnt = (output_len < 4) ? (int)output_len : 4;
455 0 0 } while (--cnt);
479 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, str_len);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, str_len);
480 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
481 0 0 ENSURE_SIZE(buf, new_size);
0 0 ENSURE_SIZE(buf, new_size);
0 0 ENSURE_SIZE(buf, new_size);
483 0 0 for (str_pos = 0; str_pos < str_len; buf->size++, str_pos++) {
484 0 0 if (str[str_pos] == '%' &&
0 0 if (str[str_pos] == '%' &&
485 0 0 str_len > str_pos + 2 &&
486 0 0 isxdigit(str[str_pos + 1]) &&
505 0 5901 GIT_ERROR_CHECK_ALLOC_MULTIPLY(&expected_size, strlen(format), 2);
0 5901 GIT_ERROR_CHECK_ALLOC_MULTIPLY(&expected_size, strlen(format), 2);
506 0 5901 GIT_ERROR_CHECK_ALLOC_ADD(&expected_size, expected_size, buf->size);
0 5901 GIT_ERROR_CHECK_ALLOC_ADD(&expected_size, expected_size, buf->size);
507 5901 0 ENSURE_SIZE(buf, expected_size);
865 5036 ENSURE_SIZE(buf, expected_size);
0 865 ENSURE_SIZE(buf, expected_size);
521 0 6250 if (len < 0) {
527 5901 349 if ((size_t)len + 1 <= buf->asize - buf->size) {
532 0 349 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len);
0 349 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len);
533 0 349 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
0 349 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
534 349 0 ENSURE_SIZE(buf, new_size);
349 0 ENSURE_SIZE(buf, new_size);
0 349 ENSURE_SIZE(buf, new_size);
556 1280 0 assert(data && datasize && buf);
1280 0 assert(data && datasize && buf);
0 1280 assert(data && datasize && buf);
560 1280 0 if (buf->size == 0 || buf->asize <= 0)
0 1280 if (buf->size == 0 || buf->asize <= 0)
564 0 1280 if (copylen > datasize - 1)
577 19 0 if (end > buf->ptr && end <= buf->ptr + buf->size) {
19 0 if (end > buf->ptr && end <= buf->ptr + buf->size) {
587 1818 3410 if (len >= buf->size)
591 3410 0 if (buf->size < buf->asize)
597 5 0 if (buf->size > amount)
620 2510 0 if (buf->asize == 0 || buf->ptr == git_buf__oom)
0 2510 if (buf->asize == 0 || buf->ptr == git_buf__oom)
632 8 40 if (ptr) {
635 2 6 if (asize)
636 0 2 buf->asize = (asize < buf->size) ? buf->size + 1 : asize;
641 48 0 ENSURE_SIZE(buf, asize);
0 48 ENSURE_SIZE(buf, asize);
0 0 ENSURE_SIZE(buf, asize);
647 0 107 if (git_buf_is_allocated(buf))
650 29 78 if (!size) {
666 0 0 if (buf->size > 0 && buf->ptr[buf->size - 1] != separator)
0 0 if (buf->size > 0 && buf->ptr[buf->size - 1] != separator)
672 0 0 for (i = 0; i < nbuf; ++i) {
676 0 0 segment = va_arg(ap, const char *);
677 0 0 if (!segment)
682 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&total_size, total_size, segment_len);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&total_size, total_size, segment_len);
684 0 0 if (segment_len == 0 || segment[segment_len - 1] != separator)
0 0 if (segment_len == 0 || segment[segment_len - 1] != separator)
685 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&total_size, total_size, 1);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&total_size, total_size, 1);
690 0 0 if (total_size == 0)
693 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&total_size, total_size, 1);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&total_size, total_size, 1);
694 0 0 if (git_buf_grow_by(buf, total_size) < 0)
700 0 0 if (buf->size > 0 && out[-1] != separator)
0 0 if (buf->size > 0 && out[-1] != separator)
704 0 0 for (i = 0; i < nbuf; ++i) {
708 0 0 segment = va_arg(ap, const char *);
709 0 0 if (!segment)
713 0 0 if (segment >= original && segment < original + original_size) {
0 0 if (segment >= original && segment < original + original_size) {
722 0 0 if (out > buf->ptr && out[-1] == separator)
0 0 if (out > buf->ptr && out[-1] == separator)
723 0 0 while (segment_len > 0 && *segment == separator) {
0 0 while (segment_len > 0 && *segment == separator) {
729 0 0 if (segment_len > 0) {
735 0 0 if (i < nbuf - 1 && out > buf->ptr && out[-1] != separator)
0 0 if (i < nbuf - 1 && out > buf->ptr && out[-1] != separator)
0 0 if (i < nbuf - 1 && out > buf->ptr && out[-1] != separator)
753 14947 1 size_t strlen_a = str_a ? strlen(str_a) : 0;
760 6050 8898 assert(str_b < buf->ptr || str_b >= buf->ptr + buf->size);
0 6050 assert(str_b < buf->ptr || str_b >= buf->ptr + buf->size);
763 14948 0 if (separator && strlen_a) {
13648 1300 if (separator && strlen_a) {
764 5 13648 while (*str_b == separator) { str_b++; strlen_b--; }
765 2822 10826 if (str_a[strlen_a - 1] != separator)
770 5567 9381 if (str_a >= buf->ptr && str_a < buf->ptr + buf->size)
3254 2313 if (str_a >= buf->ptr && str_a < buf->ptr + buf->size)
773 0 14948 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, strlen_a, strlen_b);
0 14948 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, strlen_a, strlen_b);
774 0 14948 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, need_sep);
0 14948 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, need_sep);
775 0 14948 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 1);
0 14948 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 1);
776 14948 0 ENSURE_SIZE(buf, alloc_len);
10452 4496 ENSURE_SIZE(buf, alloc_len);
0 10452 ENSURE_SIZE(buf, alloc_len);
779 3254 11694 if (offset_a >= 0)
783 11694 3254 if (offset_a != 0 && str_a)
11693 1 if (offset_a != 0 && str_a)
785 2822 12126 if (need_sep)
810 0 247 assert(str_a < buf->ptr || str_a >= buf->ptr + buf->size);
0 0 assert(str_a < buf->ptr || str_a >= buf->ptr + buf->size);
811 0 247 assert(str_b < buf->ptr || str_b >= buf->ptr + buf->size);
0 0 assert(str_b < buf->ptr || str_b >= buf->ptr + buf->size);
812 0 247 assert(str_c < buf->ptr || str_c >= buf->ptr + buf->size);
0 0 assert(str_c < buf->ptr || str_c >= buf->ptr + buf->size);
814 247 0 if (separator) {
815 247 0 if (len_a > 0) {
816 0 247 while (*str_b == separator) { str_b++; len_b--; }
819 0 247 if (len_a > 0 || len_b > 0)
0 0 if (len_a > 0 || len_b > 0)
820 0 247 while (*str_c == separator) { str_c++; len_c--; }
821 243 4 if (len_b > 0)
825 0 247 GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_a, sep_a);
0 247 GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_a, sep_a);
826 0 247 GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, len_b);
0 247 GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, len_b);
827 0 247 GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, sep_b);
0 247 GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, sep_b);
828 0 247 GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, len_c);
0 247 GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, len_c);
829 0 247 GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, 1);
0 247 GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, 1);
830 247 0 ENSURE_SIZE(buf, len_total);
247 0 ENSURE_SIZE(buf, len_total);
0 247 ENSURE_SIZE(buf, len_total);
834 247 0 if (len_a) {
838 0 247 if (sep_a)
840 243 4 if (len_b) {
844 0 247 if (sep_b)
846 247 0 if (len_c)
857 1462 0 while (buf->size > 0) {
858 792 670 if (!git__isspace(buf->ptr[buf->size - 1]))
864 792 0 if (buf->asize > buf->size)
871 0 0 return (result != 0) ? result :
872 0 0 (a->size < b->size) ? -1 : (a->size > b->size) ? 1 : 0;
885 0 0 assert(buf && where <= buf->size && nb_to_remove <= buf->size - where);
0 0 assert(buf && where <= buf->size && nb_to_remove <= buf->size - where);
0 0 assert(buf && where <= buf->size && nb_to_remove <= buf->size - where);
892 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, (buf->size - nb_to_remove), nb_to_insert);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, (buf->size - nb_to_remove), nb_to_insert);
893 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, new_size, 1);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, new_size, 1);
894 0 0 ENSURE_SIZE(buf, alloc_size);
0 0 ENSURE_SIZE(buf, alloc_size);
0 0 ENSURE_SIZE(buf, alloc_size);
917 50 0 if (buf->size && buf->ptr[0] == '!')
0 50 if (buf->size && buf->ptr[0] == '!')
920 526 0 for (i = 0; !quote && i < buf->size; i++) {
476 50 for (i = 0; !quote && i < buf->size; i++) {
921 476 0 if (buf->ptr[i] == '"' || buf->ptr[i] == '\\' ||
476 0 if (buf->ptr[i] == '"' || buf->ptr[i] == '\\' ||
476 0 if (buf->ptr[i] == '"' || buf->ptr[i] == '\\' ||
922 0 476 buf->ptr[i] < ' ' || buf->ptr[i] > '~') {
928 50 0 if (!quote)
934 0 0 for (; i < buf->size; i++) {
936 0 0 if (buf->ptr[i] >= '\a' && buf->ptr[i] <= '\r') {
0 0 if (buf->ptr[i] >= '\a' && buf->ptr[i] <= '\r') {
942 0 0 else if (buf->ptr[i] == '"' || buf->ptr[i] == '\\') {
0 0 else if (buf->ptr[i] == '"' || buf->ptr[i] == '\\') {
948 0 0 else if (buf->ptr[i] != ' ' &&
0 0 else if (buf->ptr[i] != ' ' &&
949 0 0 (buf->ptr[i] < '!' || buf->ptr[i] > '~')) {
961 0 0 if (git_buf_oom("ed)) {
981 0 0 if (buf->size < 2 || buf->ptr[0] != '"' || buf->ptr[buf->size-1] != '"')
0 0 if (buf->size < 2 || buf->ptr[0] != '"' || buf->ptr[buf->size-1] != '"')
0 0 if (buf->size < 2 || buf->ptr[0] != '"' || buf->ptr[buf->size-1] != '"')
984 0 0 for (i = 0, j = 1; j < buf->size-1; i++, j++) {
987 0 0 if (ch == '\\') {
988 0 0 if (j == buf->size-2)
1009 0 0 if (j == buf->size-3) {
1015 0 0 if (buf->ptr[j+1] < '0' || buf->ptr[j+1] > '7' ||
0 0 if (buf->ptr[j+1] < '0' || buf->ptr[j+1] > '7' ||
0 0 if (buf->ptr[j+1] < '0' || buf->ptr[j+1] > '7' ||
1016 0 0 buf->ptr[j+2] < '0' || buf->ptr[j+2] > '7') {