Skip to content

Commit

Permalink
fix compiler warnings, and a bug was hiding in there also.
Browse files Browse the repository at this point in the history
  • Loading branch information
lovettchris committed Apr 17, 2017
1 parent 43baa4f commit d0d6eb3
Show file tree
Hide file tree
Showing 38 changed files with 227 additions and 24 deletions.
9 changes: 8 additions & 1 deletion AirLib/include/common/Common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,15 @@ static void logWarning(const char* format, ...)
va_list args;
va_start(args, format);

IGNORE_FORMAT_STRING_ON
auto size = _vscprintf(format, args) + 1U;
IGNORE_FORMAT_STRING_OFF
std::unique_ptr<char[]> buf(new char[size] );

#ifndef _MSC_VER
IGNORE_FORMAT_STRING_ON
vsnprintf(buf.get(), size, format, args);
IGNORE_FORMAT_STRING_OFF
#else
vsnprintf_s(buf.get(), size, _TRUNCATE, format, args);
#endif
Expand All @@ -94,12 +98,15 @@ static void logError(const char* format, ...)
{
va_list args;
va_start(args, format);

IGNORE_FORMAT_STRING_ON
auto size = _vscprintf(format, args) + 1U;
IGNORE_FORMAT_STRING_OFF
std::unique_ptr<char[]> buf(new char[size] );

#ifndef _MSC_VER
IGNORE_FORMAT_STRING_ON
vsnprintf(buf.get(), size, format, args);
IGNORE_FORMAT_STRING_OFF
#else
vsnprintf_s(buf.get(), size, _TRUNCATE, format, args);
#endif
Expand Down
1 change: 1 addition & 0 deletions AirLib/include/common/FrequencyLimiter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class FrequencyLimiter : UpdatableObject {
public:
FrequencyLimiter(real_T frequency = Utils::max<float>(), real_T startup_delay = 0)
{
startup_delay; // avoid warning: unused parameter
initialize(frequency);
}

Expand Down
2 changes: 2 additions & 0 deletions AirLib/include/common/StateReporter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class StateReporter {
//TODO: need better line end handling
void startHeading(string heading, uint heading_size, uint columns = 20)
{
heading_size; // avoid warning: unused parameter
columns; // avoid warning: unused parameter
ss_ << "\n";
ss_ << heading;
}
Expand Down
1 change: 1 addition & 0 deletions AirLib/include/common/UpdatableObject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class UpdatableObject {

virtual void reportState(StateReporter& reporter)
{
reporter; // avoid warning: unused parameter
//default implementation doesn't do anything
}

Expand Down
1 change: 1 addition & 0 deletions AirLib/include/common/VectorMath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class VectorMathT {

static Vector3T rotateVector(const Vector3T& v, const QuaternionT& q, bool assume_unit_quat)
{
assume_unit_quat; // stop warning: unused parameter.
//More performant method is at http://gamedev.stackexchange.com/a/50545/20758
//QuaternionT vq(0, v.x(), v.y(), v.z());
//QuaternionT qi = assume_unit_quat ? q.conjugate() : q.inverse();
Expand Down
6 changes: 5 additions & 1 deletion AirLib/include/common/common_utils/AsyncTasker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
class AsyncTasker {
public:
AsyncTasker(unsigned int thread_count = 4)
: threads_(thread_count), error_handler_([](std::exception e) {})
: threads_(thread_count), error_handler_([](std::exception e) {
e; // avoid warning: unused parameter
})
{
}

Expand All @@ -27,6 +29,7 @@ class AsyncTasker {
{
threads_.push([=](int i) {
try {
i; // avoid warning: unused parameter
func();
}
catch (std::exception& e) {
Expand All @@ -37,6 +40,7 @@ class AsyncTasker {
else {
threads_.push([=](int i) {
try {
i; // avoid warning: unused parameter
for (unsigned int itr = 0; itr < iterations; ++itr) {
func();
}
Expand Down
64 changes: 58 additions & 6 deletions AirLib/include/common/common_utils/StrictMode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,64 @@
#define STRICT_MODE_ON \
__pragma(warning(pop))

#define IGNORE_FORMAT_STRING_ON

#define IGNORE_FORMAT_STRING_OFF

//TODO: limit scope of below statements required to suppress VC++ warnings
#define _CRT_SECURE_NO_WARNINGS 1
#pragma warning(disable:4996)
#endif

// special way to quiet the warning: warning: format string is not a string literal
#ifdef __CLANG__
#define IGNORE_FORMAT_STRING_ON \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wformat-nonliteral\"")

#define IGNORE_FORMAT_STRING_OFF \
_Pragma("clang diagnostic pop")
#else
#ifdef __GNUC__
#define IGNORE_FORMAT_STRING_ON \
_Pragma("gcc diagnostic push") \
_Pragma("gcc diagnostic ignored \"-Wformat-nonliteral\"")

#define IGNORE_FORMAT_STRING_OFF \
_Pragma("gcc diagnostic pop")
#endif
#endif

// Please keep this list sorted so it is easier to find stuff, also make sure there
// is no whitespace after the traling \, GCC doesn't like that.
#ifdef __CLANG__
#define STRICT_MODE_OFF \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wctor-dtor-privacy\"") \
_Pragma("clang diagnostic ignored \"-Wdelete-non-virtual-dtor\"") \
_Pragma("clang diagnostic ignored \"-Wmissing-field-initializers\"") \
_Pragma("clang diagnostic ignored \"-Wold-style-cast\"") \
_Pragma("clang diagnostic ignored \"-Wredundant-decls\"") \
_Pragma("clang diagnostic ignored \"-Wreturn-type\"") \
_Pragma("clang diagnostic ignored \"-Wshadow\"") \
_Pragma("clang diagnostic ignored \"-Wstrict-overflow\"") \
_Pragma("clang diagnostic ignored \"-Wswitch-default\"") \
_Pragma("clang diagnostic ignored \"-Wundef\"") \
_Pragma("clang diagnostic ignored \"-Wunused-parameter\"")

/* Addition options that can be enabled
_Pragma("clang diagnostic ignored \"-Wpedantic\"") \
_Pragma("clang diagnostic ignored \"-Wformat=\"") \
_Pragma("clang diagnostic ignored \"-Werror\"") \
_Pragma("clang diagnostic ignored \"-Werror=\"") \
_Pragma("clang diagnostic ignored \"-Wunused-variable\"") \
*/

#define STRICT_MODE_ON \
_Pragma("clang diagnostic pop")


#else
#ifdef __GNUC__
#define STRICT_MODE_OFF \
_Pragma("GCC diagnostic push") \
Expand All @@ -32,17 +83,18 @@
_Pragma("GCC diagnostic ignored \"-Wundef\"") \
_Pragma("GCC diagnostic ignored \"-Wunused-parameter\"")

/* Addition options that can be enabled
_Pragma("GCC diagnostic ignored \"-Wpedantic\"") \
_Pragma("GCC diagnostic ignored \"-Wformat=\"") \
_Pragma("GCC diagnostic ignored \"-Werror\"") \
_Pragma("GCC diagnostic ignored \"-Werror=\"") \
_Pragma("GCC diagnostic ignored \"-Wunused-variable\"") \
/* Addition options that can be enabled
_Pragma("GCC diagnostic ignored \"-Wpedantic\"") \
_Pragma("GCC diagnostic ignored \"-Wformat=\"") \
_Pragma("GCC diagnostic ignored \"-Werror\"") \
_Pragma("GCC diagnostic ignored \"-Werror=\"") \
_Pragma("GCC diagnostic ignored \"-Wunused-variable\"") \
*/

#define STRICT_MODE_ON \
_Pragma("GCC diagnostic pop")
#endif

#endif

#endif
10 changes: 10 additions & 0 deletions AirLib/include/common/common_utils/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ static int _vscprintf(const char * format, va_list pargs)
int retval;
va_list argcopy;
va_copy(argcopy, pargs);
IGNORE_FORMAT_STRING_ON
retval = vsnprintf(NULL, 0, format, argcopy);
IGNORE_FORMAT_STRING_OFF
va_end(argcopy);
return retval;
}
Expand Down Expand Up @@ -129,7 +131,9 @@ class Utils {
std::unique_ptr<char[]> buf(new char[size]);

#ifndef _MSC_VER
IGNORE_FORMAT_STRING_ON
vsnprintf(buf.get(), size, format, args);
IGNORE_FORMAT_STRING_OFF
#else
vsnprintf_s(buf.get(), size, _TRUNCATE, format, args);
#endif
Expand All @@ -146,7 +150,9 @@ class Utils {
std::unique_ptr<char[]> buf(new char[size]);

#ifndef _MSC_VER
IGNORE_FORMAT_STRING_ON
vsnprintf(buf.get(), size, format, args);
IGNORE_FORMAT_STRING_OFF
#else
vsnprintf_s(buf.get(), size, _TRUNCATE, format, args);
#endif
Expand Down Expand Up @@ -218,11 +224,15 @@ class Utils {
va_list args;
va_start(args, format);

IGNORE_FORMAT_STRING_ON
auto size = _vscprintf(format, args) + 1U;
IGNORE_FORMAT_STRING_OFF
std::unique_ptr<char[]> buf(new char[size] );

#ifndef _MSC_VER
IGNORE_FORMAT_STRING_ON
vsnprintf(buf.get(), size, format, args);
IGNORE_FORMAT_STRING_OFF
#else
vsnprintf_s(buf.get(), size, _TRUNCATE, format, args);
#endif
Expand Down
2 changes: 2 additions & 0 deletions AirLib/include/controllers/ControllerBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class ControllerBase : public UpdatableObject {

virtual void getStatusMessages(std::vector<std::string>& messages)
{
messages; // avoid warning: unused parameter
//default implementation
}

Expand All @@ -46,6 +47,7 @@ class ControllerBase : public UpdatableObject {

virtual void reportTelemetry(float renderTime)
{
renderTime; // avoid warning: unused parameter
//no default action
}

Expand Down
9 changes: 7 additions & 2 deletions AirLib/include/controllers/rosflight/firmware/commonstate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ class CommonState {
{
va_list args;
va_start(args, format);

IGNORE_FORMAT_STRING_ON
auto size = _vscprintf(format, args) + 1U;
IGNORE_FORMAT_STRING_OFF
std::unique_ptr<char[]> buf(new char[size] );

#ifndef _MSC_VER
IGNORE_FORMAT_STRING_ON
vsnprintf(buf.get(), size, format, args);
IGNORE_FORMAT_STRING_OFF
#else
vsnprintf_s(buf.get(), size, _TRUNCATE, format, args);
#endif
Expand All @@ -63,8 +66,10 @@ class CommonState {
{
int retval;
va_list argcopy;
va_copy(argcopy, pargs);
va_copy(argcopy, pargs);
IGNORE_FORMAT_STRING_ON
retval = vsnprintf(NULL, 0, format, argcopy);
IGNORE_FORMAT_STRING_OFF
va_end(argcopy);
return retval;
}
Expand Down
2 changes: 2 additions & 0 deletions AirLib/include/physics/Environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class Environment : public UpdatableObject {
private:
static void updateState(State& state, real_T dt, const EarthUtils::HomeGeoPoint& home_geo_point)
{
dt; // avoid warning: unused parameter

state.geo_point = EarthUtils::nedToGeodetic(state.position, home_geo_point);

real_T geo_pot = EarthUtils::getGeopotential(state.geo_point.altitude / 1000.0f);
Expand Down
1 change: 1 addition & 0 deletions AirLib/include/physics/Kinematics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Kinematics : public UpdatableObject {

virtual void update(real_T dt) override
{
dt; // avoid warning: unused parameter
//nothing to do because next state should be updated
//by physics engine. The reason is that final state
//needs to take in to account state of other objects as well,
Expand Down
1 change: 1 addition & 0 deletions AirLib/include/sensors/gps/GpsSimple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class GpsSimple : public GpsBase {
private:
void addOutputToDelayLine(real_T eph, real_T epv, real_T dt)
{
dt; // avoid warning: unused parameter
Output output;
const GroundTruth& ground_truth = getGroundTruth();

Expand Down
1 change: 1 addition & 0 deletions AirLib/include/sensors/magnetometer/MagnetometerSimple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class MagnetometerSimple : public MagnetometerBase {
}
void updateOutput(real_T dt)
{
dt; // avoid warning: unused parameter
Output output;
const GroundTruth& ground_truth = getGroundTruth();

Expand Down
2 changes: 2 additions & 0 deletions AirLib/include/vehicles/MultiRotor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ class MultiRotor : public PhysicsBody {

void updateSensors(MultiRotorParams& params, const Kinematics::State& state, const Environment& environment, real_T dt)
{
state; // avoid warning: unused parameter
environment; // avoid warning: unused parameter
params.getSensors().update(dt);
}

Expand Down
1 change: 0 additions & 1 deletion AirLib/include/vehicles/MultiRotorParams.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ class MultiRotorParams {
static void initializeRotorQuadX(vector<RotorPose>& rotor_poses /* the result we are building */,
uint rotor_count /* must be 4 */,
real_T arm_lengths[],
real_T arm_angles[],
real_T rotor_z /* z relative to center of gravity */)
{
Vector3r unit_z(0, 0, -1); //NED frame
Expand Down
2 changes: 2 additions & 0 deletions AirLib/include/vehicles/Rotor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class Rotor : public PhysicsBodyVertex {
protected:
virtual void setWrench(Wrench& wrench, real_T dt) override
{
dt; // avoid warning: unused parameter
Vector3r normal = getNormal();
//forces and torques are proportional to air density: http://physics.stackexchange.com/a/32013/14061
wrench.force = normal * output_.thrust * air_density_ratio_;
Expand All @@ -115,6 +116,7 @@ class Rotor : public PhysicsBodyVertex {
private: //methods
static void setOutput(Output& output, const RotorParams& params, const FirstOrderFilter<real_T>& control_signal_filter, RotorTurningDirection turning_direction, real_T dt)
{
dt; // avoid warning: unused parameter
output.control_signal_input = control_signal_filter.getInput();
output.control_signal_filtered = control_signal_filter.getOutput();
//see relationship of rotation speed with thrust: http://physics.stackexchange.com/a/32013/14061
Expand Down
3 changes: 1 addition & 2 deletions AirLib/include/vehicles/configs/FlamewheelQuadX.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class FlamewheelQuadX : public MultiRotorParams {
//dimensions are for F450 frame: http://artofcircuits.com/product/quadcopter-frame-hj450-with-power-distribution
params.rotor_count = 4;
std::vector<real_T> arm_lengths(params.rotor_count, 0.225f);
std::vector<real_T> arm_angles(params.rotor_count, 45);

//set up mass
params.mass = 1.635f;
Expand All @@ -44,7 +43,7 @@ class FlamewheelQuadX : public MultiRotorParams {
real_T rotor_z = 0.15f;

//computer rotor poses
initializeRotorQuadX(params.rotor_poses, params.rotor_count, arm_lengths.data(), arm_angles.data(), rotor_z);
initializeRotorQuadX(params.rotor_poses, params.rotor_count, arm_lengths.data(), rotor_z);
//compute inertia matrix
computeInertiaMatrix(params.inertia, params.body_box, params.rotor_poses, box_mass, motor_assembly_weight);
//create sensors
Expand Down
3 changes: 1 addition & 2 deletions AirLib/include/vehicles/configs/Px4HILQuadX.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class Px4HILQuadX : public MultiRotorParams {
//dimensions are for F450 frame: http://artofcircuits.com/product/quadcopter-frame-hj450-with-power-distribution
params.rotor_count = 4;
std::vector<real_T> arm_lengths(params.rotor_count, 0.2275f);
std::vector<real_T> arm_angles(params.rotor_count, 45);

//set up mass
params.mass = 1.0f; //can be varied from 0.800 to 1.600
Expand All @@ -41,7 +40,7 @@ class Px4HILQuadX : public MultiRotorParams {
real_T rotor_z = 2.5f / 100;

//computer rotor poses
initializeRotorQuadX(params.rotor_poses, params.rotor_count, arm_lengths.data(), arm_angles.data(), rotor_z);
initializeRotorQuadX(params.rotor_poses, params.rotor_count, arm_lengths.data(), rotor_z);
//compute inertia matrix
computeInertiaMatrix(params.inertia, params.body_box, params.rotor_poses, box_mass, motor_assembly_weight);
//create sensors
Expand Down
3 changes: 3 additions & 0 deletions AirLib/src/controllers/DroneControllerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ float DroneControllerBase::getAutoLookahead(float velocity, float adaptive_looka

float DroneControllerBase::getObsAvoidanceVelocity(float risk_dist, float max_obs_avoidance_vel)
{
risk_dist; // avoid warning: unused parameter
return max_obs_avoidance_vel;
}

Expand Down Expand Up @@ -605,6 +606,8 @@ void DroneControllerBase::adjustYaw(float x, float y, DrivetrainType drivetrain,

void DroneControllerBase::moveToPathPosition(const Vector3r& dest, float velocity, DrivetrainType drivetrain, /* pass by value */ YawMode yaw_mode, float last_z)
{
last_z; // avoid warning: unused parameter

//validate dest
if (dest.hasNaN())
throw std::invalid_argument(VectorMath::toString(dest,"dest vector cannot have NaN: "));
Expand Down
Loading

0 comments on commit d0d6eb3

Please sign in to comment.