Skip to content

Commit

Permalink
treat cfg->bc as a null-ending string, #191 #192
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Oct 3, 2023
1 parent 68db492 commit 2e71a51
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/mcx_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ typedef struct __align__(16) KernelParams {
unsigned int srcnum; /**< total number of source patterns */
unsigned int nphase; /**< number of samples for inverse-cdf, will be added by 2 to include -1 and 1 on the two ends */
float omega; /**< modulation angular frequency (2*pi*f), in rad/s, for FD/RF replay */
unsigned char bc[12]; /**< boundary conditions */
unsigned char bc[12]; /**< boundary condition flags, copy the first 12 chars from cfg->bc without the terminating NULL */
} MCXParam;

void mcx_run_simulation(Config* cfg, GPUInfo* gpu);
Expand Down
2 changes: 1 addition & 1 deletion src/mcx_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ typedef struct MCXConfig {
float* dx; /**< anisotropic voxel spacing for x-axis */
float* dy; /**< anisotropic voxel spacing for y-axis */
float* dz; /**< anisotropic voxel spacing for z-axis */
char bc[13]; /**<boundary condition flag for [-x,-y,-z,+x,+y,+z, det(-x,-y,-z,+x,+y,+z)] */
char bc[13]; /**<boundary condition flag for [-x,-y,-z,+x,+y,+z, det(-x,-y,-z,+x,+y,+z)], last element is always NULL for string termination */
unsigned int nphase; /**< number of samples for inverse-cdf, will be added by 2 to include -1 and 1 on the two ends */
float* invcdf; /**< equal-space sampled inversion of CDF(cos(theta)) for the phase function of the zenith angle */
} Config;
Expand Down
3 changes: 1 addition & 2 deletions src/mcxlab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1063,8 +1063,7 @@ void mcx_set_field(const mxArray* root, const mxArray* item, int idx, Config* cf
mexErrMsgTxt("the 'bc' field must be a non-empty string");
}

mxGetString(item, cfg->bc, len + 1);
cfg->bc[len] = '\0';
mxGetString(item, cfg->bc, len + 1); // copy the string, plus the ending NULL, max 13 char
printf("mcx.bc='%s';\n", cfg->bc);
} else if (strcmp(name, "detphotons") == 0) {
arraydim = mxGetDimensions(item);
Expand Down
2 changes: 1 addition & 1 deletion src/pmcx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ void parse_config(const py::dict& user_cfg, Config& mcx_config) {
throw py::value_error("the 'bc' field must be a non-empty string / have no more than 12 characters.");
}

strncpy(mcx_config.bc, bc_string.c_str(), bc_string.size());
strncpy(mcx_config.bc, bc_string.c_str(), bc_string.size() + 1); // copy the string, plus the ending NULL, max 13 char
}

if (user_cfg.contains("detphotons")) {
Expand Down

0 comments on commit 2e71a51

Please sign in to comment.