Skip to content

Commit d968242

Browse files
authored
Merge pull request #2090 from willend/cppcheck-hints
Implement 'cppcheck' linting support on Unix, can be utilised via mcrun or mctest
2 parents 7ed26c9 + 40a9fc1 commit d968242

15 files changed

Lines changed: 111 additions & 40 deletions

.github/workflows/mcstas-basictest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ jobs:
175175
./install_mcstas/bin/${MCSTAS_EXECUTABLE} --version
176176
mkdir run_RNG && cd run_RNG
177177
cp ../install_mcstas/share/mcstas/resources/examples/Tests_RNG/Test_RNG_rand01/Test_RNG_rand01.instr .
178-
../install_mcstas/bin/${MCRUN_EXECUTABLE} Test_RNG_rand01.instr -s1000 seed=1000 -d RNGtest
178+
../install_mcstas/bin/${MCRUN_EXECUTABLE} Test_RNG_rand01.instr -s1000 Ncount=1000 -d RNGtest
179179
export SUM=`grep -v \# RNGtest/rngout.dat | ${MD5SUM} | cut -f1 -d\ `
180180
export EXPECTED="f192ce4609e2225bf9d42ce9c5fa5a86"
181181
if [ "${EXPECTED}" == "${SUM}" ];

.github/workflows/mcstas-winbasictest-mingw.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ jobs:
131131

132132
- name: Run rng instrument
133133
working-directory: run_rng
134-
run: ..\install\bin\mcrun --verbose test.instr -s1000 seed=1000 -d RNGtest
134+
run: ..\install\bin\mcrun --verbose test.instr -s1000 Ncount=1000 -d RNGtest
135135

136136
- name: Test RNG instrument output
137137
working-directory: run_rng

.github/workflows/mcstas-winbasictest-msvc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ jobs:
151151

152152
- name: Run rng instrument
153153
working-directory: run_rng
154-
run: ..\install\bin\mcrun --verbose test.instr -s1000 seed=1000 -d RNGtest
154+
run: ..\install\bin\mcrun --verbose test.instr -s1000 Ncount=1000 -d RNGtest
155155

156156
- name: Test RNG instrument output
157157
working-directory: run_rng

.github/workflows/mcxtrace-basictest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ jobs:
178178
./install_mcxtrace/bin/${MCXTRACE_EXECUTABLE} --version
179179
mkdir run_RNG && cd run_RNG
180180
cp ../install_mcxtrace/share/mcxtrace/resources/examples/Tests_RNG/Test_RNG_rand01/Test_RNG_rand01.instr .
181-
../install_mcxtrace/bin/${MXRUN_EXECUTABLE} Test_RNG_rand01.instr -s1000 seed=1000 -d RNGtest
181+
../install_mcxtrace/bin/${MXRUN_EXECUTABLE} Test_RNG_rand01.instr -s1000 Ncount=1000 -d RNGtest
182182
export SUM=`grep -v \# RNGtest/rngout.dat | ${MD5SUM} | cut -f1 -d\ `
183183
export EXPECTED="f192ce4609e2225bf9d42ce9c5fa5a86"
184184
if [ "${EXPECTED}" == "${SUM}" ];

.github/workflows/mcxtrace-winbasictest-mingw.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ jobs:
120120

121121
- name: Run rng instrument
122122
working-directory: run_rng
123-
run: ..\install\bin\mxrun --verbose test.instr -s1000 seed=1000 -d RNGtest
123+
run: ..\install\bin\mxrun --verbose test.instr -s1000 Ncount=1000 -d RNGtest
124124

125125
- name: Test RNG instrument output
126126
working-directory: run_rng

.github/workflows/mcxtrace-winbasictest-msvc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ jobs:
142142

143143
- name: Run rng instrument
144144
working-directory: run_rng
145-
run: ..\install\bin\mxrun --verbose test.instr -s1000 seed=1000 -d RNGtest
145+
run: ..\install\bin\mxrun --verbose test.instr -s1000 Ncount=1000 -d RNGtest
146146

147147
- name: Test RNG instrument output
148148
working-directory: run_rng

common/lib/share/mccode-r.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,8 +2009,17 @@ int mcdetector_out_axis_nexus(NXhandle f, char *label, char *var, int rank, long
20092009
else {
20102010
double *axis;
20112011
axis=malloc(sizeof(double)*length);
2012+
if (!axis ) {
2013+
printf("Fatal memory error allocating NeXus axis of length %li, exiting!\n", length);
2014+
return(NX_ERROR);
2015+
}
20122016
char *valid;
20132017
valid=malloc(sizeof(char)*CHAR_BUF_LENGTH);
2018+
if (!valid ) {
2019+
printf("Fatal memory error allocating label axis of length %li, exiting!\n", CHAR_BUF_LENGTH);
2020+
free(axis);
2021+
return(NX_ERROR);
2022+
}
20142023
int dim=(int)length;
20152024
int i;
20162025
int nprimary=1;

mccode/nlib/share/mcstas-r.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ _class_particle mcsetstate(double x, double y, double z, double vx, double vy, d
8080
mcneutron._mctmp_a = mcneutron._mctmp_b = mcneutron._mctmp_c = 0;
8181
// what about mcneutron._logic ?
8282
mcneutron._logic.dummy=1;
83+
// init uservars via cogen'd-function
84+
particle_uservar_init(&mcneutron);
85+
8386
return(mcneutron);
8487
} /* mcsetstate */
8588

mccode/src/cogen.c.in

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,7 +2053,6 @@ int cogen_raytrace(struct instr_def *instr)
20532053
coutf(" #endif");
20542054
coutf("");
20552055
coutf(" srandom(_hash((pidx+1)*(seed+1)));");
2056-
coutf(" particle_uservar_init(_particle);");
20572056
coutf("");
20582057
coutf(" raytrace(_particle);");
20592058
coutf(" } /* inner for */");
@@ -2182,7 +2181,6 @@ int cogen_rt_funnel(struct instr_def *instr)
21822181
coutf(" _particle->_uid += mpi_node_rank * ncount; ");
21832182
coutf(" #endif");
21842183
coutf(" srandom(_hash((pidx+1)*(seed+1))); // _particle->state usage built into srandom macro");
2185-
coutf(" particle_uservar_init(_particle);");
21862184
coutf(" }");
21872185
cout( "");
21882186

mccode/xlib/share/mcxtrace-r.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ _class_particle mcsetstate(double x, double y, double z, double kx, double ky, d
5959
mcphoton._restore = 0;
6060
mcphoton._scattered = 0;
6161

62+
// init uservars via cogen'd-function
63+
particle_uservar_init(&mcphoton);
64+
6265
return(mcphoton);
6366
} /* mcsetstate */
6467

0 commit comments

Comments
 (0)