Skip to content

Commit a5bd8e4

Browse files
committed
Fix out of bounds access of plane of reflection when use_single_sample=0
1 parent 6f6bda6 commit a5bd8e4

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

mcstas-comps/examples/Tests_optics/Test_Monochromator_bent_complex/Test_Monochromator_bent_complex.instr

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* Used as a test instrument to highlight Monochromator Bent complex's capabilities
1919
*
2020
* %Example: Test_Monochromator_bent_complex.instr mos=60 Detector: E_PSD_mon_end_I=0.000215194
21+
* %Example: Test_Monochromator_bent_complex.instr mos=60 use_single_plane=1 Detector: E_PSD_mon_end_I=0.000215194
2122
*
2223
* %Parameters
2324
* sample_x: [m] Source horz illumination
@@ -39,7 +40,8 @@ double L1=2.47143,
3940
double Ld=2,
4041
double det_rot=-6.00000,
4142
double mos=60,
42-
double extra=0)
43+
double extra=0,
44+
int use_single_plane = 0)
4345

4446
DECLARE
4547
%{
@@ -62,7 +64,8 @@ double z_pos[92];
6264
double x_rot[92];
6365
double y_rot[92];
6466
double z_rot[92];
65-
char input_planes[552];
67+
char *input_planes;
68+
6669
double z_test[2];
6770
double y_test[2];
6871
double z_test1[2];
@@ -157,13 +160,25 @@ double y_rots[92] = {
157160
28.949037231991614,29.10800625807111,29.263677094830634,29.415964179519083,29.5647341124584,
158161
29.70985123904334,29.85123876074083,29.988616895395413,30.1218449608264,30.374816895175396,
159162
30.60585732884762,30.807078570093147};
160-
strcpy(input_planes, "Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;"
161-
"Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;"
162-
"Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;"
163-
"Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;"
164-
"Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;"
165-
"Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;"
166-
"Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111");
163+
if (use_single_plane){
164+
165+
input_planes = malloc(5*sizeof(char));
166+
input_planes = "Si111";
167+
} else {
168+
printf("Running input planes\n");
169+
input_planes = malloc(92*5*sizeof(char) + 92*sizeof(char));
170+
printf("Malloc worked!\n");
171+
strcpy(input_planes, "Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;"
172+
"Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;"
173+
"Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;"
174+
"Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;"
175+
"Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;"
176+
"Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;"
177+
"Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111;Si111");
178+
printf("\nAfter input planes\n");
179+
}
180+
181+
167182
for (int i=0; i<92; i++){
168183
rad_y[i]=0;
169184
xthic[i] = 0.0005;

0 commit comments

Comments
 (0)