Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 13 additions & 0 deletions src/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1728,6 +1728,19 @@ add_to_cflags() {
# Always add -Wextra
add_to_cflags "-Wextra"

# Add option to enable warnings when integer 0 is used to act
# as NULL or nullptr in assignment or comparison.
AC_ARG_ENABLE(wzero-as-null-pointer-constant,
AS_HELP_STRING(
[--enable-wzero-as-null-pointer-constant],
[Warn on zero being used as NULL pointer constant (-Wzero-as-null-pointer-constant).],
),
[
case "$enableval" in
(yes) add_to_cflags "-Wzero-as-null-pointer-constant" ;;
esac
])

# The last thing before subst-exporting CFLAGS and CXXFLAGS is to add -Werror
# if requested. Doing it earlier causes conf-tests to fail that are supposed to
# succeed when they generate warnings.
Expand Down
8 changes: 4 additions & 4 deletions src/emc/canterp/canterp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static char the_command_args[LINELEN] = { 0 }; // just the args part

class Canterp : public InterpBase {
public:
Canterp () : f(0), filename{} {}
Canterp () : f(NULL), filename{} {}
char *error_text(int errcode, char *buf, size_t buflen) override;
char *stack_name(int index, char *buf, size_t buflen) override;
char *line_text(char *buf, size_t buflen) override;
Expand Down Expand Up @@ -209,7 +209,7 @@ static int canterp_parse(char *buffer)
now we're at the args; skip first and last quotes when building
args_ptr, and make commas spaces for easy parsing later
*/
last_quote_ptr = 0;
last_quote_ptr = NULL;
inquote = 0;
while (')' != *ptr && 0 != *ptr) {
if ('"' == *ptr) {
Expand All @@ -235,7 +235,7 @@ static int canterp_parse(char *buffer)
*cmd_ptr = 0;
return INTERP_ERROR;
}
if (0 != last_quote_ptr)
if (NULL != last_quote_ptr)
*last_quote_ptr = 0;
*args_ptr = 0;
*cmd_ptr++ = ')';
Expand Down Expand Up @@ -692,7 +692,7 @@ int Canterp::execute(const char *line, int /*line_number*/) {
}

int Canterp::execute() {
return execute(0);
return execute(NULL);
}

int Canterp::open(const char *newfilename) {
Expand Down
36 changes: 18 additions & 18 deletions src/emc/ini/inifile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1106,9 +1106,9 @@ std::optional<rtapi_s64> IniFile::convertSInt(const std::string &_val)
char *eptr;

// Make sure we always use the C locale for conversion (thread local)
locale_t olc = uselocale(static_cast<locale_t>(0));
locale_t nlc = newlocale(LC_NUMERIC_MASK, "C", static_cast<locale_t>(0));
if(static_cast<locale_t>(0) == nlc) {
locale_t olc = uselocale(static_cast<locale_t>(nullptr));
locale_t nlc = newlocale(LC_NUMERIC_MASK, "C", static_cast<locale_t>(nullptr));
if(static_cast<locale_t>(nullptr) == nlc) {
print_msg("internal error: ConvertSInt(): Cannot set locale to \"C\" for strtoll");
return std::nullopt;
}
Expand All @@ -1135,9 +1135,9 @@ std::optional<rtapi_s64> IniFile::convertSInt(const IniFileTag *val) const
char *eptr;

// Make sure we always use the C locale for conversion (thread local)
locale_t olc = uselocale(static_cast<locale_t>(0));
locale_t nlc = newlocale(LC_NUMERIC_MASK, "C", static_cast<locale_t>(0));
if(static_cast<locale_t>(0) == nlc) {
locale_t olc = uselocale(static_cast<locale_t>(nullptr));
locale_t nlc = newlocale(LC_NUMERIC_MASK, "C", static_cast<locale_t>(nullptr));
if(static_cast<locale_t>(nullptr) == nlc) {
print_msg(fmt::format("{}:{}: internal error: Cannot set locale to \"C\" for strtoll", val->path, val->lineno));
return std::nullopt;
}
Expand Down Expand Up @@ -1171,9 +1171,9 @@ std::optional<rtapi_u64> IniFile::convertUInt(const std::string &_val)
}

// Make sure we always use the C locale for conversion (thread local)
locale_t olc = uselocale(static_cast<locale_t>(0));
locale_t nlc = newlocale(LC_NUMERIC_MASK, "C", static_cast<locale_t>(0));
if(static_cast<locale_t>(0) == nlc) {
locale_t olc = uselocale(static_cast<locale_t>(nullptr));
locale_t nlc = newlocale(LC_NUMERIC_MASK, "C", static_cast<locale_t>(nullptr));
if(static_cast<locale_t>(nullptr) == nlc) {
print_msg("internal error: ConvertUInt(): Cannot set locale to \"C\" for strtoull");
return std::nullopt;
}
Expand Down Expand Up @@ -1205,9 +1205,9 @@ std::optional<rtapi_u64> IniFile::convertUInt(const IniFileTag *val) const
}

// Make sure we always use the C locale for conversion (thread local)
locale_t olc = uselocale(static_cast<locale_t>(0));
locale_t nlc = newlocale(LC_NUMERIC_MASK, "C", static_cast<locale_t>(0));
if(static_cast<locale_t>(0) == nlc) {
locale_t olc = uselocale(static_cast<locale_t>(nullptr));
locale_t nlc = newlocale(LC_NUMERIC_MASK, "C", static_cast<locale_t>(nullptr));
if(static_cast<locale_t>(nullptr) == nlc) {
print_msg(fmt::format("{}:{}: internal error: Cannot set locale to \"C\" for strtoull", val->path, val->lineno));
return std::nullopt;
}
Expand Down Expand Up @@ -1235,9 +1235,9 @@ std::optional<double> IniFile::convertReal(const std::string &val)
char *eptr;

// Make sure we always use the C locale for conversion (thread local)
locale_t olc = uselocale(static_cast<locale_t>(0));
locale_t nlc = newlocale(LC_NUMERIC_MASK, "C", static_cast<locale_t>(0));
if(static_cast<locale_t>(0) == nlc) {
locale_t olc = uselocale(static_cast<locale_t>(nullptr));
locale_t nlc = newlocale(LC_NUMERIC_MASK, "C", static_cast<locale_t>(nullptr));
if(static_cast<locale_t>(nullptr) == nlc) {
print_msg("internal error: ConvertReal(): Cannot set locale to \"C\" for strtod");
return std::nullopt;
}
Expand All @@ -1262,9 +1262,9 @@ std::optional<double> IniFile::convertReal(const IniFileTag *val) const
char *eptr;

// Make sure we always use the C locale for conversion (thread local)
locale_t olc = uselocale(static_cast<locale_t>(0));
locale_t nlc = newlocale(LC_NUMERIC_MASK, "C", static_cast<locale_t>(0));
if(static_cast<locale_t>(0) == nlc) {
locale_t olc = uselocale(static_cast<locale_t>(nullptr));
locale_t nlc = newlocale(LC_NUMERIC_MASK, "C", static_cast<locale_t>(nullptr));
if(static_cast<locale_t>(nullptr) == nlc) {
print_msg(fmt::format("{}:{}: internal error: Cannot set locale to \"C\" for strtod", val->path, val->lineno));
return std::nullopt;
}
Expand Down
2 changes: 1 addition & 1 deletion src/emc/ini/inihal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ int ini_hal_init(int numjoints)
}

the_inihal_data = (ptr_inihal_data *) hal_malloc(sizeof(ptr_inihal_data));
if (the_inihal_data == 0) {
if (the_inihal_data == NULL) {
rtapi_print_msg(RTAPI_MSG_ERR,
"ini_hal_init: ERROR: hal_malloc() failed\n");
hal_exit(comp_id);
Expand Down
2 changes: 1 addition & 1 deletion src/emc/kinematics/genserfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static struct haldata {
genser_struct *kins;
go_pose *pos; // used in various functions, we malloc it
// only once in genserKinematicsSetup()
} *haldata = 0;
} *haldata = NULL;

static int total_joints;
double j[GENSER_MAX_JOINTS];
Expand Down
3 changes: 3 additions & 0 deletions src/emc/kinematics/lineardeltakins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ static object get_geometry()
return make_tuple(R, L);
}

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
BOOST_PYTHON_MODULE(lineardeltakins)
{
set_geometry(DELTA_RADIUS, DELTA_DIAGONAL_ROD);
Expand All @@ -54,3 +56,4 @@ BOOST_PYTHON_MODULE(lineardeltakins)
def("forward", forward);
def("inverse", inverse);
}
#pragma GCC diagnostic pop
3 changes: 3 additions & 0 deletions src/emc/kinematics/rotarydeltakins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ static object get_geometry()
return make_tuple(platformradius, thighlength, shinlength, footradius);
}

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
BOOST_PYTHON_MODULE(rotarydeltakins)
{
set_geometry(RDELTA_PFR, RDELTA_TL, RDELTA_SL, RDELTA_FR);
Expand All @@ -53,3 +55,4 @@ BOOST_PYTHON_MODULE(rotarydeltakins)
def("forward", forward);
def("inverse", inverse);
}
#pragma GCC diagnostic pop
22 changes: 11 additions & 11 deletions src/emc/motion-logger/motion-logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ static struct motion_logger_data_t {
FILE *logfile = NULL;
char *logfile_name = NULL;

emcmot_struct_t *emcmotStruct = 0;
emcmot_struct_t *emcmotStruct = NULL;

struct emcmot_command_t *c = 0;
struct emcmot_status_t *emcmotStatus = 0;
struct emcmot_config_t *emcmotConfig = 0;
struct emcmot_internal_t *emcmotInternal = 0;
struct emcmot_error_t *emcmotError = 0;
struct emcmot_command_t *c = NULL;
struct emcmot_status_t *emcmotStatus = NULL;
struct emcmot_config_t *emcmotConfig = NULL;
struct emcmot_internal_t *emcmotInternal = NULL;
struct emcmot_error_t *emcmotError = NULL;

static int mot_comp_id;

Expand Down Expand Up @@ -85,11 +85,11 @@ static int init_comm_buffers(void) {
rtapi_print_msg(RTAPI_MSG_INFO,
"MOTION: init_comm_buffers() starting...\n");

emcmotStruct = 0;
emcmotInternal = 0;
emcmotStatus = 0;
c = 0;
emcmotConfig = 0;
emcmotStruct = NULL;
emcmotInternal = NULL;
emcmotStatus = NULL;
c = NULL;
emcmotConfig = NULL;

/* allocate and initialize the shared memory structure */
shmem_id = rtapi_shmem_new(DEFAULT_SHMEM_KEY, mot_comp_id, sizeof(emcmot_struct_t));
Expand Down
2 changes: 1 addition & 1 deletion src/emc/motion/dbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ int dbuf_get_string(dbuf_iter *di, const char **s) {
// NUL, but let's be safe and not return a string if there's no terminated
// string in the dbuf
if(ch != 0) {
*s = 0;
*s = NULL;
return -EAGAIN;
}

Expand Down
6 changes: 3 additions & 3 deletions src/emc/motion/emcmotutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

int emcmotErrorInit(emcmot_error_t * errlog)
{
if (errlog == 0) {
if (errlog == NULL) {
return -1;
}

Expand All @@ -53,7 +53,7 @@ int emcmotErrorPutfv(emcmot_error_t * errlog, const char *fmt, va_list ap)
struct dbuf_iter it;
unsigned long long my_seq;

if (errlog == 0) {
if (errlog == NULL) {
return -1;
}

Expand Down Expand Up @@ -108,7 +108,7 @@ int emcmotErrorGet(emcmot_error_t * errlog, char *error)
unsigned long long w_res;
unsigned long long w_com;

if (errlog == 0) {
if (errlog == NULL) {
return -1;
}

Expand Down
30 changes: 15 additions & 15 deletions src/emc/motion/usrmotintf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ using namespace linuxcnc;

static int inited = 0; /* flag if inited */

static emcmot_command_t *emcmotCommand = 0;
static emcmot_status_t *emcmotStatus = 0;
static emcmot_config_t *emcmotConfig = 0;
static emcmot_internal_t *emcmotInternal = 0;
static emcmot_error_t *emcmotError = 0;
static emcmot_struct_t *emcmotStruct = 0;
static emcmot_command_t *emcmotCommand = NULL;
static emcmot_status_t *emcmotStatus = NULL;
static emcmot_config_t *emcmotConfig = NULL;
static emcmot_internal_t *emcmotInternal = NULL;
static emcmot_error_t *emcmotError = NULL;
static emcmot_struct_t *emcmotStruct = NULL;

/* usrmotIniLoad() loads params (SHMEM_KEY, COMM_TIMEOUT)
from named INI file */
Expand Down Expand Up @@ -89,7 +89,7 @@ int usrmotWriteEmcmotCommand(emcmot_command_t * c)
c->commandNum = ++commandNum;

/* check for mapped mem still around */
if (0 == emcmotCommand) {
if (NULL == emcmotCommand) {
rcs_print("USRMOT: ERROR: can't connect to shared memory\n");
return EMCMOT_COMM_ERROR_CONNECT;
}
Expand Down Expand Up @@ -126,7 +126,7 @@ int usrmotReadEmcmotStatus(emcmot_status_t * s)
int split_read_count;

/* check for shmem still around */
if (0 == emcmotStatus) {
if (NULL == emcmotStatus) {
return EMCMOT_COMM_ERROR_CONNECT;
}
split_read_count = 0;
Expand All @@ -152,7 +152,7 @@ int usrmotReadEmcmotConfig(emcmot_config_t * s)
int split_read_count;

/* check for shmem still around */
if (0 == emcmotConfig) {
if (NULL == emcmotConfig) {
return EMCMOT_COMM_ERROR_CONNECT;
}
split_read_count = 0;
Expand All @@ -177,7 +177,7 @@ int usrmotReadEmcmotInternal(emcmot_internal_t * s)
int split_read_count;

/* check for shmem still around */
if (0 == emcmotInternal) {
if (NULL == emcmotInternal) {
return EMCMOT_COMM_ERROR_CONNECT;
}
split_read_count = 0;
Expand All @@ -200,7 +200,7 @@ int usrmotReadEmcmotInternal(emcmot_internal_t * s)
int usrmotReadEmcmotError(char *e)
{
/* check to see if ptr still around */
if (emcmotError == 0) {
if (emcmotError == NULL) {
return -1;
}

Expand Down Expand Up @@ -609,10 +609,10 @@ int usrmotExit(void)
rtapi_exit(module_id);
}

emcmotStruct = 0;
emcmotCommand = 0;
emcmotStatus = 0;
emcmotError = 0;
emcmotStruct = NULL;
emcmotCommand = NULL;
emcmotStatus = NULL;
emcmotError = NULL;
/*! \todo Another #if 0 */
#if 0
/*! \todo FIXME - comp structs no longer in shmem */
Expand Down
4 changes: 2 additions & 2 deletions src/emc/pythonplugin/python_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ PythonPlugin::PythonPlugin(struct _inittab *inittab) :
status(0),
module_mtime(0),
reload_on_change(0),
toplevel(0),
abs_path(0),
toplevel(NULL),
abs_path(NULL),
log_level(0)
{
PyConfig config;
Expand Down
3 changes: 3 additions & 0 deletions src/emc/rs274ngc/canonmodule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ static void wrap_canon_error(const char *s)
}


#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
BOOST_PYTHON_MODULE(emccanon) {
using namespace boost::python;
scope().attr("__doc__") =
Expand Down Expand Up @@ -269,3 +271,4 @@ BOOST_PYTHON_MODULE(emccanon) {
def("GET_EXTERNAL_OFFSETS",&GET_EXTERNAL_OFFSETS);

}
#pragma GCC diagnostic pop
9 changes: 6 additions & 3 deletions src/emc/rs274ngc/gcodemodule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ static PyMemberDef LineCodeMembers[] = {
{}
};

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
static PyTypeObject LineCodeType = {
PyVarObject_HEAD_INIT(NULL, 0)
"gcode.linecode", /*tp_name*/
Expand Down Expand Up @@ -180,6 +182,7 @@ static PyTypeObject LineCodeType = {
#endif
#endif
};
#pragma GCC diagnostic pop

static PyObject *callback;
static int interp_error;
Expand Down Expand Up @@ -854,8 +857,8 @@ void SET_NAIVECAM_TOLERANCE(double /*tolerance*/) { }
#define RESULT_OK (result == INTERP_OK || result == INTERP_EXECUTE_FINISH)
static PyObject *parse_file(PyObject * /*self*/, PyObject *args) {
char *f;
char *unitcode=0, *initcode=0, *interpname=0;
PyObject *initcodes=0;
char *unitcode=NULL, *initcode=NULL, *interpname=NULL;
PyObject *initcodes=NULL;
int error_line_offset = 0;
struct timeval t0, t1;
int wait = 1;
Expand All @@ -872,7 +875,7 @@ static PyObject *parse_file(PyObject * /*self*/, PyObject *args) {

if(pinterp) {
delete pinterp;
pinterp = 0;
pinterp = NULL;
}
if(interpname && *interpname)
pinterp = interp_from_shlib(interpname);
Expand Down
Loading