1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <basic/sberrors.hxx>
25 const sal_uInt32 UP_LIMIT
=0xFFFFFF00;
27 template <class I
, typename T
> void write(I it
, T n
)
29 *it
= static_cast<sal_uInt8
>(n
& 0xFF);
30 // coverity[stray_semicolon : FALSE] - coverity parse error
31 if constexpr (sizeof(n
) > 1)
33 for (std::size_t i
= 1; i
< sizeof(n
); ++i
)
36 *++it
= static_cast<sal_uInt8
>(n
& 0xFF);
42 template <typename T
> void SbiBuffer::append(T n
)
46 if ((m_aBuf
.size() + sizeof(n
)) > UP_LIMIT
)
48 m_aErrCode
= ERRCODE_BASIC_PROG_TOO_LARGE
;
52 write(std::back_inserter(m_aBuf
), n
);
55 void SbiBuffer::operator+=(sal_Int8 n
) { append(n
); }
56 void SbiBuffer::operator+=(sal_Int16 n
) { append(n
); }
57 void SbiBuffer::operator+=(sal_uInt8 n
) { append(n
); }
58 void SbiBuffer::operator+=(sal_uInt16 n
) { append(n
); }
59 void SbiBuffer::operator+=(sal_uInt32 n
) { append(n
); }
60 void SbiBuffer::operator+=(sal_Int32 n
) { append(n
); }
62 // Patch of a Location
64 void SbiBuffer::Patch( sal_uInt32 off
, sal_uInt32 val
)
68 if ((off
+ sizeof(sal_uInt32
)) <= GetSize())
69 write(m_aBuf
.begin() + off
, val
);
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.
76 void SbiBuffer::Chain( sal_uInt32 off
)
80 for (sal_uInt32 i
= off
; i
;)
82 if ((i
+ sizeof(sal_uInt32
)) > GetSize())
84 m_aErrCode
= ERRCODE_BASIC_INTERNAL_ERROR
;
85 m_sErrMsg
= "BACKCHAIN";
88 auto ip
= m_aBuf
.begin() + i
;
89 i
= ip
[0] | (ip
[1] << 8) | (ip
[2] << 16) | (ip
[3] << 24);
94 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */