File: | cppu/source/LogBridge/LogBridge.cxx |
Location: | line 242, column 67 |
Description: | Access to field 'pTypeName' results in a dereference of a null pointer (loaded from variable 'pElementTypeDescr') |
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 | ||||
21 | #include "osl/mutex.hxx" | |||
22 | #include "osl/thread.h" | |||
23 | #include "uno/dispatcher.h" | |||
24 | #include "typelib/typedescription.hxx" | |||
25 | #include "cppu/helper/purpenv/Environment.hxx" | |||
26 | #include "cppu/helper/purpenv/Mapping.hxx" | |||
27 | #include "cppu/EnvDcp.hxx" | |||
28 | #include "rtl/logfile.hxx" | |||
29 | #include "uno/environment.hxx" | |||
30 | #include <com/sun/star/uno/Type.hxx> | |||
31 | #include <boost/unordered_map.hpp> | |||
32 | #include <memory> | |||
33 | ||||
34 | namespace | |||
35 | { | |||
36 | class LogBridge : public cppu::Enterable | |||
37 | { | |||
38 | osl::Mutex m_mutex; | |||
39 | sal_Int32 m_count; | |||
40 | oslThreadIdentifier m_threadId; | |||
41 | ||||
42 | virtual ~LogBridge(void); | |||
43 | ||||
44 | public: | |||
45 | explicit LogBridge(void); | |||
46 | ||||
47 | virtual void v_callInto_v(uno_EnvCallee * pCallee, va_list * pParam); | |||
48 | virtual void v_callOut_v (uno_EnvCallee * pCallee, va_list * pParam); | |||
49 | ||||
50 | virtual void v_enter(void); | |||
51 | virtual void v_leave(void); | |||
52 | ||||
53 | virtual int v_isValid(rtl::OUString * pReason); | |||
54 | }; | |||
55 | ||||
56 | LogBridge::LogBridge(void) | |||
57 | : m_count (0) | |||
58 | ,m_threadId(0) | |||
59 | { | |||
60 | } | |||
61 | ||||
62 | LogBridge::~LogBridge(void) | |||
63 | { | |||
64 | OSL_ASSERT(m_count >= 0)do { if (true && (!(m_count >= 0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/LogBridge/LogBridge.cxx" ":" "64" ": "), "OSL_ASSERT: %s", "m_count >= 0"); } } while (false); | |||
65 | } | |||
66 | ||||
67 | void LogBridge::v_callInto_v(uno_EnvCallee * pCallee, va_list * pParam) | |||
68 | { | |||
69 | enter(); | |||
70 | pCallee(pParam); | |||
71 | leave(); | |||
72 | } | |||
73 | ||||
74 | void LogBridge::v_callOut_v(uno_EnvCallee * pCallee, va_list * pParam) | |||
75 | { | |||
76 | OSL_ASSERT(m_count > 0)do { if (true && (!(m_count > 0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/LogBridge/LogBridge.cxx" ":" "76" ": "), "OSL_ASSERT: %s", "m_count > 0"); } } while (false); | |||
77 | ||||
78 | -- m_count; | |||
79 | pCallee(pParam); | |||
80 | ++ m_count; | |||
81 | ||||
82 | if (!m_threadId) | |||
83 | m_threadId = osl_getThreadIdentifier(NULL__null); | |||
84 | } | |||
85 | ||||
86 | void LogBridge::v_enter(void) | |||
87 | { | |||
88 | m_mutex.acquire(); | |||
89 | ||||
90 | OSL_ASSERT(m_count >= 0)do { if (true && (!(m_count >= 0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/LogBridge/LogBridge.cxx" ":" "90" ": "), "OSL_ASSERT: %s", "m_count >= 0"); } } while (false); | |||
91 | ||||
92 | if (m_count == 0) | |||
93 | m_threadId = osl_getThreadIdentifier(NULL__null); | |||
94 | ||||
95 | ++ m_count; | |||
96 | } | |||
97 | ||||
98 | void LogBridge::v_leave(void) | |||
99 | { | |||
100 | OSL_ASSERT(m_count > 0)do { if (true && (!(m_count > 0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/LogBridge/LogBridge.cxx" ":" "100" ": "), "OSL_ASSERT: %s", "m_count > 0"); } } while (false); | |||
101 | ||||
102 | -- m_count; | |||
103 | if (!m_count) | |||
104 | m_threadId = 0; | |||
105 | ||||
106 | ||||
107 | m_mutex.release(); | |||
108 | } | |||
109 | ||||
110 | int LogBridge::v_isValid(rtl::OUString * pReason) | |||
111 | { | |||
112 | int result = 1; | |||
113 | ||||
114 | result = m_count > 0; | |||
115 | if (!result) | |||
116 | *pReason = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("not entered")(&("not entered")[0]), ((sal_Int32)((sizeof ("not entered" ) / sizeof (("not entered")[0]))-1)), (((rtl_TextEncoding) 11 ))); | |||
117 | ||||
118 | else | |||
119 | { | |||
120 | result = m_threadId == osl_getThreadIdentifier(NULL__null); | |||
121 | ||||
122 | if (!result) | |||
123 | *pReason = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("wrong thread")(&("wrong thread")[0]), ((sal_Int32)((sizeof ("wrong thread" ) / sizeof (("wrong thread")[0]))-1)), (((rtl_TextEncoding) 11 ))); | |||
124 | } | |||
125 | ||||
126 | if (result) | |||
127 | *pReason = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OK")(&("OK")[0]), ((sal_Int32)((sizeof ("OK") / sizeof (("OK" )[0]))-1)), (((rtl_TextEncoding) 11))); | |||
128 | ||||
129 | return result; | |||
130 | } | |||
131 | ||||
132 | void traceValue(typelib_TypeDescriptionReference* _pTypeRef,void* pArg) | |||
133 | { | |||
134 | switch(_pTypeRef->eTypeClass) | |||
135 | { | |||
136 | case typelib_TypeClass_STRING: | |||
137 | { | |||
138 | const ::rtl::OString sValue( ::rtl::OUStringToOString(*static_cast< ::rtl::OUString*>(pArg),osl_getThreadTextEncoding())); | |||
139 | rtl_logfile_trace( "%s", sValue.getStr()); | |||
140 | } | |||
141 | break; | |||
142 | case typelib_TypeClass_BOOLEAN: | |||
143 | rtl_logfile_trace( "%d", *static_cast<sal_Bool*>(pArg)); | |||
144 | break; | |||
145 | case typelib_TypeClass_BYTE: | |||
146 | rtl_logfile_trace( "%d", *static_cast<sal_Int8*>(pArg)); | |||
147 | break; | |||
148 | case typelib_TypeClass_CHAR: | |||
149 | rtl_logfile_trace( "%c", *static_cast<sal_Char*>(pArg)); | |||
150 | break; | |||
151 | case typelib_TypeClass_SHORT: | |||
152 | case typelib_TypeClass_UNSIGNED_SHORT: | |||
153 | rtl_logfile_trace( "%d", *static_cast<sal_Int16*>(pArg)); | |||
154 | break; | |||
155 | case typelib_TypeClass_LONG: | |||
156 | case typelib_TypeClass_UNSIGNED_LONG: | |||
157 | case typelib_TypeClass_ENUM: | |||
158 | rtl_logfile_trace( "%d", *static_cast<sal_Int32*>(pArg)); | |||
159 | break; | |||
160 | case typelib_TypeClass_HYPER: | |||
161 | case typelib_TypeClass_UNSIGNED_HYPER: | |||
162 | rtl_logfile_trace( "%d", *static_cast<sal_Int64*>(pArg)); | |||
163 | break; | |||
164 | case typelib_TypeClass_FLOAT: | |||
165 | rtl_logfile_trace( "%f", *static_cast<float*>(pArg)); | |||
166 | break; | |||
167 | case typelib_TypeClass_DOUBLE: | |||
168 | rtl_logfile_trace( "%f", *static_cast<double*>(pArg)); | |||
169 | break; | |||
170 | case typelib_TypeClass_TYPE: | |||
171 | { | |||
172 | const ::rtl::OString sValue( ::rtl::OUStringToOString(((com::sun::star::uno::Type*)pArg)->getTypeName(),osl_getThreadTextEncoding())); | |||
173 | rtl_logfile_trace( "%s", sValue.getStr()); | |||
174 | } | |||
175 | break; | |||
176 | case typelib_TypeClass_ANY: | |||
177 | if ( static_cast<uno_Any*>(pArg)->pData ) | |||
178 | traceValue(static_cast<uno_Any*>(pArg)->pType,static_cast<uno_Any*>(pArg)->pData); | |||
179 | else | |||
180 | rtl_logfile_trace( "void"); | |||
181 | break; | |||
182 | case typelib_TypeClass_EXCEPTION: | |||
183 | rtl_logfile_trace( "exception"); | |||
184 | break; | |||
185 | case typelib_TypeClass_INTERFACE: | |||
186 | { | |||
187 | const ::rtl::OString sValue( ::rtl::OUStringToOString(_pTypeRef->pTypeName,osl_getThreadTextEncoding())); | |||
188 | rtl_logfile_trace( "%s 0x%p", sValue.getStr(),pArg); | |||
189 | } | |||
190 | break; | |||
191 | case typelib_TypeClass_VOID: | |||
192 | rtl_logfile_trace( "void"); | |||
193 | break; | |||
194 | default: | |||
195 | rtl_logfile_trace( "0x%p", pArg); | |||
196 | break; | |||
197 | } // switch(pParams[i].pTypeRef->eTypeClass) | |||
198 | } | |||
199 | } | |||
200 | ||||
201 | void LogProbe( | |||
202 | bool pre, | |||
203 | SAL_UNUSED_PARAMETER__attribute__ ((unused)) void * /*pThis*/, | |||
204 | SAL_UNUSED_PARAMETER__attribute__ ((unused)) void * /*pContext*/, | |||
205 | typelib_TypeDescriptionReference * pReturnTypeRef, | |||
206 | typelib_MethodParameter * pParams, | |||
207 | sal_Int32 nParams, | |||
208 | typelib_TypeDescription const * pMemberType, | |||
209 | void * pReturn, | |||
210 | void * pArgs[], | |||
211 | uno_Any ** ppException ) | |||
212 | { | |||
213 | static ::std::auto_ptr< ::rtl::Logfile> pLogger; | |||
214 | ::rtl::OString sTemp; | |||
215 | if ( pMemberType && pMemberType->pTypeName ) | |||
216 | sTemp = ::rtl::OUStringToOString(pMemberType->pTypeName,RTL_TEXTENCODING_ASCII_US(((rtl_TextEncoding) 11))); | |||
217 | if ( pre ) | |||
| ||||
218 | { | |||
219 | rtl_logfile_longTrace( "{ LogBridge () %s", sTemp.getStr() ); | |||
220 | if ( nParams ) | |||
221 | { | |||
222 | rtl_logfile_trace( "\n| : ( LogBridge "); | |||
223 | for(sal_Int32 i = 0;i < nParams;++i) | |||
224 | { | |||
225 | if ( i > 0 ) | |||
226 | rtl_logfile_trace( ","); | |||
227 | traceValue(pParams[i].pTypeRef,pArgs[i]); | |||
228 | ||||
229 | } | |||
230 | rtl_logfile_trace( ")"); | |||
231 | } // if ( nParams ) | |||
232 | rtl_logfile_trace( "\n"); | |||
233 | } | |||
234 | else if ( !pre ) | |||
235 | { | |||
236 | rtl_logfile_longTrace( "} LogBridge () %s",sTemp.getStr()); | |||
237 | if ( ppException && *ppException ) | |||
238 | { | |||
239 | rtl_logfile_trace( " excption occurred : "); | |||
240 | typelib_TypeDescription * pElementTypeDescr = 0; | |||
241 | TYPELIB_DANGER_GET( &pElementTypeDescr, (*ppException)->pType ){ typelib_TypeDescriptionReference * pMacroTypeRef = ((*ppException )->pType); typelib_TypeDescription ** ppMacroTypeDescr = ( &pElementTypeDescr); if (((pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || (pMacroTypeRef->eTypeClass ) == typelib_TypeClass_INTERFACE_ATTRIBUTE)) { typelib_typedescriptionreference_getDescription ( ppMacroTypeDescr, pMacroTypeRef ); } else if (!pMacroTypeRef ->pType || !pMacroTypeRef->pType->pWeakRef) { typelib_typedescriptionreference_getDescription ( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release ( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef ->pType; } }; | |||
242 | const ::rtl::OString sValue( ::rtl::OUStringToOString(pElementTypeDescr->pTypeName,osl_getThreadTextEncoding())); | |||
| ||||
243 | rtl_logfile_trace( "%s", sValue.getStr()); | |||
244 | TYPELIB_DANGER_RELEASE( pElementTypeDescr ){ if ((((pElementTypeDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || ((pElementTypeDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE )) typelib_typedescription_release( pElementTypeDescr ); }; | |||
245 | } | |||
246 | else if ( pReturnTypeRef ) | |||
247 | { | |||
248 | rtl_logfile_trace( " return : "); | |||
249 | traceValue(pReturnTypeRef,pReturn); | |||
250 | } // if ( pReturn && pReturnTypeRef ) | |||
251 | ||||
252 | rtl_logfile_trace( "\n"); | |||
253 | } | |||
254 | } | |||
255 | ||||
256 | #ifdef DISABLE_DYNLOADING | |||
257 | ||||
258 | #define uno_initEnvironment log_uno_uno_initEnvironment | |||
259 | #define uno_ext_getMapping log_uno_uno_ext_getMapping | |||
260 | ||||
261 | #endif | |||
262 | ||||
263 | extern "C" void SAL_DLLPUBLIC_EXPORT__attribute__ ((visibility("default"))) SAL_CALL uno_initEnvironment(uno_Environment * pEnv) | |||
264 | SAL_THROW_EXTERN_C()throw () | |||
265 | { | |||
266 | cppu::helper::purpenv::Environment_initWithEnterable(pEnv, new LogBridge()); | |||
267 | } | |||
268 | ||||
269 | extern "C" void SAL_DLLPUBLIC_EXPORT__attribute__ ((visibility("default"))) SAL_CALL uno_ext_getMapping(uno_Mapping ** ppMapping, | |||
270 | uno_Environment * pFrom, | |||
271 | uno_Environment * pTo ) | |||
272 | { | |||
273 | cppu::helper::purpenv::createMapping(ppMapping, pFrom, pTo,LogProbe); | |||
274 | } | |||
275 | ||||
276 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |