Coverage Report

Created: 2025-06-13 06:34

/src/perfetto/buildtools/lzma/C/7zBuf2.c
Line
Count
Source (jump to first uncovered line)
1
/* 7zBuf2.c -- Byte Buffer
2
2017-04-03 : Igor Pavlov : Public domain */
3
4
#include "Precomp.h"
5
6
#include <string.h>
7
8
#include "7zBuf.h"
9
10
void DynBuf_Construct(CDynBuf *p)
11
0
{
12
0
  p->data = 0;
13
0
  p->size = 0;
14
0
  p->pos = 0;
15
0
}
16
17
void DynBuf_SeekToBeg(CDynBuf *p)
18
0
{
19
0
  p->pos = 0;
20
0
}
21
22
int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAllocPtr alloc)
23
0
{
24
0
  if (size > p->size - p->pos)
25
0
  {
26
0
    size_t newSize = p->pos + size;
27
0
    Byte *data;
28
0
    newSize += newSize / 4;
29
0
    data = (Byte *)ISzAlloc_Alloc(alloc, newSize);
30
0
    if (!data)
31
0
      return 0;
32
0
    p->size = newSize;
33
0
    if (p->pos != 0)
34
0
      memcpy(data, p->data, p->pos);
35
0
    ISzAlloc_Free(alloc, p->data);
36
0
    p->data = data;
37
0
  }
38
0
  if (size != 0)
39
0
  {
40
0
    memcpy(p->data + p->pos, buf, size);
41
0
    p->pos += size;
42
0
  }
43
0
  return 1;
44
0
}
45
46
void DynBuf_Free(CDynBuf *p, ISzAllocPtr alloc)
47
0
{
48
0
  ISzAlloc_Free(alloc, p->data);
49
0
  p->data = 0;
50
0
  p->size = 0;
51
0
  p->pos = 0;
52
0
}