Skip to content

Commit d33ad02

Browse files
committed
Eliminate "ret" within _ethtool_etherinfo_getter
This variable was confusing cppcheck and potentially could introduce a read of an uninitialized variable if the code were carelessly modified - simplify it.
1 parent 9ddf531 commit d33ad02

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

python-ethtool/etherinfo_obj.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ int _ethtool_etherinfo_init(etherinfo_py *self, PyObject *args, PyObject *kwds)
101101
*/
102102
PyObject *_ethtool_etherinfo_getter(etherinfo_py *self, PyObject *attr_o)
103103
{
104-
PyObject *ret;
105104
char *attr = PyString_AsString(attr_o);
106105

107106
if( !self || !self->data ) {
@@ -110,24 +109,22 @@ PyObject *_ethtool_etherinfo_getter(etherinfo_py *self, PyObject *attr_o)
110109
}
111110

112111
if( strcmp(attr, "device") == 0 ) {
113-
ret = RETURN_STRING(self->data->ethinfo->device);
112+
return RETURN_STRING(self->data->ethinfo->device);
114113
} else if( strcmp(attr, "mac_address") == 0 ) {
115114
get_etherinfo(self->data, NLQRY_LINK);
116-
ret = RETURN_STRING(self->data->ethinfo->hwaddress);
115+
return RETURN_STRING(self->data->ethinfo->hwaddress);
117116
} else if( strcmp(attr, "ipv4_address") == 0 ) {
118117
get_etherinfo(self->data, NLQRY_ADDR);
119-
ret = RETURN_STRING(self->data->ethinfo->ipv4_address);
118+
return RETURN_STRING(self->data->ethinfo->ipv4_address);
120119
} else if( strcmp(attr, "ipv4_netmask") == 0 ) {
121120
get_etherinfo(self->data, NLQRY_ADDR);
122-
ret = PyInt_FromLong(self->data->ethinfo->ipv4_netmask);
121+
return PyInt_FromLong(self->data->ethinfo->ipv4_netmask);
123122
} else if( strcmp(attr, "ipv4_broadcast") == 0 ) {
124123
get_etherinfo(self->data, NLQRY_ADDR);
125-
ret = RETURN_STRING(self->data->ethinfo->ipv4_broadcast);
124+
return RETURN_STRING(self->data->ethinfo->ipv4_broadcast);
126125
} else {
127-
ret = PyObject_GenericGetAttr((PyObject *)self, attr_o);
126+
return PyObject_GenericGetAttr((PyObject *)self, attr_o);
128127
}
129-
130-
return ret;
131128
}
132129

133130
/**

0 commit comments

Comments
 (0)