Bug Summary

File:/home/alan/workspace/canalyze/llvm/llvm-git/build/smtptr-test/testcase/mysql-server/libbinlogevents/src/compression/iterator.cpp
Warning:line 170, column 7
Dereference an empty smart pointer by calling operator ->

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -disable-free -main-file-name iterator.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /home/alan/workspace/canalyze/llvm/sprinter/build/bin/resources -isystem /home/alan/workspace/canalyze/llvm/sprinter/build/bin/resources/include -isystem /home/alan/workspace/canalyze/llvm/llvm-git/build/smtptr-test/testcase/mysql-server/extra/rapidjson/include -isystem /home/alan/workspace/canalyze/llvm/llvm-git/build/smtptr-test/testcase/mysql-server/extra/lz4 -isystem /home/alan/workspace/canalyze/llvm/llvm-git/build/smtptr-test/testcase/mysql-server/extra/libedit/libedit-20190324-3.1/src/editline -isystem /home/alan/workspace/canalyze/llvm/llvm-git/build/smtptr-test/testcase/mysql-server/extra/zstd/lib -isystem /home/alan/workspace/canalyze/llvm/llvm-git/build/smtptr-test/testcase/mysql-server/build/extra/zlib -isystem /home/alan/workspace/canalyze/llvm/llvm-git/build/smtptr-test/testcase/mysql-server/extra/zlib -I /home/alan/workspace/canalyze/llvm/sprinter/build/bin/resources/include -D HAVE_CONFIG_H -D HAVE_TLSv13 -D LZ4_DISABLE_DEPRECATE_WARNINGS -D RAPIDJSON_NO_SIZETYPEDEFINE -D RAPIDJSON_SCHEMA_USE_INTERNALREGEX=0 -D RAPIDJSON_SCHEMA_USE_STDREGEX=1 -D _FILE_OFFSET_BITS=64 -D _GNU_SOURCE -D _USE_MATH_DEFINES -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /home/alan/workspace/canalyze/llvm/llvm-git/build/smtptr-test/testcase/mysql-server/build -I /home/alan/workspace/canalyze/llvm/llvm-git/build/smtptr-test/testcase/mysql-server/build/include -I /home/alan/workspace/canalyze/llvm/llvm-git/build/smtptr-test/testcase/mysql-server -I /home/alan/workspace/canalyze/llvm/llvm-git/build/smtptr-test/testcase/mysql-server/include -I /home/alan/workspace/canalyze/llvm/llvm-git/build/smtptr-test/testcase/mysql-server/libbinlogevents/include -D DBUG_OFF -D NDEBUG -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /home/alan/workspace/canalyze/llvm/sprinter/build/bin/resources/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wall -Wextra -Wformat-security -Wvla -Wundef -Wmissing-format-attribute -Woverloaded-virtual -Wcast-qual -Wimplicit-fallthrough=2 -Wstringop-truncation -Wlogical-op -Wshadow=local -w -std=c++14 -fdeprecated-macro -fdebug-compilation-dir /home/alan/workspace/canalyze/llvm/llvm-git/build/smtptr-test/testcase/mysql-server/build/libbinlogevents/src -ferror-limit 19 -fmessage-length 0 -ftls-model=initial-exec -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -vectorize-loops -vectorize-slp -faddrsig -x c++ /home/alan/workspace/canalyze/llvm/llvm-git/build/smtptr-test/testcase/mysql-server/libbinlogevents/src/compression/iterator.cpp
1/* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#include <byteorder.h>
24#include <compression/factory.h>
25#include <compression/iterator.h>
26
27namespace binary_log {
28namespace transaction {
29namespace compression {
30
31/* purecov: begin inspected */
32Iterable_buffer::Iterable_buffer(const char *input_buffer,
33 size_t input_buffer_size)
34 : Iterable_buffer(input_buffer, input_buffer_size, input_buffer_size,
35 CompType::NONE) {}
36/* purecov: end */
37
38Iterable_buffer::Iterable_buffer(
39 const char *input_buffer, size_t input_buffer_size,
40 size_t decompressed_buffer_size,
41 binary_log::transaction::compression::type comp_algo)
42 : m_compressed_buffer(input_buffer),
43 m_compressed_buffer_size(input_buffer_size),
44 m_decompressed_buffer_size(decompressed_buffer_size) {
45 if (comp_algo != CompType::NONE) {
46 auto res{false};
47 auto left{0};
48 m_decoder = Factory::build_decompressor(comp_algo);
49 auto ptr = (unsigned char *)malloc(m_decompressed_buffer_size);
50 m_decoder->set_buffer((unsigned char *)ptr, m_decompressed_buffer_size);
51
52 // We decompress everything in one go.
53 m_decoder->open();
54 std::tie(left, res) = m_decoder->decompress(
55 (const unsigned char *)m_compressed_buffer, m_compressed_buffer_size);
56 m_decoder->close();
57
58 // Some error happened. Was not able to successfully decompress everything
59 if (res || left > 0) {
60 /* purecov: begin inspected */
61 free(const_cast<char *>(m_decompressed_buffer));
62 m_decompressed_buffer = nullptr;
63 m_decompressed_buffer_size = 0;
64 /* purecov: end */
65 } else {
66 // may have been realloc'ed in the decompressor
67 std::tie(ptr, m_decompressed_buffer_size, std::ignore) =
68 m_decoder->get_buffer();
69 m_decompressed_buffer = (const char *)ptr;
70 }
71 } else {
72 /* purecov: begin inspected */
73 m_decompressed_buffer = m_compressed_buffer;
74 m_decompressed_buffer_size = m_compressed_buffer_size;
75 /* purecov: end */
76 }
77}
78
79Iterable_buffer::~Iterable_buffer() {
80 if (m_decompressed_buffer != m_compressed_buffer) {
81 auto ptr{const_cast<char *>(m_decompressed_buffer)};
82 free(ptr);
83 m_decompressed_buffer = nullptr;
84 }
85}
86
87Iterable_buffer::iterator::iterator(Iterable_buffer &parent)
88 : m_target{&parent} {
89 m_reader = std::make_unique<binary_log::Event_reader>(
90 m_target->m_decompressed_buffer, m_target->m_decompressed_buffer_size);
91 m_reader->go_to(0);
92}
93
94Iterable_buffer::iterator::iterator(const iterator &rhs) { (*this) = rhs; }
2
Calling copy assignment operator for 'iterator'
7
Returning from copy assignment operator for 'iterator'
95Iterable_buffer::iterator::iterator(iterator &&rhs) { (*this) = rhs; }
96
97Iterable_buffer::iterator::~iterator() {}
98
99Iterable_buffer::iterator &Iterable_buffer::iterator::operator=(
100 const Iterable_buffer::iterator &rhs) {
101 m_target = rhs.m_target;
102 if (rhs.m_reader != nullptr) {
3
Calling 'operator!=<binary_log::Event_reader, std::default_delete<binary_log::Event_reader>>'
4
Pointer assignment: class std::unique_ptr<class binary_log::Event_reader, struct std::default_delete<class binary_log::Event_reader> > SymRegion{reg_$0<class binary_log::transaction::compression::Iterable_buffer::iterator * this>}->m_reader = nullptr
5
Returning from 'operator!=<binary_log::Event_reader, std::default_delete<binary_log::Event_reader>>'
6
Taking false branch
103 m_reader = std::make_unique<binary_log::Event_reader>(
104 m_target->m_decompressed_buffer, m_target->m_decompressed_buffer_size);
105 m_reader->go_to(rhs.m_reader->position());
106 }
107 return (*this);
108}
109
110/* purecov: begin inspected */
111Iterable_buffer::iterator &Iterable_buffer::iterator::operator=(
112 Iterable_buffer::iterator &&rhs) {
113 m_target = rhs.m_target;
114 m_reader.swap(rhs.m_reader);
115
116 rhs.m_target = nullptr;
117
118 return (*this);
119}
120/* purecov: end */
121
122Iterable_buffer::iterator &Iterable_buffer::iterator::operator++() {
123 // advance the previous buffer length
124 if (has_next_buffer()) {
10
Calling 'iterator::has_next_buffer'
125 auto ptr = m_reader->ptr();
126 m_reader->forward(EVENT_LEN_OFFSET9);
127 uint32_t event_len = m_reader->read_and_letoh<uint32_t>();
128 m_reader->go_to((ptr - m_reader->buffer()) + event_len);
129 }
130
131 // now check again if we have reached the end
132 if (!has_next_buffer()) m_reader.reset(nullptr);
133
134 return (*this);
135}
136
137Iterable_buffer::iterator::reference Iterable_buffer::iterator::operator*()
138 const {
139 if (has_next_buffer()) return m_reader->ptr();
140 return nullptr; /* purecov: inspected */
141}
142/* purecov: begin inspected */
143Iterable_buffer::iterator Iterable_buffer::iterator::operator++(int) {
144 Iterable_buffer::iterator to_return = (*this);
1
Calling copy constructor for 'iterator'
8
Returning from copy constructor for 'iterator'
145 ++(*this);
9
Calling 'iterator::operator++'
146 return to_return;
147}
148/* purecov: end */
149
150/* purecov: begin inspected */
151Iterable_buffer::iterator::pointer Iterable_buffer::iterator::operator->()
152 const {
153 return this->operator*();
154}
155/* purecov: end */
156
157bool Iterable_buffer::iterator::operator==(
158 Iterable_buffer::iterator rhs) const {
159 return m_reader == rhs.m_reader ||
160 (m_reader != nullptr && rhs.m_reader != nullptr &&
161 m_reader->position() == rhs.m_reader->position());
162}
163
164bool Iterable_buffer::iterator::operator!=(
165 Iterable_buffer::iterator rhs) const {
166 return !((*this) == rhs);
167}
168
169bool Iterable_buffer::iterator::has_next_buffer() const {
170 if (m_reader->has_error() ||
11
Dereference an empty smart pointer by calling operator ->
171 !m_reader->can_read(LOG_EVENT_MINIMAL_HEADER_LEN19U))
172 return false;
173
174 return true;
175}
176
177Iterable_buffer::iterator Iterable_buffer::begin() {
178 Iterable_buffer::iterator begin{*this};
179 if (begin.has_next_buffer())
180 return begin;
181 else
182 return Iterable_buffer::iterator{}; /* purecov: inspected */
183}
184
185Iterable_buffer::iterator Iterable_buffer::end() {
186 return Iterable_buffer::iterator{};
187}
188
189} // namespace compression
190} // namespace transaction
191} // namespace binary_log