Bug Summary

File:comphelper/source/streaming/seekableinput.cxx
Location:line 149, column 12
Description:Called C++ object pointer is null

Annotated Source Code

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 <com/sun/star/io/XOutputStream.hpp>
21
22
23#include <comphelper/seekableinput.hxx>
24
25using namespace ::com::sun::star;
26
27namespace comphelper
28{
29
30const sal_Int32 nConstBufferSize = 32000;
31
32//---------------------------------------------------------------------------
33void copyInputToOutput_Impl( const uno::Reference< io::XInputStream >& xIn,
34 const uno::Reference< io::XOutputStream >& xOut )
35{
36 sal_Int32 nRead;
37 uno::Sequence< sal_Int8 > aSequence( nConstBufferSize );
38
39 do
40 {
41 nRead = xIn->readBytes( aSequence, nConstBufferSize );
42 if ( nRead < nConstBufferSize )
43 {
44 uno::Sequence< sal_Int8 > aTempBuf( aSequence.getConstArray(), nRead );
45 xOut->writeBytes( aTempBuf );
46 }
47 else
48 xOut->writeBytes( aSequence );
49 }
50 while ( nRead == nConstBufferSize );
51}
52
53//---------------------------------------------------------------------------
54OSeekableInputWrapper::OSeekableInputWrapper(
55 const uno::Reference< io::XInputStream >& xInStream,
56 const uno::Reference< lang::XMultiServiceFactory >& xFactory )
57: m_xFactory( xFactory )
58, m_xOriginalStream( xInStream )
59{
60 if ( !m_xFactory.is() )
61 throw uno::RuntimeException();
62}
63
64//---------------------------------------------------------------------------
65OSeekableInputWrapper::~OSeekableInputWrapper()
66{
67}
68
69//---------------------------------------------------------------------------
70uno::Reference< io::XInputStream > OSeekableInputWrapper::CheckSeekableCanWrap(
71 const uno::Reference< io::XInputStream >& xInStream,
72 const uno::Reference< lang::XMultiServiceFactory >& xFactory )
73{
74 // check that the stream is seekable and just wrap it if it is not
75 uno::Reference< io::XSeekable > xSeek( xInStream, uno::UNO_QUERY );
76 if ( xSeek.is() )
77 return xInStream;
78
79 uno::Reference< io::XInputStream > xNewStream(
80 static_cast< io::XInputStream* >(
81 new OSeekableInputWrapper( xInStream, xFactory ) ) );
82 return xNewStream;
83}
84
85//---------------------------------------------------------------------------
86void OSeekableInputWrapper::PrepareCopy_Impl()
87{
88 if ( !m_xCopyInput.is() )
89 {
90 if ( !m_xFactory.is() )
91 throw uno::RuntimeException();
92
93 uno::Reference< io::XOutputStream > xTempOut(
94 m_xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.TempFile")(&("com.sun.star.io.TempFile")[0]), ((sal_Int32)((sizeof (
"com.sun.star.io.TempFile") / sizeof (("com.sun.star.io.TempFile"
)[0]))-1)), (((rtl_TextEncoding) 11))
) ),
95 uno::UNO_QUERY );
96
97 if ( xTempOut.is() )
98 {
99 copyInputToOutput_Impl( m_xOriginalStream, xTempOut );
100 xTempOut->closeOutput();
101
102 uno::Reference< io::XSeekable > xTempSeek( xTempOut, uno::UNO_QUERY );
103 if ( xTempSeek.is() )
104 {
105 xTempSeek->seek( 0 );
106 m_xCopyInput = uno::Reference< io::XInputStream >( xTempOut, uno::UNO_QUERY );
107 if ( m_xCopyInput.is() )
108 m_xCopySeek = xTempSeek;
109 }
110 }
111 }
112
113 if ( !m_xCopyInput.is() )
114 throw io::IOException();
115}
116
117// XInputStream
118//---------------------------------------------------------------------------
119sal_Int32 SAL_CALL OSeekableInputWrapper::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
120 throw ( io::NotConnectedException,
121 io::BufferSizeExceededException,
122 io::IOException,
123 uno::RuntimeException )
124{
125 ::osl::MutexGuard aGuard( m_aMutex );
126
127 if ( !m_xOriginalStream.is() )
128 throw io::NotConnectedException();
129
130 PrepareCopy_Impl();
131
132 return m_xCopyInput->readBytes( aData, nBytesToRead );
133}
134
135//---------------------------------------------------------------------------
136sal_Int32 SAL_CALL OSeekableInputWrapper::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
137 throw ( io::NotConnectedException,
138 io::BufferSizeExceededException,
139 io::IOException,
140 uno::RuntimeException )
141{
142 ::osl::MutexGuard aGuard( m_aMutex );
143
144 if ( !m_xOriginalStream.is() )
1
Taking false branch
145 throw io::NotConnectedException();
146
147 PrepareCopy_Impl();
148
149 return m_xCopyInput->readSomeBytes( aData, nMaxBytesToRead );
2
Called C++ object pointer is null
150}
151
152//---------------------------------------------------------------------------
153void SAL_CALL OSeekableInputWrapper::skipBytes( sal_Int32 nBytesToSkip )
154 throw ( io::NotConnectedException,
155 io::BufferSizeExceededException,
156 io::IOException,
157 uno::RuntimeException )
158{
159 ::osl::MutexGuard aGuard( m_aMutex );
160
161 if ( !m_xOriginalStream.is() )
162 throw io::NotConnectedException();
163
164 PrepareCopy_Impl();
165
166 m_xCopyInput->skipBytes( nBytesToSkip );
167}
168
169//---------------------------------------------------------------------------
170sal_Int32 SAL_CALL OSeekableInputWrapper::available()
171 throw ( io::NotConnectedException,
172 io::IOException,
173 uno::RuntimeException )
174{
175 ::osl::MutexGuard aGuard( m_aMutex );
176
177 if ( !m_xOriginalStream.is() )
178 throw io::NotConnectedException();
179
180 PrepareCopy_Impl();
181
182 return m_xCopyInput->available();
183}
184
185//---------------------------------------------------------------------------
186void SAL_CALL OSeekableInputWrapper::closeInput()
187 throw ( io::NotConnectedException,
188 io::IOException,
189 uno::RuntimeException )
190{
191 ::osl::MutexGuard aGuard( m_aMutex );
192
193 if ( !m_xOriginalStream.is() )
194 throw io::NotConnectedException();
195
196 m_xOriginalStream->closeInput();
197 m_xOriginalStream = uno::Reference< io::XInputStream >();
198
199 if ( m_xCopyInput.is() )
200 {
201 m_xCopyInput->closeInput();
202 m_xCopyInput = uno::Reference< io::XInputStream >();
203 }
204
205 m_xCopySeek = uno::Reference< io::XSeekable >();
206}
207
208
209// XSeekable
210//---------------------------------------------------------------------------
211void SAL_CALL OSeekableInputWrapper::seek( sal_Int64 location )
212 throw ( lang::IllegalArgumentException,
213 io::IOException,
214 uno::RuntimeException )
215{
216 ::osl::MutexGuard aGuard( m_aMutex );
217
218 if ( !m_xOriginalStream.is() )
219 throw io::NotConnectedException();
220
221 PrepareCopy_Impl();
222
223 m_xCopySeek->seek( location );
224}
225
226//---------------------------------------------------------------------------
227sal_Int64 SAL_CALL OSeekableInputWrapper::getPosition()
228 throw ( io::IOException,
229 uno::RuntimeException )
230{
231 ::osl::MutexGuard aGuard( m_aMutex );
232
233 if ( !m_xOriginalStream.is() )
234 throw io::NotConnectedException();
235
236 PrepareCopy_Impl();
237
238 return m_xCopySeek->getPosition();
239}
240
241//---------------------------------------------------------------------------
242sal_Int64 SAL_CALL OSeekableInputWrapper::getLength()
243 throw ( io::IOException,
244 uno::RuntimeException )
245{
246 ::osl::MutexGuard aGuard( m_aMutex );
247
248 if ( !m_xOriginalStream.is() )
249 throw io::NotConnectedException();
250
251 PrepareCopy_Impl();
252
253 return m_xCopySeek->getLength();
254}
255
256} // namespace comphelper
257
258/* vim:set shiftwidth=4 softtabstop=4 expandtab: */