Bug Summary

File:/home/alan/workspace/canalyze/llvm/llvm-git/build/smtptr-test/testcase/mysql-server/plugin/keyring/buffer.cc
Warning:line 49, 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 buffer.cc -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 LOG_COMPONENT_TAG="keyring_file" -D LZ4_DISABLE_DEPRECATE_WARNINGS -D MYSQL_DYNAMIC_PLUGIN -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 -D keyring_file_EXPORTS -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 -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 -w -std=c++14 -fdeprecated-macro -fdebug-compilation-dir /home/alan/workspace/canalyze/llvm/llvm-git/build/smtptr-test/testcase/mysql-server/build/plugin/keyring -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/plugin/keyring/buffer.cc

/home/alan/workspace/canalyze/llvm/llvm-git/build/smtptr-test/testcase/mysql-server/plugin/keyring/buffer.cc

1/* Copyright (c) 2016, 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 "plugin/keyring/buffer.h"
24
25#include <memory>
26
27#include "my_dbug.h"
28#include "plugin/keyring/common/keyring_key.h"
29
30namespace keyring {
31void Buffer::free() {
32 if (data != nullptr) {
33 delete[] data;
34 data = nullptr;
35 }
36 mark_as_empty();
37 DBUG_ASSERT(size == 0 && position == 0)do { } while (0);
38}
39
40bool Buffer::get_next_key(IKey **key) {
41 *key = nullptr;
42
43 std::unique_ptr<Key> key_ptr(new Key());
1
Calling 'Keyring_alloc::operator new'
7
Returning from 'Keyring_alloc::operator new'
8
Pointer assignment: class std::unique_ptr<struct keyring::Key, struct std::default_delete<struct keyring::Key> > key_ptr = nullptr
44 size_t number_of_bytes_read_from_buffer = 0;
45 if (data == nullptr) {
9
Assuming the condition is false
10
Taking false branch
46 DBUG_ASSERT(size == 0)do { } while (0);
47 return true;
48 }
49 if (key_ptr->load_from_buffer(
11
Dereference an empty smart pointer by calling operator ->
50 data + position, &number_of_bytes_read_from_buffer, size - position))
51 return true;
52
53 position += number_of_bytes_read_from_buffer;
54 *key = key_ptr.release();
55 return false;
56}
57
58bool Buffer::has_next_key() { return position < size; }
59
60void Buffer::reserve(size_t memory_size) {
61 DBUG_ASSERT(memory_size % sizeof(size_t) ==do { } while (0)
62 0)do { } while (0); // make sure size is sizeof(size_t) aligned
63 free();
64 data = reinterpret_cast<uchar *>(
65 new size_t[memory_size / sizeof(size_t)]); // force size_t alignment
66 size = memory_size;
67 if (data) memset(data, 0, size);
68 position = 0;
69}
70
71} // namespace keyring

/home/alan/workspace/canalyze/llvm/llvm-git/build/smtptr-test/testcase/mysql-server/plugin/keyring/common/keyring_memory.h

1/* Copyright (c) 2016, 2018, 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#ifndef MYSQL_KEYRING_MEMORY_H
24#define MYSQL_KEYRING_MEMORY_H
25
26#include <mysql/plugin_keyring.h>
27#include <limits>
28#include <memory>
29
30namespace keyring {
31
32extern PSI_memory_key key_memory_KEYRING;
33
34template <class T>
35T keyring_malloc(size_t size) {
36 void *allocated_memory = my_mallocmysql_malloc_service->mysql_malloc(key_memory_KEYRING, size, MYF(MY_WME)(myf)(16));
3
Conservative call: mysql_malloc_service_st::mysql_malloc
37 return allocated_memory ? reinterpret_cast<T>(allocated_memory) : NULL__null;
4
Assuming 'allocated_memory' is null
5
'?' condition is false
38}
39
40class Keyring_alloc {
41 public:
42 static void *operator new(size_t size) noexcept {
43 return keyring_malloc<void *>(size);
2
Calling 'keyring_malloc<void *>'
6
Returning from 'keyring_malloc<void *>'
44 }
45 static void *operator new[](size_t size) noexcept {
46 return keyring_malloc<void *>(size);
47 }
48 static void operator delete(void *ptr, std::size_t) { my_freemysql_malloc_service->mysql_free(ptr); }
49 static void operator delete[](void *ptr, std::size_t) { my_freemysql_malloc_service->mysql_free(ptr); }
50};
51} // namespace keyring
52
53#endif // MYSQL_KEYRING_MEMORY_H