Bug Summary

File:home/HaikuArchives/ArtPaint/artpaint/application/ResourceServer.cpp
Warning:line 217, column 4
Value stored to 'picture' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-haiku -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name ResourceServer.cpp -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 static -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /boot/system/lib/clang/12.0.1 -iquote ./ -iquote artpaint/ -iquote artpaint/Utilities/ -iquote artpaint/application/ -iquote artpaint/controls/ -iquote artpaint/layers/ -iquote artpaint/paintwindow/ -iquote artpaint/tools/ -iquote artpaint/viewmanipulators/ -iquote artpaint/windows/ -iquote objects_artpaint/ -isystem /boot/system/develop/headers/private/interface -internal-isystem /system/develop/headers/c++ -internal-isystem /system/develop/headers/c++/x86_64-unknown-haiku -internal-isystem /system/develop/headers/c++/backward -O3 -fdeprecated-macro -fdebug-compilation-dir /boot/home/HaikuArchives/ArtPaint -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -o /tmp/scan-build-2022-06-19-103017-1294-1 -x c++ artpaint/application/ResourceServer.cpp
1/*
2 * Copyright 2009, Karsten Heimrich
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 * Karsten Heimrich <host.haiku@gmx.de>
7 *
8 */
9
10#include "ResourceServer.h"
11
12
13#include <Application.h>
14#include <Autolock.h>
15#include <Bitmap.h>
16#include <IconUtils.h>
17#include <Picture.h>
18#include <Roster.h>
19#include <TranslationUtils.h>
20#include <View.h>
21
22
23#include <new>
24
25
26BLocker ResourceServer::fLocker;
27ResourceServer* ResourceServer::fResourceServer = NULL__null;
28
29
30ResourceServer::ResourceServer()
31 : fResource(NULL__null)
32{
33}
34
35
36ResourceServer::~ResourceServer()
37{
38 delete fResource;
39 fResourceServer = NULL__null;
40}
41
42
43ResourceServer*
44ResourceServer::Instance()
45{
46 return Instantiate();
47}
48
49
50status_t
51ResourceServer::GetBitmap(int32 id, BBitmap** bitmap)
52{
53 float width;
54 float height;
55 type_code type;
56
57 if (_GetResourceInfo(id, &type, &width, &height) == B_OK((int)0))
58 return GetBitmap(type, id, width, height, bitmap);
59
60 return B_ERROR(-1);
61}
62
63
64status_t
65ResourceServer::GetBitmap(type_code type, int32 id, float width, float height,
66 BBitmap** bitmap)
67{
68 if (!_Init())
69 return B_ERROR(-1);
70
71 size_t length;
72 const void* data = fResource->LoadResource(type, id, &length);
73 if (data) {
74 if (type == B_VECTOR_ICON_TYPE) {
75 *bitmap = new (std::nothrow) BBitmap(BRect(0.0, 0.0, width - 1.0,
76 height - 1.0), B_RGBA32);
77 if (BIconUtils::GetVectorIcon((uint8*)data, length, *bitmap) != B_OK((int)0)) {
78 delete *bitmap;
79 *bitmap = NULL__null;
80 }
81 } else if (type == B_COLOR_8_BIT_TYPE) {
82 *bitmap = new (std::nothrow) BBitmap(BRect(0.0, 0.0, width - 1.0,
83 height - 1.0), B_CMAP8);
84 if (*bitmap)
85 (*bitmap)->ImportBits(data, int32(length), width, 0, B_CMAP8);
86 } else {
87 BMemoryIO memio(data, length);
88 *bitmap = BTranslationUtils::GetBitmap(&memio);
89 }
90 if (*bitmap)
91 return B_OK((int)0);
92 }
93
94 return B_ERROR(-1);
95}
96
97
98status_t
99ResourceServer::GetPicture(int32 id, BPicture* picture)
100{
101 status_t status = B_ERROR(-1);
102
103 if (!_Init() && !picture)
104 return status;
105
106 float width;
107 float height;
108 type_code type;
109
110 if (_GetResourceInfo(id, &type, &width, &height) == B_OK((int)0)) {
111 BBitmap* bitmap = NULL__null;
112 if (GetBitmap(type, id, width, height, &bitmap) == B_OK((int)0))
113 status = _FillPicture(bitmap, picture);
114 delete bitmap;
115 }
116
117 return status;
118}
119
120
121status_t
122ResourceServer::GetPicture(int32 id, BPicture** picture)
123{
124 float width;
125 float height;
126 type_code type;
127
128 if (_GetResourceInfo(id, &type, &width, &height) == B_OK((int)0))
129 return GetPicture(type, id, width, height, picture);
130
131 return B_ERROR(-1);
132}
133
134
135status_t
136ResourceServer::GetPicture(type_code type, int32 id, float width, float height,
137 BPicture** picture)
138{
139 status_t status = B_ERROR(-1);
140
141 if (!_Init())
142 return status;
143
144 BBitmap* bitmap = NULL__null;
145 if (GetBitmap(type, id, width, height, &bitmap) == B_OK((int)0)) {
146 *picture = new (std::nothrow) BPicture();
147 if ((status = _FillPicture(bitmap, *picture)) != B_OK((int)0)) {
148 delete *picture;
149 *picture = NULL__null;
150 }
151 delete bitmap;
152 }
153
154 return status;
155}
156
157
158ResourceServer*
159ResourceServer::Instantiate()
160{
161 if (fResourceServer == NULL__null) {
162 BAutolock _(&fLocker);
163 if (fResourceServer == NULL__null)
164 fResourceServer = new (std::nothrow) ResourceServer();
165 }
166 return fResourceServer;
167}
168
169
170void
171ResourceServer::DestroyServer()
172{
173 if (fResourceServer) {
174 delete fResourceServer;
175 fResourceServer = NULL__null;
176 }
177}
178
179
180bool
181ResourceServer::_Init()
182{
183 if (fResource)
184 return true;
185
186 app_info appInfo;
187 be_app->GetAppInfo(&appInfo);
188
189 BFile app(&(appInfo.ref), B_READ_ONLY0x0000);
190 if (app.InitCheck() == B_OK((int)0))
191 fResource = new (std::nothrow) BResources(&app);
192
193 return (fResource != NULL__null);
194}
195
196
197status_t
198ResourceServer::_FillPicture(const BBitmap* bitmap, BPicture* picture)
199{
200 status_t status = B_ERROR(-1);
201
202 if (!bitmap || !picture)
203 return status;
204
205 BBitmap* offscreenBitmap = new (std::nothrow) BBitmap(bitmap->Bounds(),
206 B_RGBA32, true);
207 if (offscreenBitmap) {
208 BView* view = new (std::nothrow) BView(bitmap->Bounds(), "offscreen",
209 B_FOLLOW_NONE0, B_WILL_DRAW);
210 if (view) {
211 status = B_OK((int)0);
212 offscreenBitmap->Lock();
213 offscreenBitmap->AddChild(view);
214 view->SetDrawingMode(B_OP_ALPHA);
215 view->BeginPicture(picture);
216 view->DrawBitmap(bitmap);
217 picture = view->EndPicture();
Value stored to 'picture' is never read
218 offscreenBitmap->Unlock();
219 }
220 delete offscreenBitmap;
221 }
222
223 return status;
224}
225
226
227status_t
228ResourceServer::_GetResourceInfo(int32 id, type_code* type, float* width,
229 float* height)
230{
231 status_t status = B_OK((int)0);
232
233 switch (id) {
234 case LEFT_ARROW: {
235 case RIGHT_ARROW:
236 case LEFT_ARROW_PUSHED:
237 case RIGHT_ARROW_PUSHED:
238 *width = 9.0;
239 *height = 13.0;
240 *type = B_COLOR_8_BIT_TYPE;
241 } break;
242
243 case OK_BUTTON: {
244 case CANCEL_BUTTON:
245 case OK_BUTTON_PUSHED:
246 case CANCEL_BUTTON_PUSHED:
247 *width = 16.0;
248 *height = 16.0;
249 *type = B_COLOR_8_BIT_TYPE;
250 } break;
251
252 case POP_UP_LIST: {
253 case POP_UP_LIST_PUSHED:
254 *width = 10.0;
255 *height = 20.0;
256 *type = B_COLOR_8_BIT_TYPE;
257 } break;
258
259 default: {
260 *width = 0.0;
261 *height = 0.0;
262 status = B_ERROR(-1);
263 *type = B_ANY_TYPE;
264 } break;
265 }
266
267 return status;
268}