Bug Summary

File:/rootdir/_build/../src/refptr-test.cc
Warning:line 81, column 9
Method called on moved-from object 'ptr1'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name refptr-test.cc -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/rootdir/_build -resource-dir /usr/lib/llvm-14/lib/clang/14.0.6 -I src/test-refptr.p -I src -I ../src -I . -I .. -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -D _FILE_OFFSET_BITS=64 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/x86_64-linux-gnu/c++/12 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/backward -internal-isystem /usr/lib/llvm-14/lib/clang/14.0.6/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Wno-address-of-packed-member -Wno-missing-field-initializers -Wno-packed -Wno-switch-enum -Wno-unused-parameter -Wwrite-strings -std=gnu++17 -fdeprecated-macro -fdebug-compilation-dir=/rootdir/_build -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-checker deadcode.DeadStores -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.core.SizeofPtr -analyzer-checker alpha.security.ArrayBoundV2 -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2022-12-31-022803-10898-1 -x c++ ../src/refptr-test.cc
1/*
2 * Copyright © 2018 Christian Persch
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 3 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#include "config.h"
19
20#include "refptr.hh"
21
22/* Test object */
23
24typedef struct _TestObject TestObject;
25typedef struct _TestObjectClass TestObjectClass;
26
27struct _TestObject {
28 GObject parent_instance;
29};
30
31struct _TestObjectClass{
32 GObjectClass parent_class;
33};
34
35static GType test_object_get_type(void);
36
37G_DEFINE_TYPE(TestObject, test_object, G_TYPE_OBJECT)static void test_object_init (TestObject *self); static void test_object_class_init
(TestObjectClass *klass); static GType test_object_get_type_once
(void); static gpointer test_object_parent_class = __null; static
gint TestObject_private_offset; static void test_object_class_intern_init
(gpointer klass) { test_object_parent_class = g_type_class_peek_parent
(klass); if (TestObject_private_offset != 0) g_type_class_adjust_private_offset
(klass, &TestObject_private_offset); test_object_class_init
((TestObjectClass*) klass); } __attribute__ ((__unused__)) static
inline gpointer test_object_get_instance_private (TestObject
*self) { return (((gpointer) ((guint8*) (self) + (glong) (TestObject_private_offset
)))); } GType test_object_get_type (void) { static gsize static_g_define_type_id
= 0; if ((__extension__ ({ static_assert (sizeof *(&static_g_define_type_id
) == sizeof (gpointer), "Expression evaluates to false"); (void
) (0 ? (gpointer) *(&static_g_define_type_id) : __null); (
!(__extension__ ({ static_assert (sizeof *(&static_g_define_type_id
) == sizeof (gpointer), "Expression evaluates to false"); gpointer
gapg_temp_newval; gpointer *gapg_temp_atomic = (gpointer *)(
&static_g_define_type_id); __atomic_load (gapg_temp_atomic
, &gapg_temp_newval, 5); gapg_temp_newval; })) &&
g_once_init_enter (&static_g_define_type_id)); }))) { GType
g_define_type_id = test_object_get_type_once (); (__extension__
({ static_assert (sizeof *(&static_g_define_type_id) == sizeof
(gpointer), "Expression evaluates to false"); 0 ? (void) (*(
&static_g_define_type_id) = (g_define_type_id)) : (void) 0
; g_once_init_leave ((&static_g_define_type_id), (gsize) (
g_define_type_id)); })); } return static_g_define_type_id; } [
[gnu::noinline]] static GType test_object_get_type_once (void
) { GType g_define_type_id = g_type_register_static_simple ((
(GType) ((20) << (2))), g_intern_static_string ("TestObject"
), sizeof (TestObjectClass), (GClassInitFunc)(void (*)(void))
test_object_class_intern_init, sizeof (TestObject), (GInstanceInitFunc
)(void (*)(void)) test_object_init, (GTypeFlags) 0); { {{};} }
return g_define_type_id; }
38
39static void
40test_object_init(TestObject* object)
41{
42}
43
44static void
45test_object_finalize(GObject *object)
46{
47 G_OBJECT_CLASS(test_object_parent_class)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass
*) ((test_object_parent_class)), (((GType) ((20) << (2)
)))))))
->finalize(object);
48}
49
50static void
51test_object_class_init(TestObjectClass* klass)
52{
53 GObjectClass* gobject_class = G_OBJECT_CLASS(klass)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass
*) ((klass)), (((GType) ((20) << (2))))))))
;
54 gobject_class->finalize = test_object_finalize;
55}
56
57static TestObject*
58test_object_new(void)
59{
60 return reinterpret_cast<TestObject*>(g_object_new(test_object_get_type(),
61 nullptr));
62}
63
64/* Tests */
65
66typedef union {
67 TestObject* obj;
68 void* ptr;
69} obj_t;
70
71static void
72test_glib_refptr(void)
73{
74 obj_t obj1;
75 obj1.obj = test_object_new();
76 g_object_add_weak_pointer(G_OBJECT(obj1.obj)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((obj1.obj)), (((GType) ((20) << (2))))))))
, &obj1.ptr);
77 auto ptr1 = bte::glib::RefPtr<TestObject>{obj1.obj};
78 g_assert_true(ptr1.get() == obj1.obj)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_
; if (ptr1.get() == obj1.obj) _g_boolean_var_ = 1; else _g_boolean_var_
= 0; _g_boolean_var_; }), 1)) ; else g_assertion_message (((
gchar*) 0), "../src/refptr-test.cc", 78, ((const char*) (__PRETTY_FUNCTION__
)), "'" "ptr1.get() == obj1.obj" "' should be TRUE"); } while
(0)
;
1
Taking true branch
2
Taking true branch
3
Loop condition is false. Exiting loop
79
80 auto ptr2 = std::move(ptr1);
4
Object 'ptr1' is moved
81 g_assert_true(ptr1.get() == nullptr)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_
; if (ptr1.get() == nullptr) _g_boolean_var_ = 1; else _g_boolean_var_
= 0; _g_boolean_var_; }), 1)) ; else g_assertion_message (((
gchar*) 0), "../src/refptr-test.cc", 81, ((const char*) (__PRETTY_FUNCTION__
)), "'" "ptr1.get() == nullptr" "' should be TRUE"); } while (
0)
;
5
Method called on moved-from object 'ptr1'
82 g_assert_true(ptr2.get() == obj1.obj)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_
; if (ptr2.get() == obj1.obj) _g_boolean_var_ = 1; else _g_boolean_var_
= 0; _g_boolean_var_; }), 1)) ; else g_assertion_message (((
gchar*) 0), "../src/refptr-test.cc", 82, ((const char*) (__PRETTY_FUNCTION__
)), "'" "ptr2.get() == obj1.obj" "' should be TRUE"); } while
(0)
;
83
84 obj_t obj2;
85 obj2.obj = test_object_new();
86 g_object_add_weak_pointer(G_OBJECT(obj2.obj)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((obj2.obj)), (((GType) ((20) << (2))))))))
, &obj2.ptr);
87 g_assert_nonnull(obj2.ptr)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_
; if ((obj2.ptr) != nullptr) _g_boolean_var_ = 1; else _g_boolean_var_
= 0; _g_boolean_var_; }), 1)) ; else g_assertion_message (((
gchar*) 0), "../src/refptr-test.cc", 87, ((const char*) (__PRETTY_FUNCTION__
)), "'" "obj2.ptr" "' should not be nullptr"); } while (0)
;
88 ptr2.reset(obj2.obj);
89 g_assert_null(obj1.ptr)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_
; if ((obj1.ptr) == nullptr) _g_boolean_var_ = 1; else _g_boolean_var_
= 0; _g_boolean_var_; }), 1)) ; else g_assertion_message (((
gchar*) 0), "../src/refptr-test.cc", 89, ((const char*) (__PRETTY_FUNCTION__
)), "'" "obj1.ptr" "' should be nullptr"); } while (0)
;
90 g_assert_true(ptr2.get() == obj2.obj)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_
; if (ptr2.get() == obj2.obj) _g_boolean_var_ = 1; else _g_boolean_var_
= 0; _g_boolean_var_; }), 1)) ; else g_assertion_message (((
gchar*) 0), "../src/refptr-test.cc", 90, ((const char*) (__PRETTY_FUNCTION__
)), "'" "ptr2.get() == obj2.obj" "' should be TRUE"); } while
(0)
;
91 g_assert_nonnull(obj2.ptr)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_
; if ((obj2.ptr) != nullptr) _g_boolean_var_ = 1; else _g_boolean_var_
= 0; _g_boolean_var_; }), 1)) ; else g_assertion_message (((
gchar*) 0), "../src/refptr-test.cc", 91, ((const char*) (__PRETTY_FUNCTION__
)), "'" "obj2.ptr" "' should not be nullptr"); } while (0)
;
92
93 ptr2 = nullptr;
94 g_assert_null(obj2.ptr)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_
; if ((obj2.ptr) == nullptr) _g_boolean_var_ = 1; else _g_boolean_var_
= 0; _g_boolean_var_; }), 1)) ; else g_assertion_message (((
gchar*) 0), "../src/refptr-test.cc", 94, ((const char*) (__PRETTY_FUNCTION__
)), "'" "obj2.ptr" "' should be nullptr"); } while (0)
;
95
96 obj_t obj3;
97 obj3.obj = test_object_new();
98 g_object_add_weak_pointer(G_OBJECT(obj3.obj)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((obj3.obj)), (((GType) ((20) << (2))))))))
, &obj3.ptr);
99 g_assert_nonnull(obj3.ptr)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_
; if ((obj3.ptr) != nullptr) _g_boolean_var_ = 1; else _g_boolean_var_
= 0; _g_boolean_var_; }), 1)) ; else g_assertion_message (((
gchar*) 0), "../src/refptr-test.cc", 99, ((const char*) (__PRETTY_FUNCTION__
)), "'" "obj3.ptr" "' should not be nullptr"); } while (0)
;
100 auto ptr3 = bte::glib::RefPtr<TestObject>{obj3.obj};
101 TestObject* obj4 = ptr3.release();
102 g_assert_null(ptr3.get())do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_
; if ((ptr3.get()) == nullptr) _g_boolean_var_ = 1; else _g_boolean_var_
= 0; _g_boolean_var_; }), 1)) ; else g_assertion_message (((
gchar*) 0), "../src/refptr-test.cc", 102, ((const char*) (__PRETTY_FUNCTION__
)), "'" "ptr3.get()" "' should be nullptr"); } while (0)
;
103 g_assert_nonnull(obj4)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_
; if ((obj4) != nullptr) _g_boolean_var_ = 1; else _g_boolean_var_
= 0; _g_boolean_var_; }), 1)) ; else g_assertion_message (((
gchar*) 0), "../src/refptr-test.cc", 103, ((const char*) (__PRETTY_FUNCTION__
)), "'" "obj4" "' should not be nullptr"); } while (0)
;
104 g_object_unref(obj4);
105 g_assert_null(obj3.ptr)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_
; if ((obj3.ptr) == nullptr) _g_boolean_var_ = 1; else _g_boolean_var_
= 0; _g_boolean_var_; }), 1)) ; else g_assertion_message (((
gchar*) 0), "../src/refptr-test.cc", 105, ((const char*) (__PRETTY_FUNCTION__
)), "'" "obj3.ptr" "' should be nullptr"); } while (0)
;
106
107 obj_t obj5;
108 obj5.obj = test_object_new();
109 g_object_add_weak_pointer(G_OBJECT(obj5.obj)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((obj5.obj)), (((GType) ((20) << (2))))))))
, &obj5.ptr);
110 g_assert_nonnull(obj5.ptr)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_
; if ((obj5.ptr) != nullptr) _g_boolean_var_ = 1; else _g_boolean_var_
= 0; _g_boolean_var_; }), 1)) ; else g_assertion_message (((
gchar*) 0), "../src/refptr-test.cc", 110, ((const char*) (__PRETTY_FUNCTION__
)), "'" "obj5.ptr" "' should not be nullptr"); } while (0)
;
111 bte::glib::RefPtr<TestObject> ptr5{obj5.obj};
112
113 obj_t obj6;
114 obj6.obj = test_object_new();
115 g_object_add_weak_pointer(G_OBJECT(obj6.obj)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((obj6.obj)), (((GType) ((20) << (2))))))))
, &obj6.ptr);
116 g_assert_nonnull(obj6.ptr)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_
; if ((obj6.ptr) != nullptr) _g_boolean_var_ = 1; else _g_boolean_var_
= 0; _g_boolean_var_; }), 1)) ; else g_assertion_message (((
gchar*) 0), "../src/refptr-test.cc", 116, ((const char*) (__PRETTY_FUNCTION__
)), "'" "obj6.ptr" "' should not be nullptr"); } while (0)
;
117
118 ptr5.reset(obj6.obj);
119 g_assert_null(obj5.ptr)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_
; if ((obj5.ptr) == nullptr) _g_boolean_var_ = 1; else _g_boolean_var_
= 0; _g_boolean_var_; }), 1)) ; else g_assertion_message (((
gchar*) 0), "../src/refptr-test.cc", 119, ((const char*) (__PRETTY_FUNCTION__
)), "'" "obj5.ptr" "' should be nullptr"); } while (0)
;
120
121 ptr5.reset();
122 g_assert_null(obj6.ptr)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_
; if ((obj6.ptr) == nullptr) _g_boolean_var_ = 1; else _g_boolean_var_
= 0; _g_boolean_var_; }), 1)) ; else g_assertion_message (((
gchar*) 0), "../src/refptr-test.cc", 122, ((const char*) (__PRETTY_FUNCTION__
)), "'" "obj6.ptr" "' should be nullptr"); } while (0)
;
123 g_assert_null(ptr5.get())do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_
; if ((ptr5.get()) == nullptr) _g_boolean_var_ = 1; else _g_boolean_var_
= 0; _g_boolean_var_; }), 1)) ; else g_assertion_message (((
gchar*) 0), "../src/refptr-test.cc", 123, ((const char*) (__PRETTY_FUNCTION__
)), "'" "ptr5.get()" "' should be nullptr"); } while (0)
;
124}
125
126int
127main(int argc,
128 char* argv[])
129{
130 g_test_init(&argc, &argv, nullptr);
131
132 g_test_add_func("/bte/glib/refptr", test_glib_refptr);
133
134 return g_test_run();
135}