LibreOffice Module basic (master) 1
buffer.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
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 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <buffer.hxx>
21#include <basic/sberrors.hxx>
22
23namespace
24{
25const sal_uInt32 UP_LIMIT=0xFFFFFF00;
26
27template <class I, typename T> void write(I it, T n)
28{
29 *it = static_cast<sal_uInt8>(n & 0xFF);
30 // coverity[stray_semicolon : FALSE] - coverity parse error
31 if constexpr (sizeof(n) > 1)
32 {
33 for (std::size_t i = 1; i < sizeof(n); ++i)
34 {
35 n >>= 8;
36 *++it = static_cast<sal_uInt8>(n & 0xFF);
37 }
38 }
39}
40}
41
42template <typename T> void SbiBuffer::append(T n)
43{
44 if (m_aErrCode)
45 return;
46 if ((m_aBuf.size() + sizeof(n)) > UP_LIMIT)
47 {
49 m_aBuf.clear();
50 return;
51 }
52 write(std::back_inserter(m_aBuf), n);
53}
54
56void SbiBuffer::operator+=(sal_Int16 n) { append(n); }
58void SbiBuffer::operator+=(sal_uInt16 n) { append(n); }
59void SbiBuffer::operator+=(sal_uInt32 n) { append(n); }
60void SbiBuffer::operator+=(sal_Int32 n) { append(n); }
61
62// Patch of a Location
63
64void SbiBuffer::Patch( sal_uInt32 off, sal_uInt32 val )
65{
66 if (m_aErrCode)
67 return;
68 if ((off + sizeof(sal_uInt32)) <= GetSize())
69 write(m_aBuf.begin() + off, val);
70}
71
72// Forward References upon label and procedures
73// establish a linkage. The beginning of the linkage is at the passed parameter,
74// the end of the linkage is 0.
75
76void SbiBuffer::Chain( sal_uInt32 off )
77{
78 if (m_aErrCode)
79 return;
80 for (sal_uInt32 i = off; i;)
81 {
82 if ((i + sizeof(sal_uInt32)) > GetSize())
83 {
85 m_sErrMsg = "BACKCHAIN";
86 break;
87 }
88 auto ip = m_aBuf.begin() + i;
89 i = ip[0] | (ip[1] << 8) | (ip[2] << 16) | (ip[3] << 24);
90 write(ip, GetSize());
91 }
92}
93
94/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< sal_uInt8 > m_aBuf
Definition: buffer.hxx:30
void Chain(sal_uInt32)
Definition: buffer.cxx:76
void Patch(sal_uInt32, sal_uInt32)
Definition: buffer.cxx:64
OUString m_sErrMsg
Definition: buffer.hxx:32
sal_uInt32 GetSize() const
Definition: buffer.hxx:47
void append(T n)
Definition: buffer.cxx:42
void operator+=(sal_Int8)
Definition: buffer.cxx:55
ErrCode m_aErrCode
Definition: buffer.hxx:31
sal_Int64 n
int i
#define ERRCODE_BASIC_PROG_TOO_LARGE
Definition: sberrors.hxx:151
#define ERRCODE_BASIC_INTERNAL_ERROR
Definition: sberrors.hxx:33
unsigned char sal_uInt8
signed char sal_Int8