Skip to content

Commit

Permalink
runs on linux! prevent buffer overflow by
Browse files Browse the repository at this point in the history
reducing the number of characters to copy into logstring

also increased the size of some buffers to try to prevent overflows and warnings.
still gives warnings...
  • Loading branch information
tomthe committed Mar 14, 2023
1 parent 4898227 commit ddcb6e4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ void prepare_output_files(int seg)
***********************************************/

logmsg("--t prepare_output_files_1 \n"," ",1);
char segnum[6];
char segnum[10];

if (seg == 0)
{
Expand Down
12 changes: 6 additions & 6 deletions src/src/load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ int load( char *file)
int create_output_fn_dir(){
// concatenate "sim_results_" with the name of the supplement file:
//sprintf(output_file_name, "sim_results_%s", words[1]);
char buffer_output_dir [250];
char buffer_output_fn [250];
char buffer_output_dir [1024];
char buffer_output_fn [1024];
sprintf (buffer_output_dir, "sim_results_%s_%ld_%s/", rate_file_name, original_seed,result_suffix);
sprintf (buffer_output_fn, "%sresult", buffer_output_dir);

Expand All @@ -364,7 +364,7 @@ int create_output_fn_dir(){


// copy the .sup-file (rate_file_name) into the subfolder:
char buffer_sup_fn_dest [250];
char buffer_sup_fn_dest [1024];
sprintf (buffer_sup_fn_dest, "%s%s", buffer_output_dir, rate_file_name);
FILE *source = fopen(rate_file_name, "rb");
FILE *destination = fopen(buffer_sup_fn_dest, "wb");
Expand Down Expand Up @@ -2387,7 +2387,7 @@ specified for unmarried males THESE RATES WILL BE IGNORED.",1);
}
if (rates_test == 0)
{
char logstring[512];
// char logstring[512];
sprintf(logstring,
" ***NO DEATH RATES specified for SINGLE %ss \n"
" ***of ANY group This is unusual -- are you SURE you know \n"
Expand Down Expand Up @@ -2423,11 +2423,11 @@ specified for unmarried males THESE RATES WILL BE IGNORED.",1);
if (1)
{
sprintf(logstring,
"* - - - - - - - - - - - - - - - - - - - - - - \n"
"* \n\n"
"* group: %d event: %d, %s sex:%d, %s mstatus:%d, %s, \n"
"* upper age: %d has rate with zero duration\n"
"* crnt->width: %d ; crnt->lambda: %7.4f\n crnt->mu %7.4f, crnt->modified_lambda: %f"
"* - - - - - - - - - - - - - - - - - - - - - - ",
"* \n",
grp, event,index_to_event[event], sex, index_to_sex[sex], mstat,
index_to_mstatus[mstat], crnt->upper_age, crnt->width,
crnt->lambda, crnt->mu,crnt->modified_lambda);
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test_futurecalls.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ library("rsocsim")

# create a new folder for all the files related to a simulation.
# this will be in your home- or user-directory:
folder = "C:\\Users\\tom\\socsim\\socsim_sim_2186\\"#rsocsim::create_simulation_folder()
folder = socsim::create_simulation_folder()

# create a new supplement-file. Supplement-files tell socsim what
# to simulate. create_sup_file will create a very basic supplement filee
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/testit2.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ supfile

seed = 47

rsocsim::socsim(folder,supfile,seed,suffix="te/st1")#,process_method = "inprocess")
rsocsim::socsim(folder,supfile,seed,suffix="test1")#,process_method = "inprocess")


supfile = "CousinDiversity.sup"
Expand Down

0 comments on commit ddcb6e4

Please sign in to comment.