Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init variables, check for valid file pointers before using, provide valid return values #1424

Open
wants to merge 19 commits into
base: production
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions plugins/configurationcache/configurationcachetree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,9 @@ int CacheTree::SaveCache(std::string filename)

FILE* pfile;
pfile = fopen(_fulldirname.c_str(),"wb");
if( pfile == NULL) {
return 0;
lazydroid marked this conversation as resolved.
Show resolved Hide resolved
}

fwrite(&_statedof, sizeof(_statedof), 1, pfile);
fwrite(&_weights[0], sizeof(_weights[0])*_weights.size(), 1, pfile);
Expand Down
3 changes: 3 additions & 0 deletions plugins/configurationcache/configurationcachetree.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ class CacheTree
int GetNumKnownNodes();

/// \brief save cache to disk
///
/// \param[in] filename the file name where to save the cache
/// \return 1 if everything went fine and 0 if there was a trouble opening the file
int SaveCache(std::string filename);

/// \brief load cache from disk
Expand Down
16 changes: 10 additions & 6 deletions plugins/rplanners/ParabolicPathSmooth/ParabolicRamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1796,12 +1796,16 @@ bool ParabolicRampND::SolveMinTime(const Vector& amax,const Vector& vmax)
SaveRamp("ParabolicRampND_SolveMinAccel_failure.dat",ramps[i].x0,ramps[i].dx0,ramps[i].x1,ramps[i].dx1,-1,vmax[i],endTime);
PARABOLIC_RAMP_PLOG("Saving to failed_ramps.txt\n");
FILE* f=fopen("failed_ramps.txt","w+");
fprintf(f,"MinAccel T=%.15e, vmax=%.15e\n",endTime,vmax[i]);
fprintf(f,"x0=%.15e, dx0=%.15e\n",ramps[i].x0,ramps[i].dx0);
fprintf(f,"x1=%.15e, dx1=%.15e\n",ramps[i].x1,ramps[i].dx1);
fprintf(f,"MinTime solution v=%.15e, t1=%.15e, t2=%.15e, T=%.15e\n",ramps[i].v,ramps[i].tswitch1,ramps[i].tswitch2,ramps[i].ttotal);
fprintf(f,"\n");
fclose(f);
if( f != NULL ) {
fprintf(f,"MinAccel T=%.15e, vmax=%.15e\n",endTime,vmax[i]);
fprintf(f,"x0=%.15e, dx0=%.15e\n",ramps[i].x0,ramps[i].dx0);
fprintf(f,"x1=%.15e, dx1=%.15e\n",ramps[i].x1,ramps[i].dx1);
fprintf(f,"MinTime solution v=%.15e, t1=%.15e, t2=%.15e, T=%.15e\n",ramps[i].v,ramps[i].tswitch1,ramps[i].tswitch2,ramps[i].ttotal);
fprintf(f,"\n");
fclose(f);
} else {
PARABOLIC_RAMP_PLOG("Failed to open failed_ramps.txt\n");
}
return false;
}
if(Abs(ramps[i].a1) > EpsilonA+amax[i] || Abs(ramps[i].a2) > EpsilonA+amax[i] || Abs(ramps[i].v) > EpsilonV+vmax[i]) {
Expand Down
12 changes: 6 additions & 6 deletions plugins/rplanners/ParabolicPathSmooth/ppramp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ bool PPRamp::SolveMinTime2(Real amax,Real timeLowerBound)
}
_a2 = -_a1;
PARABOLIC_RAMP_ASSERT(ttotal >= timeLowerBound);
Real ts1,ts2;
Real ts1 = -1.0, ts2 = -1.0;
int res = CalcSwitchTimes(_a1,ts1,ts2);
PARABOLIC_RAMP_ASSERT(res > 0);
if(res == 1) {
Expand Down Expand Up @@ -195,7 +195,7 @@ bool PPRamp::SolveFixedTime(Real amax,Real endTime)
Real c2 = 0.25 * endTime * endTime;
Real c1 = x0 - x1 + 0.5*endTime*(dx0+dx1);
Real c0 = -0.25*(dx0-dx1)*(dx0-dx1);
Real aroots[2];
Real aroots[2] = { 0.0, 0.0 };
int numroots = SolveQuadratic(c2, c1, c0, aroots[0], aroots[1]);
if( numroots ==2 && Abs(aroots[0]) > Abs(aroots[1]) ) {
swap(aroots[0],aroots[1]);
Expand Down Expand Up @@ -352,7 +352,7 @@ Real PPRamp::CalcTotalTime(Real a) const

int PPRamp::CalcTotalTimes(Real a,Real& t1,Real& t2) const
{
Real ts1,ts2;
Real ts1 = -1.0, ts2 = -1.0;
int res=CalcSwitchTimes(a,ts1,ts2);
if(res == 0) return res;
else if(res == 1) {
Expand Down Expand Up @@ -429,7 +429,7 @@ int PPRamp::CalcSwitchTimes(Real a,Real& t1,Real& t2) const

Real PPRamp::CalcSwitchTime(Real a) const
{
Real t1 = 0.0, t2 = 0.0;
Real t1 = -1.0, t2 = -1.0;
int res = CalcSwitchTimes(a,t1,t2);
if(res == 0) {
return -1;
Expand Down Expand Up @@ -478,7 +478,7 @@ Real PPRamp::CalcMinAccel(Real endTime,Real sign,Real& switchTime) const
Real a = -(dx1 - dx0)/endTime;
Real b = (2.0*(dx0+dx1)+4.0*(x0-x1)/endTime);
Real c = (dx1 - dx0)*endTime;
Real rat1,rat2;
Real rat1 = 0.0, rat2 = 0.0;
int res=SolveQuadratic(a,b,c,rat1,rat2);
Real accel1 = (dx1-dx0)/rat1;
Real accel2 = (dx1-dx0)/rat2;
Expand Down Expand Up @@ -607,7 +607,7 @@ Real PPRamp::CalcMinAccel(Real endTime,Real sign,Real& switchTime) const
b = b/Abs(dx1-dx0);
c = -Abs(dx1-dx0)/endTime;
}
Real accel1,accel2;
Real accel1 = 0.0, accel2 = 0.0;
int res=SolveQuadratic(a,b,c,accel1,accel2);
//remove negative accelerations
if(res >= 1 && accel1 < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ PolynomialCheckReturn PolynomialChecker::CheckChunk(const Chunk& c, const std::v
bool bHasVelocityLimits = vmVect.size() == ndof;
bool bHasAccelerationLimits = amVect.size() == ndof;
bool bHasJerkLimits = jmVect.size() == ndof;
PolynomialCheckReturn ret;
PolynomialCheckReturn ret = PCR_Normal;
for( size_t idof = 0; idof < ndof; ++idof ) {
if( bHasVelocityLimits ) {
vm = vmVect[idof];
Expand Down
2 changes: 1 addition & 1 deletion src/libopenrave-core/colladaparser/colladareader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ class ColladaReader : public daeErrorHandler
if (find(_vOpenRAVESchemeAliases.begin(), _vOpenRAVESchemeAliases.end(), urioriginal.scheme()) !=
_vOpenRAVESchemeAliases.end()) {
if (urioriginal.path().empty()) {
return nullptr;
return std::string();
cielavenir marked this conversation as resolved.
Show resolved Hide resolved
}
// remove first slash because we need relative file
uriresolved = "file:";
Expand Down
2 changes: 1 addition & 1 deletion src/libopenrave/planningutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4198,7 +4198,7 @@ int DynamicsCollisionConstraint::Check(const std::vector<dReal>& q0, const std::
BOOST_ASSERT(0);
} // end switch maskinterpolation
bool bFoundTimeInstant = false;
dReal root;
lazydroid marked this conversation as resolved.
Show resolved Hide resolved
dReal root = 1234567890;
lazydroid marked this conversation as resolved.
Show resolved Hide resolved
if( numroots > 0 ) {
std::sort(_vrawroots.begin(), _vrawroots.begin() + numroots);
for( int iroot = 0; iroot < numroots; ++iroot ) {
Expand Down
Loading