Skip to content

Commit

Permalink
Fixed up minor possible errors caught by CppCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
krishauser committed Mar 30, 2019
1 parent a05f11b commit fc61be0
Show file tree
Hide file tree
Showing 79 changed files with 398 additions and 323 deletions.
40 changes: 20 additions & 20 deletions File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ bool File::OpenTCPSocket(SOCKET sockfd)
{
Close();
if(sockfd == 0) {
LOG4CXX_ERROR(KrisLibrary::logger(),"File::Open: socket file descriptor 0 is incompatible\n");
LOG4CXX_ERROR(KrisLibrary::logger(),"File::Open: socket file descriptor 0 is incompatible");
return false;
}

Expand All @@ -283,7 +283,7 @@ bool File::OpenUDPSocket(SOCKET sockfd)
{
Close();
if(sockfd == 0) {
LOG4CXX_ERROR(KrisLibrary::logger(),"File::Open: socket file descriptor 0 is incompatible\n");
LOG4CXX_ERROR(KrisLibrary::logger(),"File::Open: socket file descriptor 0 is incompatible");
return false;
}

Expand Down Expand Up @@ -311,13 +311,13 @@ bool File::Open(const char* fn, int openmode)
listen(sockfd,1);
SOCKET clientsocket = Accept(sockfd);
if(clientsocket == INVALID_SOCKET) {
LOG4CXX_ERROR(KrisLibrary::logger(),"File::Open: Accept connection to client on "<<fn);
LOG4CXX_ERROR(KrisLibrary::logger(),"File::Open: Accept connection to client on "<<fn);
perror("");
SocketClose(sockfd);
return false;
}
if(clientsocket == 0) {
LOG4CXX_ERROR(KrisLibrary::logger(),"File::Open: Accept connection returned a 0 file descriptor, this is incompatible\n");
LOG4CXX_ERROR(KrisLibrary::logger(),"File::Open: Accept connection returned a 0 file descriptor, this is incompatible");
SocketClose(clientsocket);
SocketClose(sockfd);
return false;
Expand All @@ -333,12 +333,12 @@ bool File::Open(const char* fn, int openmode)
else {
SOCKET sockfd = Connect(fn);
if (sockfd == INVALID_SOCKET) {
LOG4CXX_ERROR(KrisLibrary::logger(),"File::Open: Connect client to "<<fn);
LOG4CXX_ERROR(KrisLibrary::logger(),"File::Open: Connect client to "<<fn);
perror("");
return false;
}
if(sockfd == 0) {
LOG4CXX_ERROR(KrisLibrary::logger(),"File::Open: socket connect returned a 0 file descriptor, this is incompatible\n");
LOG4CXX_ERROR(KrisLibrary::logger(),"File::Open: socket connect returned a 0 file descriptor, this is incompatible");
SocketClose(sockfd);
return false;
}
Expand Down Expand Up @@ -470,7 +470,7 @@ bool File::ReadData(void* d, int size)
while(totalread < size) {
int n=SocketRead(impl->socket,buffer+totalread,size-totalread);
if(n == 0) {
LOG4CXX_INFO(KrisLibrary::logger(),"File(socket): socketRead returned 0, connection shutdown\n");
LOG4CXX_INFO(KrisLibrary::logger(),"File(socket): socketRead returned 0, connection shutdown");
return false;
}
if(n < 0) {
Expand Down Expand Up @@ -527,7 +527,7 @@ bool File::WriteData(const void* d, int size)
return false;
}
if(n == 0) {
LOG4CXX_INFO(KrisLibrary::logger(),"File(socket): SocketWrite returned "<<n<<", what does it mean?\n");
LOG4CXX_INFO(KrisLibrary::logger(),"File(socket): SocketWrite returned "<<n<<", what does it mean?");
ThreadSleep(0.001);
}
totalsent += n;
Expand All @@ -553,57 +553,57 @@ bool File::ReadString(char* str, int bufsize)
{
if(mode & FILEREAD)
{
int i,c;
int i;
switch(srctype)
{
case MODE_MYFILE:
case MODE_EXTFILE:
for(i=0; i<bufsize; i++)
{
c = ReadChar(impl->file);
int c = ReadChar(impl->file);
if(c==EOF) {
if(i != 0) LOG4CXX_ERROR(KrisLibrary::logger(),"File::ReadString hit end of file without finding null character\n");
if(i != 0) LOG4CXX_ERROR(KrisLibrary::logger(),"File::ReadString hit end of file without finding null character");
return false;
}
str[i]=c;
if(c==0)
return true;
}
LOG4CXX_ERROR(KrisLibrary::logger(),"File::ReadString string length is greater than buffer size "<<bufsize);
LOG4CXX_ERROR(KrisLibrary::logger(),"File::ReadString string length is greater than buffer size "<<bufsize);
break;
case MODE_MYDATA:
case MODE_EXTDATA:
for(i=0; i<bufsize; i++)
{
if(impl->datapos >= impl->datasize) {
LOG4CXX_ERROR(KrisLibrary::logger(),"File::ReadString ran past end of internal buffer without finding null character\n");
LOG4CXX_ERROR(KrisLibrary::logger(),"File::ReadString ran past end of internal buffer without finding null character");
return false;
}
str[i]=impl->datafile[impl->datapos];
impl->datapos++;
if(str[i]==0)
return true;
}
LOG4CXX_ERROR(KrisLibrary::logger(),"File::ReadString string length is greater than buffer size "<<bufsize);
LOG4CXX_ERROR(KrisLibrary::logger(),"File::ReadString string length is greater than buffer size "<<bufsize);
break;
case MODE_TCPSOCKET:
case MODE_UDPSOCKET:
{
int slen;
if(!ReadData(&slen,4)) {
LOG4CXX_ERROR(KrisLibrary::logger(),"File::ReadString read length failed\n");
LOG4CXX_ERROR(KrisLibrary::logger(),"File::ReadString read length failed");
return false;
}
if(slen < 0) {
LOG4CXX_ERROR(KrisLibrary::logger(),"File::ReadString read length "<<slen);
LOG4CXX_ERROR(KrisLibrary::logger(),"File::ReadString read length "<<slen);
return false;
}
if(slen+1 > bufsize) {
LOG4CXX_ERROR(KrisLibrary::logger(),"File::ReadString read length "<<slen<<" is greater than buffer size "<<bufsize);
LOG4CXX_ERROR(KrisLibrary::logger(),"File::ReadString read length "<<slen<<" is greater than buffer size "<<bufsize);
return false;
}
if(!ReadData(str,slen)) {
LOG4CXX_ERROR(KrisLibrary::logger(),"File::ReadString read string failed\n");
LOG4CXX_ERROR(KrisLibrary::logger(),"File::ReadString read string failed");
return false;
}
str[slen] = 0;
Expand All @@ -615,7 +615,7 @@ bool File::ReadString(char* str, int bufsize)
}
}
else
LOG4CXX_ERROR(KrisLibrary::logger(),"File::ReadString: file not in FILEREAD mode\n");
LOG4CXX_ERROR(KrisLibrary::logger(),"File::ReadString: file not in FILEREAD mode");
return false;
}

Expand All @@ -625,7 +625,7 @@ bool File::WriteString(const char* str)
case MODE_TCPSOCKET:
case MODE_UDPSOCKET:
if(strlen(str) > 0xffffffff) {
LOG4CXX_ERROR(KrisLibrary::logger(),"File::WriteString: string must be no longer than 2^32\n");
LOG4CXX_ERROR(KrisLibrary::logger(),"File::WriteString: string must be no longer than 2^32");
return false;
}
else {
Expand Down
5 changes: 4 additions & 1 deletion File.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ class File
public:
File();
~File();
///Opens a named file on the hard drive with the given open mode
///Non-copyable
File(const File&) = delete;
const File& operator = (const File&) = delete;
///Opens a named file on the hard drive with the given open mode
bool Open(const char*, int openmode = FILEREAD | FILEWRITE);
///Connects this File object to a previously opened FILE object
bool Open(void*, int openmode = FILEREAD | FILEWRITE);
Expand Down
2 changes: 1 addition & 1 deletion GLdraw/GLDisplayList.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace GLDraw {

struct GLDisplayList
{
GLDisplayList(int count=1);
explicit GLDisplayList(int count=1);
~GLDisplayList();
operator bool() const { return isCompiled(); }
bool isCompiled() const;
Expand Down
4 changes: 2 additions & 2 deletions GLdraw/GLView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ void GLView::getCurrentGL()
glGetFloatv(GL_MODELVIEW_MATRIX,mv);
#endif //MATH_DOUBLE
x=(Real)vp[0]; y=(Real)vp[1]; w=(Real)vp[2]; h=(Real)vp[3];
projection=pr;
modelview=mv;
projection.set(pr);
modelview.set(mv);
updateInverses();
}

Expand Down
8 changes: 4 additions & 4 deletions GLdraw/TransformWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using namespace GLDraw;
using namespace std;

Widget::Widget()
:hasHighlight(false),hasFocus(false)
:hasHighlight(false),hasFocus(false), requestRedraw(true)
{}

WidgetSet::WidgetSet()
Expand Down Expand Up @@ -388,7 +388,7 @@ void TransformWidget::DrawGL(Camera::Viewport& viewport)
if(enableTranslation) {
Vector3 axis;
if(enableTranslationAxes[0]) {
axis = T.R.col1();
axis.set(T.R.col1());
scale = (hasHighlight && hoverItem == 1 ? hoverScale : 1.0)*globalScale;
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,xAxisColor.rgba);
drawCylinder(axis*axisLength*globalScale,axisRadius*scale,8);
Expand All @@ -399,7 +399,7 @@ void TransformWidget::DrawGL(Camera::Viewport& viewport)
}

if(enableTranslationAxes[1]) {
axis = T.R.col2();
axis.set(T.R.col2());
scale = (hasHighlight && hoverItem == 2 ? hoverScale : 1.0)*globalScale;
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,yAxisColor.rgba);
drawCylinder(axis*axisLength*globalScale,axisRadius*scale,8);
Expand All @@ -410,7 +410,7 @@ void TransformWidget::DrawGL(Camera::Viewport& viewport)
}

if(enableTranslationAxes[2]) {
axis = T.R.col3();
axis.set(T.R.col3());
scale = (hasHighlight && hoverItem == 3 ? hoverScale : 1.0)*globalScale;
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,zAxisColor.rgba);
drawCylinder(axis*axisLength*globalScale,axisRadius*scale,8);
Expand Down
12 changes: 12 additions & 0 deletions Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ Timer::Timer()
Reset();
}

Timer::Timer(const Timer& rhs)
:impl(new TimerImpl)
{
*this = rhs;
}

const Timer& Timer::operator =(const Timer& rhs)
{
*impl = *rhs.impl;
return *this;
}

Timer::~Timer()
{
delete impl;
Expand Down
2 changes: 2 additions & 0 deletions Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class Timer
{
public:
Timer();
Timer(const Timer& rhs);
~Timer();
const Timer& operator = (const Timer&);
void Reset();

// Returns elapsed time in milliseconds,seconds respectively
Expand Down
2 changes: 2 additions & 0 deletions errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ inline void RaiseErrorFmt(const char* func, const char* file, int line, const ch
va_start(args, fmt);
char buf[1024];
vsnprintf(buf, 1024, fmt, args);
va_end(args);
LOG4CXX_FATAL(KrisLibrary::logger(),buf);
Abort();
}
Expand All @@ -57,6 +58,7 @@ inline void RaiseErrorFmt(const char* fmt,...)
va_start(args, fmt);
char buf[1024];
vsnprintf(buf, 1024, fmt, args);
va_end(args);
LOG4CXX_FATAL(KrisLibrary::logger(),buf);
Abort();
}
Expand Down
6 changes: 3 additions & 3 deletions geometry/AnyGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ int PointIndex(const CollisionImplicitSurface& s,const Vector3& ptworld)
}

AnyDistanceQueryResult::AnyDistanceQueryResult()
:hasPenetration(0),hasElements(0),hasClosestPoints(0),hasDirections(0),d(Inf)
:hasPenetration(0),hasElements(0),hasClosestPoints(0),hasDirections(0),d(Inf),elem1(-1),elem2(-1)
{}

AnyDistanceQuerySettings::AnyDistanceQuerySettings()
Expand Down Expand Up @@ -496,7 +496,7 @@ bool AnyGeometry3D::Load(const char* fn)
else if(0==strcmp(ext,"geom")) {
ifstream in(fn,ios::in);
if(!in) {
LOG4CXX_ERROR(KrisLibrary::logger(),"AnyGeometry3D::Load: File "<<fn);
LOG4CXX_ERROR(KrisLibrary::logger(),"AnyGeometry3D::Load: File "<<fn);
return false;
}
if(!Load(in)) return false;
Expand All @@ -506,7 +506,7 @@ bool AnyGeometry3D::Load(const char* fn)
else {
ifstream in(fn,ios::in);
if(!in) {
LOG4CXX_ERROR(KrisLibrary::logger(),"AnyGeometry3D::Load: File "<<fn);
LOG4CXX_ERROR(KrisLibrary::logger(),"AnyGeometry3D::Load: File "<<fn);
return false;
}
if(!Load(in)) return false;
Expand Down
4 changes: 2 additions & 2 deletions geometry/Arrangement1D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void Arrangement1D::GetIntervals(vector<Interval>& segs,vector<const IDList*>& i
ids.reserve(n);
segs.resize(0);
ids.resize(0);
for(SortedIntervals::const_iterator i=intervals.begin();i!=intervals.end();i++) {
for(SortedIntervals::const_iterator i=intervals.begin();i!=intervals.end();++i) {
if(i->second.pointIDs.size() != i->second.intervalIDs.size()) {
if(i!=intervals.begin()) {
SortedIntervals::const_iterator p=i; --p;
Expand All @@ -145,7 +145,7 @@ void Arrangement1D::GetAllIntervals(vector<Interval>& segs,vector<const IDList*>
ids.reserve(n);
segs.resize(0);
ids.resize(0);
for(SortedIntervals::const_iterator i=intervals.begin();i!=intervals.end();i++) {
for(SortedIntervals::const_iterator i=intervals.begin();i!=intervals.end();++i) {
if(i->second.pointIDs.size() != i->second.intervalIDs.size()) {
if(i!=intervals.begin()) {
SortedIntervals::const_iterator p=i; --p;
Expand Down
1 change: 1 addition & 0 deletions geometry/BallTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <KrisLibrary/math/AABB.h>
#include <iostream>
#include <climits>
#include <algorithm>
using namespace Geometry;
using namespace std;

Expand Down
2 changes: 1 addition & 1 deletion geometry/CollisionImplicitSurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CollisionImplicitSurface
{
public:
CollisionImplicitSurface();
CollisionImplicitSurface(const Meshing::VolumeGrid& vg);
explicit CollisionImplicitSurface(const Meshing::VolumeGrid& vg);
CollisionImplicitSurface(const CollisionImplicitSurface& vg);
///Sets up the collision detection data structures. This is automatically
///called during initialization, and needs to be called any time the implicit
Expand Down
Loading

0 comments on commit fc61be0

Please sign in to comment.