diff --git a/rogueviz/sag/annealing.cpp b/rogueviz/sag/annealing.cpp index e96595de..d5550cff 100644 --- a/rogueviz/sag/annealing.cpp +++ b/rogueviz/sag/annealing.cpp @@ -144,7 +144,7 @@ void dofullsa(ld satime) { if(t2 - tl > view_each * .98) { tl = t2; - println(hlog, format("it %12Ld temp %6.4f [1/e at %13.6f] cost = %f ", + println(hlog, format("it %12lld temp %6.4f [1/e at %13.6f] cost = %f ", numiter, double(sag::temperature), (double) exp(sag::temperature), double(sag::cost))); } @@ -205,7 +205,7 @@ void dofullsa_iterations(long long saiter) { if(cpct > lpct && output_fullsa) { lpct = cpct; - println(hlog, format("it %12Ld ratio %6.3f temp %8.4f step %9.3g cost %9.2f R=%8.4f T=%8.4f", + println(hlog, format("it %12lld ratio %6.3f temp %8.4f step %9.3g cost %9.2f R=%8.4f T=%8.4f", numiter, last_ratio, double(sag::temperature), (double) exp(sag::temperature), cost, lgsag.R, lgsag.T)); } diff --git a/rogueviz/sag/cells.cpp b/rogueviz/sag/cells.cpp index cdc03c3b..af7f2e6d 100644 --- a/rogueviz/sag/cells.cpp +++ b/rogueviz/sag/cells.cpp @@ -79,7 +79,7 @@ struct sagdist_t { clear(); fd = open(fname.c_str(), O_RDONLY | O_LARGEFILE); if(fd == -1) throw hr_exception("open failed in map"); - read(fd, &N, 8); + if(read(fd, &N, 8) < 8) throw hr_exception("file error"); tabmap = (distance*) mmap(nullptr, N*N*sizeof(distance)+8, PROT_READ, MAP_SHARED, fd, 0); @@ -117,7 +117,7 @@ struct sagdist_t { void save(string fname) { fd = open(fname.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0666); - write(fd, &N, 8); + if(write(fd, &N, 8) < 8) throw hr_exception("write error"); size_t size = N*N*sizeof(distance); println(hlog, "size is ", hr::format("%zd", size)); char *p = (char*) tab; diff --git a/rogueviz/sag/data.cpp b/rogueviz/sag/data.cpp index 8e4435c0..2d5b0631 100644 --- a/rogueviz/sag/data.cpp +++ b/rogueviz/sag/data.cpp @@ -173,7 +173,7 @@ void load_sag_solution(const string& fname) { void load_sag_solution_basic(const string& fname) { if(!(state & SS_DATA)) throw hr_exception("load_sag_solution_basic with no data"); FILE *f = fopen(fname.c_str(), "rt"); - for(auto& i: sagid) fscanf(f, "%d", &i); + for(auto& i: sagid) if(fscanf(f, "%d", &i) < 1) throw hr_exception("read error in load_sag_solution_basic"); fclose(f); println(hlog, "loaded sagid = ", sagid); diff --git a/rogueviz/sag/sag.cpp b/rogueviz/sag/sag.cpp index 0f0c02e7..c04f7a06 100644 --- a/rogueviz/sag/sag.cpp +++ b/rogueviz/sag/sag.cpp @@ -41,7 +41,7 @@ void iterate() { if(t < (sag_ittime+1) / 2) ipturn *= 2; else if(t > sag_ittime * 2) ipturn /= 2; else ipturn = ipturn * sag_ittime / t; - print(hlog, format("it %12Ld temp %6.4f [2:%8.6f,10:%8.6f,50:%8.6f] cost = %f\n", + print(hlog, format("it %12lld temp %6.4f [2:%8.6f,10:%8.6f,50:%8.6f] cost = %f\n", numiter, double(sag::temperature), (double) exp(-2 * exp(-sag::temperature)), (double) exp(-10 * exp(-sag::temperature)),