Coverage Report

Created: 2023-06-07 06:56

/src/ots/subprojects/woff2-1.0.2/src/woff2_out.cc
Line
Count
Source (jump to first uncovered line)
1
/* Copyright 2014 Google Inc. All Rights Reserved.
2
3
   Distributed under MIT license.
4
   See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
*/
6
7
/* Output buffer for WOFF2 decompression. */
8
9
#include <woff2/output.h>
10
11
using std::string;
12
13
namespace woff2 {
14
15
WOFF2StringOut::WOFF2StringOut(string* buf)
16
  : buf_(buf),
17
    max_size_(kDefaultMaxSize),
18
5.15k
    offset_(0) {}
19
20
56.8k
bool WOFF2StringOut::Write(const void *buf, size_t n) {
21
56.8k
  return Write(buf, offset_, n);
22
56.8k
}
23
24
65.6k
bool WOFF2StringOut::Write(const void *buf, size_t offset, size_t n) {
25
65.6k
  if (offset > max_size_ || n > max_size_ - offset) {
26
0
    return false;
27
0
  }
28
65.6k
  if (offset == buf_->size()) {
29
4.90k
    buf_->append(static_cast<const char*>(buf), n);
30
60.7k
  } else {
31
60.7k
    if (offset + n > buf_->size()) {
32
1.36k
      buf_->append(offset + n - buf_->size(), 0);
33
1.36k
    }
34
60.7k
    buf_->replace(offset, n, static_cast<const char*>(buf), n);
35
60.7k
  }
36
65.6k
  offset_ = std::max(offset_, offset + n);
37
38
65.6k
  return true;
39
65.6k
}
40
41
0
void WOFF2StringOut::SetMaxSize(size_t max_size) {
42
0
  max_size_ = max_size;
43
0
  if (offset_ > max_size_) {
44
0
    offset_ = max_size_;
45
0
  }
46
0
}
47
48
WOFF2MemoryOut::WOFF2MemoryOut(uint8_t* buf, size_t buf_size)
49
  : buf_(buf),
50
    buf_size_(buf_size),
51
0
    offset_(0) {}
52
53
0
bool WOFF2MemoryOut::Write(const void *buf, size_t n) {
54
0
  return Write(buf, offset_, n);
55
0
}
56
57
0
bool WOFF2MemoryOut::Write(const void *buf, size_t offset, size_t n) {
58
0
  if (offset > buf_size_ || n > buf_size_ - offset) {
59
0
    return false;
60
0
  }
61
0
  std::memcpy(buf_ + offset, buf, n);
62
0
  offset_ = std::max(offset_, offset + n);
63
64
0
  return true;
65
0
}
66
67
} // namespace woff2