From: Andreas Hansson Date: Wed, 1 Oct 2014 12:05:54 +0000 (-0400) Subject: misc: Fix issues identified by static analysis X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6498ccddb2f13a6fac6a210372b1aa86873507b9;p=gem5.git misc: Fix issues identified by static analysis Another bunch of issues addressed. --- diff --git a/src/base/loader/object_file.cc b/src/base/loader/object_file.cc index 170e18d5e..29cea8ccf 100644 --- a/src/base/loader/object_file.cc +++ b/src/base/loader/object_file.cc @@ -54,7 +54,8 @@ ObjectFile::ObjectFile(const string &_filename, int _fd, size_t _len, uint8_t *_data, Arch _arch, OpSys _opSys) : filename(_filename), descriptor(_fd), fileData(_data), len(_len), - arch(_arch), opSys(_opSys), globalPtr(0) + arch(_arch), opSys(_opSys), entry(0), globalPtr(0), + text{0, nullptr, 0}, data{0, nullptr, 0}, bss{0, nullptr, 0} { } @@ -116,7 +117,9 @@ createObjectFile(const string &fname, bool raw) } // find the length of the file by seeking to the end - size_t len = (size_t)lseek(fd, 0, SEEK_END); + off_t off = lseek(fd, 0, SEEK_END); + fatal_if(off < 0, "Failed to determine size of object file %s\n", fname); + size_t len = static_cast(off); // mmap the whole shebang uint8_t *fileData = diff --git a/src/base/statistics.hh b/src/base/statistics.hh index 1b3d0fc54..a6edde2f9 100644 --- a/src/base/statistics.hh +++ b/src/base/statistics.hh @@ -1361,7 +1361,8 @@ class DistStor /** The number of buckets. Equal to (max-min)/bucket_size. */ size_type buckets; - Params() : DistParams(Dist) {} + Params() : DistParams(Dist), min(0), max(0), bucket_size(0), + buckets(0) {} }; private: diff --git a/src/base/vnc/vncserver.cc b/src/base/vnc/vncserver.cc index e762ad1d4..77a4316ab 100644 --- a/src/base/vnc/vncserver.cc +++ b/src/base/vnc/vncserver.cc @@ -184,6 +184,8 @@ VncServer::accept() panic("%s: cannot accept a connection if not listening!", name()); int fd = listener.accept(true); + fatal_if(fd < 0, "%s: failed to accept VNC connection!", name()); + if (dataFd != -1) { char message[] = "vnc server already attached!\n"; atomic_write(fd, message, sizeof(message)); @@ -643,7 +645,8 @@ VncServer::sendFrameBufferUpdate() assert(fbPtr); uint8_t *tmp = vc->convert(fbPtr); - write(tmp, videoWidth() * videoHeight() * sizeof(uint32_t)); + uint64_t num_pixels = videoWidth() * videoHeight(); + write(tmp, num_pixels * sizeof(uint32_t)); delete [] tmp; } diff --git a/src/mem/ruby/system/System.cc b/src/mem/ruby/system/System.cc index dad5b8aa6..0675366d1 100644 --- a/src/mem/ruby/system/System.cc +++ b/src/mem/ruby/system/System.cc @@ -153,7 +153,7 @@ RubySystem::writeCompressedTrace(uint8_t *raw_data, string filename, if (gzclose(compressedMemory)) { fatal("Close failed on memory trace file '%s'\n", filename); } - delete raw_data; + delete[] raw_data; } void diff --git a/src/sim/sim_object.cc b/src/sim/sim_object.cc index 44d498c3c..a7be4ebd2 100644 --- a/src/sim/sim_object.cc +++ b/src/sim/sim_object.cc @@ -70,6 +70,11 @@ SimObject::SimObject(const Params *p) probeManager = new ProbeManager(this); } +SimObject::~SimObject() +{ + delete probeManager; +} + void SimObject::init() { diff --git a/src/sim/sim_object.hh b/src/sim/sim_object.hh index e4526e773..9bf95d07f 100644 --- a/src/sim/sim_object.hh +++ b/src/sim/sim_object.hh @@ -101,7 +101,7 @@ class SimObject : public EventManager, public Serializable, public Drainable typedef SimObjectParams Params; const Params *params() const { return _params; } SimObject(const Params *_params); - virtual ~SimObject() {} + virtual ~SimObject(); public: