Bug Summary

File:home/HaikuArchives/ArtPaint/addons/AddOns/Grayscale/GrayscaleAddOn.cpp
Warning:line 76, column 30
Called C++ object pointer is null

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 GrayscaleAddOn.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 ../../UtilityClasses/ -iquote ./ -iquote ../../../artpaint/application -iquote ../../../artpaint/controls -iquote ../../../artpaint/layers -iquote ../../../artpaint/paintwindow -iquote ../../../artpaint/tools -iquote ../../../artpaint/viewmanipulators -iquote ../../../artpaint/windows -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/addons/AddOns/Grayscale -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++ GrayscaleAddOn.cpp
1/*
2 * Copyright 2003, Heikki Suhonen
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 * Heikki Suhonen <heikki.suhonen@gmail.com>
7 *
8 */
9#include <Bitmap.h>
10#include <Catalog.h>
11#include <Message.h>
12#include <StatusBar.h>
13#include <Window.h>
14
15#include "AddOns.h"
16#include "ManipulatorInformer.h"
17#include "GrayscaleAddOn.h"
18#include "Selection.h"
19
20#undef B_TRANSLATION_CONTEXT"AddOns_Grayscale"
21#define B_TRANSLATION_CONTEXT"AddOns_Grayscale" "AddOns_Grayscale"
22
23
24#ifdef __cplusplus201402L
25extern "C" {
26#endif
27 char name[255] = B_TRANSLATE_MARK("Grayscale")("Grayscale");
28 char menu_help_string[255] = B_TRANSLATE_MARK("Converts the active layer to grayscale.")("Converts the active layer to grayscale.");
29 int32 add_on_api_version = ADD_ON_API_VERSION;
30 add_on_types add_on_type = COLOR_ADD_ON;
31#ifdef __cplusplus201402L
32}
33#endif
34
35
36Manipulator* instantiate_add_on(BBitmap *bm,ManipulatorInformer *i)
37{
38 delete i;
39 return new GrayscaleAddOnManipulator(bm);
40}
41
42
43
44GrayscaleAddOnManipulator::GrayscaleAddOnManipulator(BBitmap*)
45 : Manipulator()
46{
47}
48
49
50GrayscaleAddOnManipulator::~GrayscaleAddOnManipulator()
51{
52
53}
54
55
56BBitmap* GrayscaleAddOnManipulator::ManipulateBitmap(BBitmap *original,Selection *selection,BStatusBar *status_bar)
57{
58 // We may create another bitmap and return it instead of original, but we may
59 // also do the manipulation on the original and return it. We Should send messages
60 // to progress_view that contain B_UPDATE_STATUS_BAR as their 'what'. The sum of
61 // message deltas should equal 100*prog_step.
62 BMessage progress_message = BMessage(B_UPDATE_STATUS_BAR);
63 progress_message.AddFloat("delta",0.0);
64 if (status_bar != NULL__null) {
1
Assuming 'status_bar' is equal to NULL
2
Taking false branch
65 progress_message.ReplaceFloat("delta",100);
66 status_bar->Window()->PostMessage(&progress_message,status_bar);
67 }
68
69 int32 bits_length = original->BitsLength()/4;
70 uint32 *bits = (uint32*)original->Bits();
71 float blue,red,green;
72 union {
73 uint8 bytes[4];
74 uint32 word;
75 } color;
76 if ((selection == NULL__null) && (selection->IsEmpty() == TRUE1)) {
3
Assuming 'selection' is equal to NULL
4
Called C++ object pointer is null
77 for (int32 i=0;i<bits_length;i++) {
78 color.word = *bits;
79 blue = color.bytes[0] * 0.114;
80 green = color.bytes[1] * 0.587;
81 red = color.bytes[2] * 0.299;
82 float sum = blue + red + green;
83 color.bytes[0] = sum;
84 color.bytes[1] = sum;
85 color.bytes[2] = sum;
86 *bits++ = color.word;
87 }
88 }
89 else {
90 int32 width = original->Bounds().Width();
91 int32 height = original->Bounds().Height();
92 for (int32 y=0;y<=height;y++) {
93 for (int32 x=0;x<=width;x++) {
94 if (selection->ContainsPoint(x,y)) {
95 color.word = *bits;
96 blue = color.bytes[0] * 0.114;
97 green = color.bytes[1] * 0.587;
98 red = color.bytes[2] * 0.299;
99 float sum = blue + red + green;
100 color.bytes[0] = sum;
101 color.bytes[1] = sum;
102 color.bytes[2] = sum;
103 *bits++ = color.word;
104 }
105 else {
106 ++bits;
107 }
108 }
109 }
110 }
111 return original;
112}
113
114
115const char* GrayscaleAddOnManipulator::ReturnHelpString()
116{
117 return B_TRANSLATE("Converts the active layer to grayscale.")BLocaleRoster::Default()->GetCatalog()->GetString(("Converts the active layer to grayscale."
), "AddOns_Grayscale")
;
118}
119
120
121const char* GrayscaleAddOnManipulator::ReturnName()
122{
123 return B_TRANSLATE("Grayscale")BLocaleRoster::Default()->GetCatalog()->GetString(("Grayscale"
), "AddOns_Grayscale")
;
124}