File: | home/maarten/src/libreoffice/core/binaryurp/source/marshal.cxx |
Warning: | line 232, column 13 3rd function call argument is an uninitialized value |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 <sal/config.h> | |||
21 | ||||
22 | #include <cassert> | |||
23 | #include <vector> | |||
24 | ||||
25 | #include <com/sun/star/uno/RuntimeException.hpp> | |||
26 | #include <com/sun/star/uno/Sequence.hxx> | |||
27 | #include <cppu/unotype.hxx> | |||
28 | #include <rtl/byteseq.hxx> | |||
29 | #include <rtl/string.hxx> | |||
30 | #include <rtl/textcvt.h> | |||
31 | #include <rtl/textenc.h> | |||
32 | #include <rtl/ustring.h> | |||
33 | #include <rtl/ustring.hxx> | |||
34 | #include <sal/types.h> | |||
35 | #include <typelib/typeclass.h> | |||
36 | #include <typelib/typedescription.h> | |||
37 | #include <typelib/typedescription.hxx> | |||
38 | #include <uno/dispatcher.hxx> | |||
39 | ||||
40 | #include "binaryany.hxx" | |||
41 | #include "bridge.hxx" | |||
42 | #include "cache.hxx" | |||
43 | #include "lessoperators.hxx" | |||
44 | #include "marshal.hxx" | |||
45 | ||||
46 | namespace binaryurp { | |||
47 | ||||
48 | namespace { | |||
49 | ||||
50 | void write64(std::vector< unsigned char > * buffer, sal_uInt64 value) { | |||
51 | Marshal::write8(buffer, value >> 56); | |||
52 | Marshal::write8(buffer, (value >> 48) & 0xFF); | |||
53 | Marshal::write8(buffer, (value >> 40) & 0xFF); | |||
54 | Marshal::write8(buffer, (value >> 32) & 0xFF); | |||
55 | Marshal::write8(buffer, (value >> 24) & 0xFF); | |||
56 | Marshal::write8(buffer, (value >> 16) & 0xFF); | |||
57 | Marshal::write8(buffer, (value >> 8) & 0xFF); | |||
58 | Marshal::write8(buffer, value & 0xFF); | |||
59 | } | |||
60 | ||||
61 | void writeCompressed(std::vector< unsigned char > * buffer, sal_uInt32 value) { | |||
62 | if (value < 0xFF) { | |||
63 | Marshal::write8(buffer, static_cast< sal_uInt8 >(value)); | |||
64 | } else { | |||
65 | Marshal::write8(buffer, 0xFF); | |||
66 | Marshal::write32(buffer, value); | |||
67 | } | |||
68 | } | |||
69 | ||||
70 | void writeString( | |||
71 | std::vector< unsigned char > * buffer, OUString const & value) | |||
72 | { | |||
73 | assert(buffer != nullptr)(static_cast <bool> (buffer != nullptr) ? void (0) : __assert_fail ("buffer != nullptr", "/home/maarten/src/libreoffice/core/binaryurp/source/marshal.cxx" , 73, __extension__ __PRETTY_FUNCTION__)); | |||
74 | OString v; | |||
75 | if (!value.convertToString( | |||
76 | &v, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)), | |||
77 | (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR((sal_uInt32)0x0001) | | |||
78 | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR((sal_uInt32)0x0010)))) | |||
79 | { | |||
80 | throw css::uno::RuntimeException( | |||
81 | "UNO string contains invalid UTF-16 sequence"); | |||
82 | } | |||
83 | writeCompressed(buffer, static_cast< sal_uInt32 >(v.getLength())); | |||
84 | buffer->insert(buffer->end(), v.getStr(), v.getStr() + v.getLength()); | |||
85 | } | |||
86 | ||||
87 | } | |||
88 | ||||
89 | Marshal::Marshal(rtl::Reference< Bridge > const & bridge, WriterState & state): | |||
90 | bridge_(bridge), state_(state) | |||
91 | { | |||
92 | assert(bridge.is())(static_cast <bool> (bridge.is()) ? void (0) : __assert_fail ("bridge.is()", "/home/maarten/src/libreoffice/core/binaryurp/source/marshal.cxx" , 92, __extension__ __PRETTY_FUNCTION__)); | |||
93 | } | |||
94 | ||||
95 | Marshal::~Marshal() {} | |||
96 | ||||
97 | void Marshal::write8(std::vector< unsigned char > * buffer, sal_uInt8 value) { | |||
98 | assert(buffer != nullptr)(static_cast <bool> (buffer != nullptr) ? void (0) : __assert_fail ("buffer != nullptr", "/home/maarten/src/libreoffice/core/binaryurp/source/marshal.cxx" , 98, __extension__ __PRETTY_FUNCTION__)); | |||
99 | buffer->push_back(value); | |||
100 | } | |||
101 | ||||
102 | void Marshal::write16(std::vector< unsigned char > * buffer, sal_uInt16 value) { | |||
103 | write8(buffer, value >> 8); | |||
104 | write8(buffer, value & 0xFF); | |||
105 | } | |||
106 | ||||
107 | void Marshal::write32(std::vector< unsigned char > * buffer, sal_uInt32 value) { | |||
108 | write8(buffer, value >> 24); | |||
109 | write8(buffer, (value >> 16) & 0xFF); | |||
110 | write8(buffer, (value >> 8) & 0xFF); | |||
111 | write8(buffer, value & 0xFF); | |||
112 | } | |||
113 | ||||
114 | void Marshal::writeValue( | |||
115 | std::vector< unsigned char > * buffer, | |||
116 | css::uno::TypeDescription const & type, BinaryAny const & value) | |||
117 | { | |||
118 | assert((static_cast <bool> (type.is() && (type.get()-> eTypeClass == typelib_TypeClass_ANY || value.getType().equals (type))) ? void (0) : __assert_fail ("type.is() && (type.get()->eTypeClass == typelib_TypeClass_ANY || value.getType().equals(type))" , "/home/maarten/src/libreoffice/core/binaryurp/source/marshal.cxx" , 121, __extension__ __PRETTY_FUNCTION__)) | |||
119 | type.is() &&(static_cast <bool> (type.is() && (type.get()-> eTypeClass == typelib_TypeClass_ANY || value.getType().equals (type))) ? void (0) : __assert_fail ("type.is() && (type.get()->eTypeClass == typelib_TypeClass_ANY || value.getType().equals(type))" , "/home/maarten/src/libreoffice/core/binaryurp/source/marshal.cxx" , 121, __extension__ __PRETTY_FUNCTION__)) | |||
120 | (type.get()->eTypeClass == typelib_TypeClass_ANY ||(static_cast <bool> (type.is() && (type.get()-> eTypeClass == typelib_TypeClass_ANY || value.getType().equals (type))) ? void (0) : __assert_fail ("type.is() && (type.get()->eTypeClass == typelib_TypeClass_ANY || value.getType().equals(type))" , "/home/maarten/src/libreoffice/core/binaryurp/source/marshal.cxx" , 121, __extension__ __PRETTY_FUNCTION__)) | |||
121 | value.getType().equals(type)))(static_cast <bool> (type.is() && (type.get()-> eTypeClass == typelib_TypeClass_ANY || value.getType().equals (type))) ? void (0) : __assert_fail ("type.is() && (type.get()->eTypeClass == typelib_TypeClass_ANY || value.getType().equals(type))" , "/home/maarten/src/libreoffice/core/binaryurp/source/marshal.cxx" , 121, __extension__ __PRETTY_FUNCTION__)); | |||
122 | writeValue(buffer, type, value.getValue(type)); | |||
123 | } | |||
124 | ||||
125 | void Marshal::writeType( | |||
126 | std::vector< unsigned char > * buffer, | |||
127 | css::uno::TypeDescription const & value) | |||
128 | { | |||
129 | value.makeComplete(); | |||
130 | assert(value.is())(static_cast <bool> (value.is()) ? void (0) : __assert_fail ("value.is()", "/home/maarten/src/libreoffice/core/binaryurp/source/marshal.cxx" , 130, __extension__ __PRETTY_FUNCTION__)); | |||
131 | typelib_TypeClass tc = value.get()->eTypeClass; | |||
132 | if (tc <= typelib_TypeClass_ANY) { | |||
133 | write8(buffer, static_cast< sal_uInt8 >(tc)); | |||
134 | } else { | |||
135 | bool found; | |||
136 | sal_uInt16 idx = state_.typeCache.add(value, &found); | |||
137 | if (found) { | |||
138 | write8(buffer, static_cast< sal_uInt8 >(tc)); | |||
139 | write16(buffer, idx); | |||
140 | } else { | |||
141 | write8(buffer, static_cast< sal_uInt8 >(tc) | 0x80); | |||
142 | write16(buffer, idx); | |||
143 | writeString(buffer, OUString(value.get()->pTypeName)); | |||
144 | } | |||
145 | } | |||
146 | } | |||
147 | ||||
148 | void Marshal::writeOid( | |||
149 | std::vector< unsigned char > * buffer, OUString const & oid) | |||
150 | { | |||
151 | bool found; | |||
152 | sal_uInt16 idx; | |||
153 | if ( oid.isEmpty() ) { | |||
154 | found = true; | |||
155 | idx = cache::ignore; | |||
156 | } else { | |||
157 | idx = state_.oidCache.add(oid, &found); | |||
158 | } | |||
159 | if (found) { | |||
160 | write8(buffer, 0); | |||
161 | } else { | |||
162 | writeString(buffer, oid); | |||
163 | } | |||
164 | write16(buffer, idx); | |||
165 | } | |||
166 | ||||
167 | void Marshal::writeTid( | |||
168 | std::vector< unsigned char > * buffer, rtl::ByteSequence const & tid) | |||
169 | { | |||
170 | bool found; | |||
171 | sal_uInt16 idx = state_.tidCache.add(tid, &found); | |||
172 | if (found
| |||
| ||||
173 | write8(buffer, 0); | |||
174 | } else { | |||
175 | sal_Sequence * p = tid.getHandle(); | |||
176 | writeValue( | |||
177 | buffer, | |||
178 | css::uno::TypeDescription( | |||
179 | cppu::UnoType< css::uno::Sequence< sal_Int8 > >::get()), &p); | |||
180 | } | |||
181 | write16(buffer, idx); | |||
182 | } | |||
183 | ||||
184 | void Marshal::writeValue( | |||
185 | std::vector< unsigned char > * buffer, | |||
186 | css::uno::TypeDescription const & type, void const * value) | |||
187 | { | |||
188 | assert(buffer != nullptr && type.is())(static_cast <bool> (buffer != nullptr && type. is()) ? void (0) : __assert_fail ("buffer != nullptr && type.is()" , "/home/maarten/src/libreoffice/core/binaryurp/source/marshal.cxx" , 188, __extension__ __PRETTY_FUNCTION__)); | |||
189 | type.makeComplete(); | |||
190 | switch (type.get()->eTypeClass) { | |||
191 | case typelib_TypeClass_VOID: | |||
192 | break; | |||
193 | case typelib_TypeClass_BOOLEAN: | |||
194 | assert(*static_cast< sal_uInt8 const * >(value) <= 1)(static_cast <bool> (*static_cast< sal_uInt8 const * >(value) <= 1) ? void (0) : __assert_fail ("*static_cast< sal_uInt8 const * >(value) <= 1" , "/home/maarten/src/libreoffice/core/binaryurp/source/marshal.cxx" , 194, __extension__ __PRETTY_FUNCTION__)); | |||
195 | [[fallthrough]]; | |||
196 | case typelib_TypeClass_BYTE: | |||
197 | write8(buffer, *static_cast< sal_uInt8 const * >(value)); | |||
198 | break; | |||
199 | case typelib_TypeClass_SHORT: | |||
200 | case typelib_TypeClass_UNSIGNED_SHORT: | |||
201 | case typelib_TypeClass_CHAR: | |||
202 | write16(buffer, *static_cast< sal_uInt16 const * >(value)); | |||
203 | break; | |||
204 | case typelib_TypeClass_LONG: | |||
205 | case typelib_TypeClass_UNSIGNED_LONG: | |||
206 | case typelib_TypeClass_FLOAT: | |||
207 | case typelib_TypeClass_ENUM: | |||
208 | write32(buffer, *static_cast< sal_uInt32 const * >(value)); | |||
209 | break; | |||
210 | case typelib_TypeClass_HYPER: | |||
211 | case typelib_TypeClass_UNSIGNED_HYPER: | |||
212 | case typelib_TypeClass_DOUBLE: | |||
213 | write64(buffer, *static_cast< sal_uInt64 const * >(value)); | |||
214 | break; | |||
215 | case typelib_TypeClass_STRING: | |||
216 | writeString( | |||
217 | buffer, | |||
218 | OUString(*static_cast< rtl_uString * const * >(value))); | |||
219 | break; | |||
220 | case typelib_TypeClass_TYPE: | |||
221 | writeType( | |||
222 | buffer, | |||
223 | css::uno::TypeDescription( | |||
224 | *static_cast< typelib_TypeDescriptionReference * const * >( | |||
225 | value))); | |||
226 | break; | |||
227 | case typelib_TypeClass_ANY: | |||
228 | { | |||
229 | uno_Any const * p = static_cast< uno_Any const * >(value); | |||
230 | css::uno::TypeDescription t(p->pType); | |||
231 | writeType(buffer, t); | |||
232 | writeValue(buffer, t, p->pData); | |||
| ||||
233 | break; | |||
234 | } | |||
235 | case typelib_TypeClass_SEQUENCE: | |||
236 | { | |||
237 | sal_Sequence * p = *static_cast< sal_Sequence * const * >(value); | |||
238 | writeCompressed(buffer, static_cast< sal_uInt32 >(p->nElements)); | |||
239 | css::uno::TypeDescription ctd( | |||
240 | reinterpret_cast< typelib_IndirectTypeDescription * >( | |||
241 | type.get())-> | |||
242 | pType); | |||
243 | assert(ctd.is())(static_cast <bool> (ctd.is()) ? void (0) : __assert_fail ("ctd.is()", "/home/maarten/src/libreoffice/core/binaryurp/source/marshal.cxx" , 243, __extension__ __PRETTY_FUNCTION__)); | |||
244 | if (ctd.get()->eTypeClass == typelib_TypeClass_BYTE) { | |||
245 | buffer->insert( | |||
246 | buffer->end(), p->elements, p->elements + p->nElements); | |||
247 | } else { | |||
248 | for (sal_Int32 i = 0; i != p->nElements; ++i) { | |||
249 | writeValue(buffer, ctd, p->elements + i * ctd.get()->nSize); | |||
250 | } | |||
251 | } | |||
252 | break; | |||
253 | } | |||
254 | case typelib_TypeClass_STRUCT: | |||
255 | case typelib_TypeClass_EXCEPTION: | |||
256 | writeMemberValues(buffer, type, value); | |||
257 | break; | |||
258 | case typelib_TypeClass_INTERFACE: | |||
259 | writeOid( | |||
260 | buffer, | |||
261 | bridge_->registerOutgoingInterface( | |||
262 | css::uno::UnoInterfaceReference( | |||
263 | *static_cast< uno_Interface * const * >(value)), | |||
264 | type)); | |||
265 | break; | |||
266 | default: | |||
267 | assert(false)(static_cast <bool> (false) ? void (0) : __assert_fail ( "false", "/home/maarten/src/libreoffice/core/binaryurp/source/marshal.cxx" , 267, __extension__ __PRETTY_FUNCTION__)); // this cannot happen | |||
268 | break; | |||
269 | } | |||
270 | } | |||
271 | ||||
272 | void Marshal::writeMemberValues( | |||
273 | std::vector< unsigned char > * buffer, | |||
274 | css::uno::TypeDescription const & type, void const * aggregateValue) | |||
275 | { | |||
276 | assert((static_cast <bool> (type.is() && (type.get()-> eTypeClass == typelib_TypeClass_STRUCT || type.get()->eTypeClass == typelib_TypeClass_EXCEPTION) && aggregateValue != nullptr) ? void (0) : __assert_fail ("type.is() && (type.get()->eTypeClass == typelib_TypeClass_STRUCT || type.get()->eTypeClass == typelib_TypeClass_EXCEPTION) && aggregateValue != nullptr" , "/home/maarten/src/libreoffice/core/binaryurp/source/marshal.cxx" , 280, __extension__ __PRETTY_FUNCTION__)) | |||
277 | type.is() &&(static_cast <bool> (type.is() && (type.get()-> eTypeClass == typelib_TypeClass_STRUCT || type.get()->eTypeClass == typelib_TypeClass_EXCEPTION) && aggregateValue != nullptr) ? void (0) : __assert_fail ("type.is() && (type.get()->eTypeClass == typelib_TypeClass_STRUCT || type.get()->eTypeClass == typelib_TypeClass_EXCEPTION) && aggregateValue != nullptr" , "/home/maarten/src/libreoffice/core/binaryurp/source/marshal.cxx" , 280, __extension__ __PRETTY_FUNCTION__)) | |||
278 | (type.get()->eTypeClass == typelib_TypeClass_STRUCT ||(static_cast <bool> (type.is() && (type.get()-> eTypeClass == typelib_TypeClass_STRUCT || type.get()->eTypeClass == typelib_TypeClass_EXCEPTION) && aggregateValue != nullptr) ? void (0) : __assert_fail ("type.is() && (type.get()->eTypeClass == typelib_TypeClass_STRUCT || type.get()->eTypeClass == typelib_TypeClass_EXCEPTION) && aggregateValue != nullptr" , "/home/maarten/src/libreoffice/core/binaryurp/source/marshal.cxx" , 280, __extension__ __PRETTY_FUNCTION__)) | |||
279 | type.get()->eTypeClass == typelib_TypeClass_EXCEPTION) &&(static_cast <bool> (type.is() && (type.get()-> eTypeClass == typelib_TypeClass_STRUCT || type.get()->eTypeClass == typelib_TypeClass_EXCEPTION) && aggregateValue != nullptr) ? void (0) : __assert_fail ("type.is() && (type.get()->eTypeClass == typelib_TypeClass_STRUCT || type.get()->eTypeClass == typelib_TypeClass_EXCEPTION) && aggregateValue != nullptr" , "/home/maarten/src/libreoffice/core/binaryurp/source/marshal.cxx" , 280, __extension__ __PRETTY_FUNCTION__)) | |||
280 | aggregateValue != nullptr)(static_cast <bool> (type.is() && (type.get()-> eTypeClass == typelib_TypeClass_STRUCT || type.get()->eTypeClass == typelib_TypeClass_EXCEPTION) && aggregateValue != nullptr) ? void (0) : __assert_fail ("type.is() && (type.get()->eTypeClass == typelib_TypeClass_STRUCT || type.get()->eTypeClass == typelib_TypeClass_EXCEPTION) && aggregateValue != nullptr" , "/home/maarten/src/libreoffice/core/binaryurp/source/marshal.cxx" , 280, __extension__ __PRETTY_FUNCTION__)); | |||
281 | type.makeComplete(); | |||
282 | typelib_CompoundTypeDescription * ctd = | |||
283 | reinterpret_cast< typelib_CompoundTypeDescription * >(type.get()); | |||
284 | if (ctd->pBaseTypeDescription != nullptr) { | |||
285 | writeMemberValues( | |||
286 | buffer, | |||
287 | css::uno::TypeDescription(&ctd->pBaseTypeDescription->aBase), | |||
288 | aggregateValue); | |||
289 | } | |||
290 | for (sal_Int32 i = 0; i != ctd->nMembers; ++i) { | |||
291 | writeValue( | |||
292 | buffer, css::uno::TypeDescription(ctd->ppTypeRefs[i]), | |||
293 | (static_cast< char const * >(aggregateValue) + | |||
294 | ctd->pMemberOffsets[i])); | |||
295 | } | |||
296 | } | |||
297 | ||||
298 | } | |||
299 | ||||
300 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |