diff --git a/src/mcx_utils.c b/src/mcx_utils.c index f990f7e..ef468cc 100644 --- a/src/mcx_utils.c +++ b/src/mcx_utils.c @@ -292,7 +292,7 @@ void mcx_initcfg(Config* cfg) { cfg->debuglevel = 0; cfg->gpuid = 0; - memset(cfg->bc, 0, 12); + memset(cfg->bc, 0, 13); memset(&cfg->his, 0, sizeof(History)); memcpy(cfg->his.magic, "MCXH", 4); cfg->his.version = 1; diff --git a/src/mcx_utils.h b/src/mcx_utils.h index 86b629a..6db7642 100644 --- a/src/mcx_utils.h +++ b/src/mcx_utils.h @@ -232,7 +232,7 @@ typedef struct MCXConfig { int parentid; /**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); diff --git a/src/pmcxcl.cpp b/src/pmcxcl.cpp index 01ad2d7..3009c56 100644 --- a/src/pmcxcl.cpp +++ b/src/pmcxcl.cpp @@ -758,11 +758,10 @@ void parse_config(const py::dict& user_cfg, Config& mcx_config) { std::string bc_string = py::str(user_cfg["bc"]); if (bc_string.empty() || bc_string.size() > 12) { - throw py::value_error("the 'bc' field must be a non-empty string / have less than 12 characters."); + throw py::value_error("the 'bc' field must be a non-empty string / have no less than 12 characters."); } - strncpy(mcx_config.bc, bc_string.c_str(), bc_string.size() + 1); - mcx_config.bc[bc_string.size()] = '\0'; + 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")) {