Commit 9314af23 authored by Samuel Debionne's avatar Samuel Debionne
Browse files

Fixes some artihmetic overflows, uninitialized variables and throws where code should be noexcept

parent 173e0870
Pipeline #34918 passed with stages
in 32 minutes and 28 seconds
......@@ -41,6 +41,8 @@ void LIMACORE_API ClearBuffer(void *ptr, int nb_concat_frames, const FrameDim& f
struct LIMACORE_API Allocator
{
DEB_STRUCT_NAMESPC(DebModCommon, "MemUtils", "Allocator");
struct Data {
virtual ~Data() = default;
};
......@@ -54,9 +56,10 @@ struct LIMACORE_API Allocator
Allocator(Allocator&& o) : m_ref_count(0)
{
DEB_MEMBER_FUNCT();
if (o.m_ref_count != 0)
throw LIMA_COM_EXC(InvalidValue,
"Moved-from Allocator is not empty");
DEB_ERROR() << "Moved-from Allocator is not empty";
}
// Allocate a buffer of a given size and eventually return
......@@ -102,9 +105,10 @@ struct LIMACORE_API Allocator
virtual ~Allocator()
{
DEB_MEMBER_FUNCT();
if (m_ref_count != 0)
std::cerr << "Error: destroying non-empty Allocator"
<< std::endl;
DEB_ERROR() << "Error: destroying non-empty Allocator";
}
// The real resource management counter, triggered by Ref
......
......@@ -5,6 +5,7 @@
#include <iostream>
#include "lima/Constants.h"
#include "lima/Exceptions.h"
#include "processlib/Data.h"
......@@ -35,7 +36,14 @@ namespace lima
inline void alloc(int size)
{
if(!buffer || double(size) > this->size())
buffer = (char*)realloc(buffer,size);
{
char* tmp = (char*)realloc(buffer,size);
if (tmp == NULL)
throw LIMA_COM_EXC(Error, "Error in realloc: ")
<< "NULL pointer returned";
else
buffer = tmp;
}
}
inline void setParams(int fNumber,int w,int h,VideoMode m)
{
......
......@@ -103,7 +103,7 @@ int lima::GetDefMaxNbBuffers(const FrameDim& frame_dim)
void lima::ClearBuffer(void *ptr, int nb_concat_frames,
const FrameDim& frame_dim)
{
memset(ptr, 0, nb_concat_frames * frame_dim.getMemSize());
memset(ptr, 0, nb_concat_frames * size_t(frame_dim.getMemSize()));
}
Allocator *Allocator::defaultAllocator()
......
......@@ -184,7 +184,7 @@ bool Cond::wait(double timeout)
struct timeval now;
struct timespec waitTimeout;
gettimeofday(&now,NULL);
waitTimeout.tv_sec = now.tv_sec + long(timeout);
waitTimeout.tv_sec = now.tv_sec + time_t(timeout);
waitTimeout.tv_nsec = (now.tv_usec * 1000) +
long((timeout - long(timeout)) * 1e9);
if(waitTimeout.tv_nsec >= 1000000000L) // Carry
......@@ -241,10 +241,8 @@ Thread::ExceptionCleanUp::~ExceptionCleanUp()
m_thread.m_exception_handled = true;
}
Thread::Thread()
Thread::Thread() : m_thread(NULL), m_started(false), m_finished(false), m_exception_handled(false), m_tid(0)
{
m_started = m_finished = m_exception_handled = false;
m_tid = 0;
pthread_attr_init(&m_thread_attr);
}
......
......@@ -70,7 +70,7 @@ namespace lima
"Control");
friend class CtAccumulation;
public:
ThresholdCallback() {};
ThresholdCallback() : m_max(0) {};
virtual ~ThresholdCallback() {};
int m_max;
......
......@@ -103,7 +103,7 @@ namespace lima
private:
typedef std::map<std::string,ModuleTypeCallback*> ModuleMap;
CtConfig(const CtConfig &other): m_ctrl(other.m_ctrl) {}
CtConfig(const CtConfig &other): m_ctrl(other.m_ctrl), m_config(NULL) {}
CtControl& m_ctrl;
libconfig::Config* m_config;
......
......@@ -267,10 +267,10 @@ public:
typedef std::map<long, FrameParameters> Frame2Params;
struct Handler
{
Handler() : m_handler(NULL) {}
Handler() : m_handler(NULL), m_nb_frames(0) {}
void* m_handler;
int m_nb_frames;
int m_nb_frames;
};
struct cmpParameters
{
......
......@@ -92,7 +92,7 @@ static const LZ4F_preferences_t lz4_preferences = {
int framesPerFile,const CtSaving::HeaderMap &header);
~FileLz4Compression();
virtual void process(Data &aData);
void _compression(const char *src,int size,ZBufferList& return_buffers);
void _compression(const char *src,size_t size,ZBufferList& return_buffers);
};
#endif // WITH_LZ4_COMPRESSION
......
......@@ -864,7 +864,7 @@ void SoftOpPeakFinder::setComputingMode(ComputingMode aComputingMode)
void SoftOpPeakFinder::getComputingMode(ComputingMode &aComputingMode) const
{
Tasks::PeakFinderTask::ComputingMode aMode;
Tasks::PeakFinderTask::ComputingMode aMode = Tasks::PeakFinderTask::MAXIMUM;
for(NameMapConstIterator i = m_task_manager.begin(); i != m_task_manager.end();++i) {
i->second.second->getComputingMode(aMode);
}
......
......@@ -172,6 +172,8 @@ protected:
private:
struct ChangeEvent {
ChangeEvent() : force(false), finished(NULL) {}
ImageStatus status;
bool force;
bool *finished;
......
......@@ -158,24 +158,24 @@ void FileLz4Compression::process(Data &aData)
m_container._setBuffer(aData.frameNumber,std::move(aBufferListPt));
}
void FileLz4Compression::_compression(const char *src,int size,
void FileLz4Compression::_compression(const char *src, size_t size,
ZBufferList& return_buffers)
{
DEB_MEMBER_FUNCT();
int buffer_size = LZ4F_compressFrameBound(size,&lz4_preferences);
size_t buffer_size = LZ4F_compressFrameBound(size,&lz4_preferences);
buffer_size += LZ4_HEADER_SIZE + LZ4_FOOTER_SIZE;
return_buffers.emplace_back(buffer_size);
ZBuffer& newBuffer = return_buffers.back();
char* buffer = (char*)newBuffer.ptr();
int offset = LZ4F_compressBegin(m_ctx,buffer,
size_t offset = LZ4F_compressBegin(m_ctx,buffer,
buffer_size,&lz4_preferences);
if(LZ4F_isError(offset))
THROW_CTL_ERROR(Error) << "Failed to start compression: " << DEB_VAR1(offset);
int error_code = LZ4F_compressUpdate(m_ctx,buffer + offset,buffer_size - offset,
size_t error_code = LZ4F_compressUpdate(m_ctx,buffer + offset,buffer_size - offset,
src,size,NULL);
if(LZ4F_isError(error_code))
THROW_CTL_ERROR(Error) << "Compression Failed: "
......
......@@ -43,6 +43,7 @@ struct SaveContainerHdf5::_File
m_in_append(false),
m_dataset_extended(false),
m_entry_index(0),
m_nb_frames(0),
m_frame_cnt(0)
{}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment