From 5b8a15a92bdd8400a550bdfb8bb7ae6675ff731e Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 2 May 2020 11:49:28 -0700 Subject: [PATCH] Eliminate some compile warnings in vda/. Added virtual destructors. Fixed some sprintf warnings but not all; that seems like an infinite rat-hole. --- vda/des.h | 1 + vda/vda_lib.cpp | 4 ++-- vda/vda_lib.h | 3 ++- vda/vda_lib2.cpp | 18 +++++++++--------- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/vda/des.h b/vda/des.h index 777d4133a2..e3825ab8b2 100644 --- a/vda/des.h +++ b/vda/des.h @@ -33,6 +33,7 @@ using std::vector; struct EVENT { double t; virtual void handle(){} + virtual ~EVENT(){} }; inline bool compare(EVENT* e1, EVENT* e2) { diff --git a/vda/vda_lib.cpp b/vda/vda_lib.cpp index 122007f294..0e843c9b2c 100644 --- a/vda/vda_lib.cpp +++ b/vda/vda_lib.cpp @@ -77,7 +77,7 @@ META_CHUNK::META_CHUNK( parent = par; coding = d->policy.codings[coding_level]; if (parent) { - sprintf(name, "%s.%d", parent->name, index); + sprintf(name, "%.64s.%d", parent->name, index); } else { sprintf(name, "%d", index); } @@ -501,7 +501,7 @@ bool CHUNK::download_in_progress() { int CHUNK::recovery_action(double now) { int retval; - char buf[256]; + char buf[1024]; VDA_FILE_AUX* fp = parent->dfile; if (data_now_present) { diff --git a/vda/vda_lib.h b/vda/vda_lib.h index 7a127c9334..0da5e5485f 100644 --- a/vda/vda_lib.h +++ b/vda/vda_lib.h @@ -112,7 +112,7 @@ struct DATA_UNIT { virtual int compute_min_failures(){return 0;}; virtual int upload_all(){return 0;}; - char name[64]; + char name[256]; char dir[1024]; // the following are determined during recovery_plan() @@ -193,6 +193,7 @@ struct CHUNK : DATA_UNIT { bool present_on_server; CHUNK(META_CHUNK* mc, double s, int index); + virtual ~CHUNK(){} int start_upload(); void host_failed(VDA_CHUNK_HOST* p); diff --git a/vda/vda_lib2.cpp b/vda/vda_lib2.cpp index 46209da3c8..abd566ca8e 100644 --- a/vda/vda_lib2.cpp +++ b/vda/vda_lib2.cpp @@ -92,7 +92,7 @@ int get_chunk_numbers(VDA_CHUNK_HOST& vch, vector& chunk_numbers) { ///////////////// DATA_UNIT /////////////////////// int DATA_UNIT::delete_file() { - char path[1024], buf[1024]; + char path[2048], buf[1024]; sprintf(path, "%s/data.vda", dir); ssize_t n = readlink(path, buf, sizeof(buf)-1); if (n < 0) { @@ -115,7 +115,7 @@ META_CHUNK::META_CHUNK(VDA_FILE_AUX* d, META_CHUNK* p, int index) { parent = p; if (parent) { if (strlen(parent->name)) { - sprintf(name, "%s.%d", parent->name, index); + sprintf(name, "%.64s.%d", parent->name, index); } else { sprintf(name, "%d", index); } @@ -129,7 +129,7 @@ META_CHUNK::META_CHUNK(VDA_FILE_AUX* d, META_CHUNK* p, int index) { // int META_CHUNK::init(const char* _dir, POLICY& p, int coding_level) { double size; - char child_dir[1024]; + char child_dir[2048]; safe_strcpy(dir, _dir); coding = p.codings[coding_level]; @@ -153,7 +153,7 @@ int META_CHUNK::init(const char* _dir, POLICY& p, int coding_level) { // write the chunk's MD5 to a file // - char file_path[1024], md5_file_path[1024]; + char file_path[2048], md5_file_path[2048]; sprintf(file_path, "%s/%d/%s", dir, i, DATA_FILENAME); sprintf(md5_file_path, "%s/%d/md5.txt", dir, i); char md5[64]; @@ -174,7 +174,7 @@ int META_CHUNK::get_state(const char* _dir, POLICY& p, int coding_level) { coding = p.codings[coding_level]; if (coding_level < p.coding_levels - 1) { for (int i=0; iget_state(child_dir, p, coding_level+1); @@ -365,12 +365,12 @@ CHUNK::CHUNK(META_CHUNK* mc, double s, int index) { parent = mc; size = s; if (strlen(parent->name)) { - sprintf(name, "%s.%d", parent->name, index); + sprintf(name, "%.64s.%d", parent->name, index); } else { sprintf(name, "%d", index); } - sprintf(dir, "%s/%d", mc->dir, index); - char path[256]; + sprintf(dir, "%.256s/%d", mc->dir, index); + char path[2048]; double fsize; sprintf(path, "%s/data.vda", dir); int retval = file_size(path, fsize); @@ -512,7 +512,7 @@ int VDA_FILE_AUX::init() { // and put them in the appropriate lists // int VDA_FILE_AUX::get_state() { - char buf[256]; + char buf[2048]; sprintf(buf, "%s/chunk_sizes.txt", dir); FILE* f = fopen(buf, "r");