Coverage Report

Created: 2026-03-12 06:42

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libwpd/src/lib/WPXMemoryStream.cpp
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2
/* libwpd
3
 * Version: MPL 2.0 / LGPLv2.1+
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * Major Contributor(s):
10
 * Copyright (C) 2004-2005 William Lachance (wrlach@gmail.com)
11
 * Copyright (C) 2006 Fridrich Strba (fridrich.strba@bluewin.ch)
12
 *
13
 * For minor contributions see the git repository.
14
 *
15
 * Alternatively, the contents of this file may be used under the terms
16
 * of the GNU Lesser General Public License Version 2.1 or later
17
 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
18
 * applicable instead of those above.
19
 *
20
 * For further information visit http://libwpd.sourceforge.net
21
 */
22
23
/* "This product is not manufactured, approved, or supported by
24
 * Corel Corporation or Corel Corporation Limited."
25
 */
26
27
#include "WPXMemoryStream.h"
28
#include "libwpd_internal.h"
29
30
31
WPXMemoryInputStream::WPXMemoryInputStream(unsigned char *data, unsigned long size) :
32
316k
  librevenge::RVNGInputStream(),
33
316k
  m_offset(0),
34
316k
  m_size(size),
35
316k
  m_data(data)
36
316k
{
37
316k
}
38
39
WPXMemoryInputStream::~WPXMemoryInputStream()
40
316k
{
41
316k
}
42
43
const unsigned char *WPXMemoryInputStream::read(unsigned long numBytes, unsigned long &numBytesRead)
44
436M
{
45
436M
  numBytesRead = 0;
46
47
436M
  if (numBytes == 0)
48
0
    return nullptr;
49
50
436M
  long numBytesToRead;
51
52
436M
  if ((m_offset+numBytes) < m_size)
53
435M
    numBytesToRead = numBytes;
54
712k
  else
55
712k
    numBytesToRead = m_size - m_offset;
56
57
436M
  numBytesRead = numBytesToRead; // about as paranoid as we can be..
58
59
436M
  if (numBytesToRead == 0)
60
65.7k
    return nullptr;
61
62
436M
  long oldOffset = m_offset;
63
436M
  m_offset += numBytesToRead;
64
65
436M
  return &m_data[oldOffset];
66
436M
}
67
68
int WPXMemoryInputStream::seek(long offset, librevenge::RVNG_SEEK_TYPE seekType)
69
40.0M
{
70
40.0M
  if (seekType == librevenge::RVNG_SEEK_CUR)
71
1.77M
    m_offset += offset;
72
38.2M
  else if (seekType == librevenge::RVNG_SEEK_SET)
73
38.2M
    m_offset = offset;
74
0
  else if (seekType == librevenge::RVNG_SEEK_END)
75
0
    m_offset = m_size+offset;
76
77
40.0M
  if (m_offset < 0)
78
0
  {
79
0
    m_offset = 0;
80
0
    return 1;
81
0
  }
82
40.0M
  if ((long)m_offset > (long)m_size)
83
10.6M
  {
84
10.6M
    m_offset = m_size;
85
10.6M
    return 1;
86
10.6M
  }
87
88
29.3M
  return 0;
89
40.0M
}
90
91
long WPXMemoryInputStream::tell()
92
19.4M
{
93
19.4M
  return m_offset;
94
19.4M
}
95
96
bool WPXMemoryInputStream::isEnd()
97
397M
{
98
397M
  if ((long)m_offset == (long)m_size)
99
663k
    return true;
100
101
397M
  return false;
102
397M
}
103
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */