Branch Coverage

deps/libgit2/src/buffer.c
Criterion Covered Total %
branch 215 598 35.9


line true false branch
32 36119 0 ENSURE_SIZE(buf, initial_size);
46 36073 ENSURE_SIZE(buf, initial_size);
0 46 ENSURE_SIZE(buf, initial_size);
43 0 30128 if (buf->ptr == git_buf__oom)
46 23696 6432 if (buf->asize == 0 && buf->size != 0) {
0 23696 if (buf->asize == 0 && buf->size != 0) {
51 2 30126 if (!target_size)
54 459 29669 if (target_size <= buf->asize)
57 23694 5975 if (buf->asize == 0) {
68 1180 4795 if ((new_size = (new_size << 1) - (new_size >> 1)) < target_size)
76 0 29669 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 29669 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 29669 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 31656 if (!buf) return;
130 20411 11245 if (buf->asize > 0 && buf->ptr != NULL && buf->ptr != git_buf__oom)
20411 0 if (buf->asize > 0 && buf->ptr != NULL && buf->ptr != git_buf__oom)
20411 0 if (buf->asize > 0 && buf->ptr != NULL && buf->ptr != git_buf__oom)
145 41 438 if (buf->ptr == NULL) {
146 41 0 assert(buf->size == 0 && buf->asize == 0);
0 41 assert(buf->size == 0 && buf->asize == 0);
148 95 343 } else if (buf->asize > buf->size)
156 647 13834 if (!buf->ptr) {
161 8486 5995 if (buf->asize > 0)
169 7583 11 if (len == 0 || data == NULL) {
0 7583 if (len == 0 || data == NULL) {
172 6417 1166 if (data != buf->ptr) {
173 0 6417 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, len, 1);
0 6417 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, len, 1);
174 6417 0 ENSURE_SIZE(buf, alloclen);
3637 2780 ENSURE_SIZE(buf, alloclen);
0 3637 ENSURE_SIZE(buf, alloclen);
179 7583 0 if (buf->asize > buf->size)
198 3133 0 return git_buf_set(buf, string, string ? strlen(string) : 0);
204 0 21430 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, 2);
0 21430 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, 2);
205 21430 0 ENSURE_SIZE(buf, new_size);
2285 19145 ENSURE_SIZE(buf, new_size);
0 2285 ENSURE_SIZE(buf, new_size);
214 0 16 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len);
0 16 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len);
215 0 16 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
0 16 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
216 16 0 ENSURE_SIZE(buf, new_size);
1 15 ENSURE_SIZE(buf, new_size);
0 1 ENSURE_SIZE(buf, new_size);
225 14414 636 if (len) {
228 0 14414 assert(data);
230 0 14414 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len);
0 14414 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len);
231 0 14414 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
0 14414 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
232 14414 0 ENSURE_SIZE(buf, new_size);
6385 8029 ENSURE_SIZE(buf, new_size);
0 6385 ENSURE_SIZE(buf, new_size);
242 0 8345 assert(string);
256 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&blocks, blocks, 1);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&blocks, blocks, 1);
257 0 0 GIT_ERROR_CHECK_ALLOC_MULTIPLY(&alloclen, blocks, 4);
0 0 GIT_ERROR_CHECK_ALLOC_MULTIPLY(&alloclen, blocks, 4);
258 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, buf->size);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, buf->size);
260 0 0 ENSURE_SIZE(buf, alloclen);
0 0 ENSURE_SIZE(buf, alloclen);
0 0 ENSURE_SIZE(buf, alloclen);
264 0 0 for (len -= extra; len > 0; len -= 3) {
275 0 0 if (extra > 0) {
277 0 0 b = (extra > 1) ? *read++ : 0;
281 0 0 *write++ = (extra > 1) ? base64_encode[(b & 0x0f) << 2] : '=';
317 0 0 if (len % 4) {
322 0 0 assert(len % 4 == 0);
323 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);
324 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
325 0 0 ENSURE_SIZE(buf, new_size);
0 0 ENSURE_SIZE(buf, new_size);
0 0 ENSURE_SIZE(buf, new_size);
327 0 0 for (i = 0; i < len; i += 4) {
328 0 0 if ((a = base64_decode[(unsigned char)base64[i]]) < 0 ||
0 0 if ((a = base64_decode[(unsigned char)base64[i]]) < 0 ||
329 0 0 (b = base64_decode[(unsigned char)base64[i+1]]) < 0 ||
330 0 0 (c = base64_decode[(unsigned char)base64[i+2]]) < 0 ||
355 0 2 GIT_ERROR_CHECK_ALLOC_MULTIPLY(&alloclen, blocks, 5);
0 2 GIT_ERROR_CHECK_ALLOC_MULTIPLY(&alloclen, blocks, 5);
356 0 2 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, buf->size);
0 2 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, buf->size);
357 0 2 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1);
0 2 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1);
359 2 0 ENSURE_SIZE(buf, alloclen);
0 2 ENSURE_SIZE(buf, alloclen);
0 0 ENSURE_SIZE(buf, alloclen);
361 8 2 while (len) {
366 32 6 for (i = 24; i >= 0; i -= 8) {
370 2 30 if (--len == 0)
374 40 8 for (i = 4; i >= 0; i--) {
381 40 8 for (i = 0; i < 5; i++)
418 0 0 if (base85_len % 5 ||
0 0 if (base85_len % 5 ||
424 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);
425 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
426 0 0 ENSURE_SIZE(buf, new_size);
0 0 ENSURE_SIZE(buf, new_size);
0 0 ENSURE_SIZE(buf, new_size);
428 0 0 while (output_len) {
435 0 0 if (--de < 0)
439 0 0 } while (--cnt);
442 0 0 if (--de < 0)
446 0 0 if (0xffffffff / 85 < acc ||
0 0 if (0xffffffff / 85 < acc ||
452 0 0 cnt = (output_len < 4) ? (int)output_len : 4;
457 0 0 } while (--cnt);
481 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);
482 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
483 0 0 ENSURE_SIZE(buf, new_size);
0 0 ENSURE_SIZE(buf, new_size);
0 0 ENSURE_SIZE(buf, new_size);
485 0 0 for (str_pos = 0; str_pos < str_len; buf->size++, str_pos++) {
486 0 0 if (str[str_pos] == '%' &&
0 0 if (str[str_pos] == '%' &&
487 0 0 str_len > str_pos + 2 &&
488 0 0 isxdigit(str[str_pos + 1]) &&
507 0 6271 GIT_ERROR_CHECK_ALLOC_MULTIPLY(&expected_size, strlen(format), 2);
0 6271 GIT_ERROR_CHECK_ALLOC_MULTIPLY(&expected_size, strlen(format), 2);
508 0 6271 GIT_ERROR_CHECK_ALLOC_ADD(&expected_size, expected_size, buf->size);
0 6271 GIT_ERROR_CHECK_ALLOC_ADD(&expected_size, expected_size, buf->size);
509 6271 0 ENSURE_SIZE(buf, expected_size);
865 5406 ENSURE_SIZE(buf, expected_size);
0 865 ENSURE_SIZE(buf, expected_size);
523 0 6620 if (len < 0) {
529 6271 349 if ((size_t)len + 1 <= buf->asize - buf->size) {
534 0 349 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len);
0 349 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len);
535 0 349 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
0 349 GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
536 349 0 ENSURE_SIZE(buf, new_size);
349 0 ENSURE_SIZE(buf, new_size);
0 349 ENSURE_SIZE(buf, new_size);
558 1104 0 assert(data && datasize && buf);
1104 0 assert(data && datasize && buf);
0 1104 assert(data && datasize && buf);
562 1104 0 if (buf->size == 0 || buf->asize <= 0)
0 1104 if (buf->size == 0 || buf->asize <= 0)
566 0 1104 if (copylen > datasize - 1)
579 0 0 if (end > buf->ptr && end <= buf->ptr + buf->size) {
0 0 if (end > buf->ptr && end <= buf->ptr + buf->size) {
589 1642 3309 if (len >= buf->size)
593 3309 0 if (buf->size < buf->asize)
599 5 0 if (buf->size > amount)
622 2918 0 if (buf->asize == 0 || buf->ptr == git_buf__oom)
0 2918 if (buf->asize == 0 || buf->ptr == git_buf__oom)
634 9 58 if (ptr) {
637 2 7 if (asize)
638 0 2 buf->asize = (asize < buf->size) ? buf->size + 1 : asize;
643 67 0 ENSURE_SIZE(buf, asize);
0 67 ENSURE_SIZE(buf, asize);
0 0 ENSURE_SIZE(buf, asize);
649 0 107 if (git_buf_is_allocated(buf))
652 29 78 if (!size) {
668 0 0 if (buf->size > 0 && buf->ptr[buf->size - 1] != separator)
0 0 if (buf->size > 0 && buf->ptr[buf->size - 1] != separator)
674 0 0 for (i = 0; i < nbuf; ++i) {
678 0 0 segment = va_arg(ap, const char *);
679 0 0 if (!segment)
684 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);
686 0 0 if (segment_len == 0 || segment[segment_len - 1] != separator)
0 0 if (segment_len == 0 || segment[segment_len - 1] != separator)
687 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&total_size, total_size, 1);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&total_size, total_size, 1);
692 0 0 if (total_size == 0)
695 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&total_size, total_size, 1);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&total_size, total_size, 1);
696 0 0 if (git_buf_grow_by(buf, total_size) < 0)
702 0 0 if (buf->size > 0 && out[-1] != separator)
0 0 if (buf->size > 0 && out[-1] != separator)
706 0 0 for (i = 0; i < nbuf; ++i) {
710 0 0 segment = va_arg(ap, const char *);
711 0 0 if (!segment)
715 0 0 if (segment >= original && segment < original + original_size) {
0 0 if (segment >= original && segment < original + original_size) {
724 0 0 if (out > buf->ptr && out[-1] == separator)
0 0 if (out > buf->ptr && out[-1] == separator)
725 0 0 while (segment_len > 0 && *segment == separator) {
0 0 while (segment_len > 0 && *segment == separator) {
731 0 0 if (segment_len > 0) {
737 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)
755 15750 1 size_t strlen_a = str_a ? strlen(str_a) : 0;
762 5517 10234 if (buf->size)
763 4837 680 assert(str_b < buf->ptr || str_b >= buf->ptr + buf->size);
0 4837 assert(str_b < buf->ptr || str_b >= buf->ptr + buf->size);
766 15751 0 if (separator && strlen_a) {
14627 1124 if (separator && strlen_a) {
767 5 14627 while (*str_b == separator) { str_b++; strlen_b--; }
768 2951 11676 if (str_a[strlen_a - 1] != separator)
773 5517 10234 if (buf->size && str_a >= buf->ptr && str_a < buf->ptr + buf->size)
4043 1474 if (buf->size && str_a >= buf->ptr && str_a < buf->ptr + buf->size)
3421 622 if (buf->size && str_a >= buf->ptr && str_a < buf->ptr + buf->size)
776 0 15751 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, strlen_a, strlen_b);
0 15751 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, strlen_a, strlen_b);
777 0 15751 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, need_sep);
0 15751 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, need_sep);
778 0 15751 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 1);
0 15751 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 1);
779 15751 0 ENSURE_SIZE(buf, alloc_len);
11116 4635 ENSURE_SIZE(buf, alloc_len);
0 11116 ENSURE_SIZE(buf, alloc_len);
782 3421 12330 if (offset_a >= 0)
786 12330 3421 if (offset_a != 0 && str_a)
12329 1 if (offset_a != 0 && str_a)
788 2951 12800 if (need_sep)
813 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);
814 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);
815 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);
817 247 0 if (separator) {
818 247 0 if (len_a > 0) {
819 0 247 while (*str_b == separator) { str_b++; len_b--; }
822 0 247 if (len_a > 0 || len_b > 0)
0 0 if (len_a > 0 || len_b > 0)
823 0 247 while (*str_c == separator) { str_c++; len_c--; }
824 243 4 if (len_b > 0)
828 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);
829 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);
830 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);
831 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);
832 0 247 GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, 1);
0 247 GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, 1);
833 247 0 ENSURE_SIZE(buf, len_total);
247 0 ENSURE_SIZE(buf, len_total);
0 247 ENSURE_SIZE(buf, len_total);
837 247 0 if (len_a) {
841 0 247 if (sep_a)
843 243 4 if (len_b) {
847 0 247 if (sep_b)
849 247 0 if (len_c)
860 1410 0 while (buf->size > 0) {
861 766 644 if (!git__isspace(buf->ptr[buf->size - 1]))
867 766 0 if (buf->asize > buf->size)
874 0 0 return (result != 0) ? result :
875 0 0 (a->size < b->size) ? -1 : (a->size > b->size) ? 1 : 0;
888 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);
895 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);
896 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, new_size, 1);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, new_size, 1);
897 0 0 ENSURE_SIZE(buf, alloc_size);
0 0 ENSURE_SIZE(buf, alloc_size);
0 0 ENSURE_SIZE(buf, alloc_size);
920 50 0 if (buf->size && buf->ptr[0] == '!')
0 50 if (buf->size && buf->ptr[0] == '!')
923 526 0 for (i = 0; !quote && i < buf->size; i++) {
476 50 for (i = 0; !quote && i < buf->size; i++) {
924 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] == '\\' ||
925 0 476 buf->ptr[i] < ' ' || buf->ptr[i] > '~') {
931 50 0 if (!quote)
937 0 0 for (; i < buf->size; i++) {
939 0 0 if (buf->ptr[i] >= '\a' && buf->ptr[i] <= '\r') {
0 0 if (buf->ptr[i] >= '\a' && buf->ptr[i] <= '\r') {
945 0 0 else if (buf->ptr[i] == '"' || buf->ptr[i] == '\\') {
0 0 else if (buf->ptr[i] == '"' || buf->ptr[i] == '\\') {
951 0 0 else if (buf->ptr[i] != ' ' &&
0 0 else if (buf->ptr[i] != ' ' &&
952 0 0 (buf->ptr[i] < '!' || buf->ptr[i] > '~')) {
964 0 0 if (git_buf_oom("ed)) {
984 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] != '"')
987 0 0 for (i = 0, j = 1; j < buf->size-1; i++, j++) {
990 0 0 if (ch == '\\') {
991 0 0 if (j == buf->size-2)
1012 0 0 if (j == buf->size-3) {
1018 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' ||
1019 0 0 buf->ptr[j+2] < '0' || buf->ptr[j+2] > '7') {