From ddcb6e4923856ea10e910d99af312e8d65820bd0 Mon Sep 17 00:00:00 2001 From: Tom Theile Date: Tue, 14 Mar 2023 16:47:47 +0100 Subject: [PATCH] runs on linux! prevent buffer overflow by 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... --- src/src/io.c | 2 +- src/src/load.cpp | 12 ++++++------ tests/testthat/test_futurecalls.R | 2 +- tests/testthat/testit2.R | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/src/io.c b/src/src/io.c index a2cfaac..191386c 100644 --- a/src/src/io.c +++ b/src/src/io.c @@ -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) { diff --git a/src/src/load.cpp b/src/src/load.cpp index 51cf21c..24a9137 100644 --- a/src/src/load.cpp +++ b/src/src/load.cpp @@ -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); @@ -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"); @@ -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" @@ -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); diff --git a/tests/testthat/test_futurecalls.R b/tests/testthat/test_futurecalls.R index 2ed1bad..f647106 100644 --- a/tests/testthat/test_futurecalls.R +++ b/tests/testthat/test_futurecalls.R @@ -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 diff --git a/tests/testthat/testit2.R b/tests/testthat/testit2.R index fc8e169..19e9ac0 100644 --- a/tests/testthat/testit2.R +++ b/tests/testthat/testit2.R @@ -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"