Bug Summary

File:/home/sdobbs/work/clang/halld_recon/src/libraries/HDGEOMETRY/DMagneticFieldMapSpoiled.cc
Warning:line 79, column 3
1st function call argument is an uninitialized value

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -main-file-name DMagneticFieldMapSpoiled.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 -fhalf-no-semantic-interposition -mframe-pointer=none -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 /w/halld-scifs17exp/home/sdobbs/clang/llvm-project/install/lib/clang/12.0.0 -D HAVE_CCDB -D HAVE_RCDB -D HAVE_EVIO -D HAVE_TMVA=1 -D RCDB_MYSQL=1 -D RCDB_SQLITE=1 -D SQLITE_USE_LEGACY_STRUCT=ON -I .Linux_CentOS7.7-x86_64-gcc4.8.5/libraries/HDGEOMETRY -I libraries/HDGEOMETRY -I . -I libraries -I libraries/include -I /w/halld-scifs17exp/home/sdobbs/clang/halld_recon/Linux_CentOS7.7-x86_64-gcc4.8.5/include -I external/xstream/include -I /usr/include/tirpc -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/root/root-6.08.06/include -I /w/halld-scifs17exp/halld2/home/sdobbs/Software/jana/jana_0.8.2/Linux_CentOS7.7-x86_64-gcc4.8.5/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/ccdb/ccdb_1.06.06/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/rcdb/rcdb_0.06.00/cpp/include -I /usr/include/mysql -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/sqlitecpp/SQLiteCpp-2.2.0^bs130/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/sqlite/sqlite-3.13.0^bs130/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/hdds/hdds-4.9.0/Linux_CentOS7.7-x86_64-gcc4.8.5/src -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/xerces-c/xerces-c-3.1.4/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/evio/evio-4.4.6/Linux-x86_64/include -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5 -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/x86_64-redhat-linux -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/backward -internal-isystem /usr/local/include -internal-isystem /w/halld-scifs17exp/home/sdobbs/clang/llvm-project/install/lib/clang/12.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /home/sdobbs/work/clang/halld_recon/src -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -o /tmp/scan-build-2021-01-21-110224-160369-1 -x c++ libraries/HDGEOMETRY/DMagneticFieldMapSpoiled.cc
1// $Id$
2//
3// File: DMagneticFieldMapSpoiled.cc
4// Created: Wed Mar 25 04:04:16 EDT 2009
5// Creator: davidl (on Darwin Amelia.local 9.6.0 i386)
6//
7
8#include "DMagneticFieldMapSpoiled.h"
9#include "DMagneticFieldMapCalibDB.h"
10
11#include <iostream>
12#include <cmath>
13using namespace std;
14
15#include <JANA/JApplication.h>
16#include <JANA/JParameterManager.h>
17using namespace jana;
18
19#include <DVector3.h>
20
21//---------------------------------
22// DMagneticFieldMapSpoiled (Constructor)
23//---------------------------------
24DMagneticFieldMapSpoiled::DMagneticFieldMapSpoiled(JApplication *japp, unsigned int run_number, string namepath)
25{
26 bfield = new DMagneticFieldMapCalibDB(japp, run_number, namepath);
27
28 initialized = false;
29}
30
31//---------------------------------
32// DMagneticFieldMapSpoiled (Constructor)
33//---------------------------------
34DMagneticFieldMapSpoiled::DMagneticFieldMapSpoiled(JCalibration *jcalib, string namepath)
35{
36 bfield = new DMagneticFieldMapCalibDB(jcalib, namepath);
37
38 initialized = false;
39}
40
41//---------------------------------
42// ~DMagneticFieldMapSpoiled (Destructor)
43//---------------------------------
44DMagneticFieldMapSpoiled::~DMagneticFieldMapSpoiled()
45{
46 if(bfield)delete bfield;
47}
48
49//---------------------------------
50// Init
51//---------------------------------
52void DMagneticFieldMapSpoiled::Init(void)
53{
54 phi_amp = 0.0;
55 phi_omega = M_PI3.14159265358979323846/(2.0*M_PI3.14159265358979323846);
56 r_amp = 0.0;
57 r_omega = M_PI3.14159265358979323846/65.0;
58 z_amp = 0.0;
59 z_omega = M_PI3.14159265358979323846/(20.0);
60
61 if(!gPARMS){
62 _DBG_std::cerr<<"libraries/HDGEOMETRY/DMagneticFieldMapSpoiled.cc"
<<":"<<62<<" "
<<"gPARMS==NULL!"<<endl;
63 return;
64 }
65
66 gPARMS->SetDefaultParameter("BFIELD:PHI_AMP", phi_amp);
67 gPARMS->SetDefaultParameter("BFIELD:PHI_OMEGA", phi_omega);
68 gPARMS->SetDefaultParameter("BFIELD:R_AMP", r_amp);
69 gPARMS->SetDefaultParameter("BFIELD:R_OMEGA", r_omega);
70 gPARMS->SetDefaultParameter("BFIELD:Z_AMP", z_amp);
71 gPARMS->SetDefaultParameter("BFIELD:Z_OMEGA", z_omega);
72
73 initialized=true;
74}
75
76void DMagneticFieldMapSpoiled::GetField(const DVector3 &pos,DVector3 &Bout) const{
77 double Bx,By,Bz;
1
'Bx' declared without an initial value
78 GetField(pos.x(),pos.y(),pos.z(),Bx,By,Bz);
2
Calling 'DMagneticFieldMapSpoiled::GetField'
7
Returning from 'DMagneticFieldMapSpoiled::GetField'
79 Bout.SetXYZ(Bx,By,Bz);
8
1st function call argument is an uninitialized value
80}
81
82//---------------------------------
83// GetField
84//---------------------------------
85void DMagneticFieldMapSpoiled::GetField(double x, double y, double z, double &Bx, double &By, double &Bz, int method) const
86{
87 if(!initialized){
3
Assuming field 'initialized' is false
4
Taking true branch
88 DMagneticFieldMapSpoiled *mythis = const_cast<DMagneticFieldMapSpoiled*>(this);
89 mythis->Init();
90 }
91 if(!initialized
4.1
Field 'initialized' is false
)return;
5
Taking true branch
6
Returning without writing to 'Bx'
92 bfield->GetField(x, y, z, Bx, By, Bz, method);
93
94 DVector3 B(Bx, By, Bz);
95 double r = sqrt(x*x + y*y);
96 double phi = atan2(y,x);
97 if(phi<0.0)phi+=2.0*M_PI3.14159265358979323846;
98
99 // Apply phi dependance
100 double fac = phi_amp*sin(phi_omega*phi) + 1.0;
101
102 // Apply r dependance
103 fac *= r_amp*sin(r_omega*r) + 1.0;
104
105 // Apply z dependance
106 fac *= z_amp*sin(z_omega*z) + 1.0;
107
108 B *= fac;
109 Bx = B.X();
110 By = B.Y();
111 Bz = B.Z();
112
113}
114
115
116//---------------------------------
117// get z-component of magnetic field
118//---------------------------------
119double DMagneticFieldMapSpoiled::GetBz(double x, double y, double z) const
120{
121 if(!initialized){
122 DMagneticFieldMapSpoiled *mythis = const_cast<DMagneticFieldMapSpoiled*>(this);
123 mythis->Init();
124 }
125 if(!initialized)return 0.;
126 double Bx,By,Bz;
127 bfield->GetField(x, y, z, Bx, By, Bz);
128
129 DVector3 B(Bx, By, Bz);
130 double r = sqrt(x*x + y*y);
131 double phi = atan2(y,x);
132 if(phi<0.0)phi+=2.0*M_PI3.14159265358979323846;
133
134 // Apply phi dependance
135 double fac = phi_amp*sin(phi_omega*phi) + 1.0;
136
137 // Apply r dependance
138 fac *= r_amp*sin(r_omega*r) + 1.0;
139
140 // Apply z dependance
141 fac *= z_amp*sin(z_omega*z) + 1.0;
142
143 B *= fac;
144 return B.Z();
145
146}
147
148
149//---------------------------------
150// GetFieldGradient
151//---------------------------------
152void DMagneticFieldMapSpoiled::GetFieldGradient(double x, double y, double z,
153 double &dBxdx, double &dBxdy,
154 double &dBxdz,
155 double &dBydx, double &dBydy,
156 double &dBydz,
157 double &dBzdx, double &dBzdy,
158 double &dBzdz) const
159{
160 if(!initialized){
161 DMagneticFieldMapSpoiled *mythis = const_cast<DMagneticFieldMapSpoiled*>(this);
162 mythis->Init();
163 }
164 if(!initialized)return;
165 bfield->GetFieldGradient(x, y, z, dBxdx, dBxdy, dBxdz, dBydx, dBydy, dBydz, dBzdx, dBzdy, dBzdz);
166}
167
168
169void DMagneticFieldMapSpoiled::GetFieldBicubic(double x,double y,double z,
170 double &Bx,double &By,double &Bz) const{
171 if(!initialized){
172 DMagneticFieldMapSpoiled *mythis = const_cast<DMagneticFieldMapSpoiled*>(this);
173 mythis->Init();
174 }
175 if(!initialized)return;
176 bfield->GetFieldBicubic(x,y,z,Bx,By,Bz);
177}
178
179
180void DMagneticFieldMapSpoiled::GetFieldAndGradient(double x,double y,double z,
181 double &Bx,double &By,
182 double &Bz,
183 double &dBxdx, double &dBxdy,
184 double &dBxdz,
185 double &dBydx, double &dBydy,
186 double &dBydz,
187 double &dBzdx, double &dBzdy,
188 double &dBzdz) const{
189 if(!initialized){
190 DMagneticFieldMapSpoiled *mythis = const_cast<DMagneticFieldMapSpoiled*>(this);
191 mythis->Init();
192 }
193 if(!initialized)return;
194 bfield->GetFieldAndGradient(x,y,z,Bx,By,Bz,dBxdx,dBxdy,dBxdz,
195 dBydx,dBydy,dBydz,dBzdx,dBzdy,dBzdz);
196}