| 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 |
|
| 23 |
namespace |
| 24 |
{ |
| 25 |
const sal_uInt32 UP_LIMIT=0xFFFFFF00; |
| 26 |
|
| 27 |
template <class I, typename T> void write(I it, T n) |
| 28 |
{ |
| 29 |
*it = static_cast<sal_uInt8>(n & 0xFF); |
| 30 |
if constexpr (sizeof(n) > 1) |
| 31 |
{ |
| 32 |
for (std::size_t i = 1; i < sizeof(n); ++i) |
| 33 |
{ |
| 34 |
n >>= 8; |
| 35 |
*++it = static_cast<sal_uInt8>(n & 0xFF); |
| 36 |
} |
| 37 |
} |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
template <typename T> void SbiBuffer::append(T n) |
| 42 |
{ |
| 43 |
if (m_aErrCode) |
| 44 |
return; |
| 45 |
if ((m_aBuf.size() + sizeof(n)) > UP_LIMIT) |
| 46 |
{ |
| 47 |
m_aErrCode = ERRCODE_BASIC_PROG_TOO_LARGE; |
| 48 |
m_aBuf.clear(); |
| 49 |
return; |
| 50 |
} |
| 51 |
write(std::back_inserter(m_aBuf), n); |
| 52 |
} |
| 53 |
|
| 54 |
void SbiBuffer::operator+=(sal_Int8 n) { append(n); } |
| 55 |
void SbiBuffer::operator+=(sal_Int16 n) { append(n); } |
| 56 |
void SbiBuffer::operator+=(sal_uInt8 n) { append(n); } |
| 57 |
void SbiBuffer::operator+=(sal_uInt16 n) { append(n); } |
| 58 |
void SbiBuffer::operator+=(sal_uInt32 n) { append(n); } |
| 59 |
void SbiBuffer::operator+=(sal_Int32 n) { append(n); } |
| 60 |
|
| 61 |
// Patch of a Location |
| 62 |
|
| 63 |
void SbiBuffer::Patch( sal_uInt32 off, sal_uInt32 val ) |
| 64 |
{ |
| 65 |
if (m_aErrCode) |
| 66 |
return; |
| 67 |
if ((off + sizeof(sal_uInt32)) <= GetSize()) |
| 68 |
write(m_aBuf.begin() + off, val); |
| 69 |
} |
| 70 |
|
| 71 |
// Forward References upon label and procedures |
| 72 |
// establish a linkage. The beginning of the linkage is at the passed parameter, |
| 73 |
// the end of the linkage is 0. |
| 74 |
|
| 75 |
void SbiBuffer::Chain( sal_uInt32 off ) |
| 76 |
{ |
| 77 |
if (m_aErrCode) |
| 78 |
return; |
| 79 |
for (sal_uInt32 i = off; i;) |
| 80 |
{ |
| 81 |
if ((i + sizeof(sal_uInt32)) > GetSize()) |
| 82 |
{ |
| 83 |
m_aErrCode = ERRCODE_BASIC_INTERNAL_ERROR; |
| 84 |
m_sErrMsg = u"BACKCHAIN"_ustr; |
| 85 |
break; |
| 86 |
} |
| 87 |
auto ip = m_aBuf.begin() + i; |
| 88 |
i = ip[0] | (ip[1] << 8) | (ip[2] << 16) | (ip[3] << 24); |
| 89 |
write(ip, GetSize()); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |