Skip to content

Commit

Permalink
[Make]: Fix type conversions and add more warnings (sonic-net#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored and Shu0T1an ChenG committed Jul 27, 2017
1 parent 06309b6 commit 8f13f8e
Show file tree
Hide file tree
Showing 17 changed files with 131 additions and 99 deletions.
34 changes: 34 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,40 @@ AM_CONDITIONAL(GTEST, test x$gtest = xtrue)
CFLAGS_COMMON="-std=c++11 -Wall -fPIC -Wno-write-strings -I/usr/include/libnl3 -I/usr/include/swss"
CFLAGS_COMMON+=" -Werror"
CFLAGS_COMMON+=" -Wno-reorder"
CFLAGS_COMMON+=" -Wcast-align"
CFLAGS_COMMON+=" -Wcast-qual"
CFLAGS_COMMON+=" -Wconversion"
CFLAGS_COMMON+=" -Wdisabled-optimization"
CFLAGS_COMMON+=" -Wextra"
CFLAGS_COMMON+=" -Wfloat-equal"
CFLAGS_COMMON+=" -Wformat=2"
CFLAGS_COMMON+=" -Wformat-nonliteral"
CFLAGS_COMMON+=" -Wformat-security"
CFLAGS_COMMON+=" -Wformat-y2k"
CFLAGS_COMMON+=" -Wimport"
CFLAGS_COMMON+=" -Winit-self"
CFLAGS_COMMON+=" -Winvalid-pch"
CFLAGS_COMMON+=" -Wlong-long"
CFLAGS_COMMON+=" -Wmissing-field-initializers"
CFLAGS_COMMON+=" -Wmissing-format-attribute"
CFLAGS_COMMON+=" -Wno-aggregate-return"
CFLAGS_COMMON+=" -Wno-padded"
CFLAGS_COMMON+=" -Wno-switch-enum"
CFLAGS_COMMON+=" -Wno-unused-parameter"
CFLAGS_COMMON+=" -Wpacked"
CFLAGS_COMMON+=" -Wpointer-arith"
CFLAGS_COMMON+=" -Wredundant-decls"
CFLAGS_COMMON+=" -Wstack-protector"
CFLAGS_COMMON+=" -Wstrict-aliasing=3"
CFLAGS_COMMON+=" -Wswitch"
CFLAGS_COMMON+=" -Wswitch-default"
CFLAGS_COMMON+=" -Wunreachable-code"
CFLAGS_COMMON+=" -Wunused"
CFLAGS_COMMON+=" -Wvariadic-macros"
CFLAGS_COMMON+=" -Wno-switch-default"
CFLAGS_COMMON+=" -Wno-long-long"
CFLAGS_COMMON+=" -Wno-redundant-decls"

AC_SUBST(CFLAGS_COMMON)

AC_CONFIG_FILES([
Expand Down
4 changes: 2 additions & 2 deletions fpmsyncd/fpmlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void FpmLink::readMe()
throw FpmConnectionClosedException();
if (read < 0)
throw system_error(errno, system_category());
m_pos+= read;
m_pos+= (uint32_t)read;

/* Check for complete messages */
while (true)
Expand Down Expand Up @@ -140,5 +140,5 @@ void FpmLink::readMe()
}

memmove(m_messageBuffer, m_messageBuffer + start, m_pos - start);
m_pos = m_pos - start;
m_pos = m_pos - (uint32_t)start;
}
31 changes: 15 additions & 16 deletions orchagent/aclorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ bool AclRule::validateAddPriority(string attr_name, string attr_value)
{
char *endp = NULL;
errno = 0;
m_priority = strtol(attr_value.c_str(), &endp, 0);
m_priority = (uint32_t)strtol(attr_value.c_str(), &endp, 0);
// chack conversion was successfull and the value is within the allowed range
status = (errno == 0) &&
(endp == attr_value.c_str() + attr_value.size()) &&
Expand Down Expand Up @@ -161,23 +161,23 @@ bool AclRule::validateAddMatch(string attr_name, string attr_value)
flags = trim(flagsData[0]);
mask = trim(flagsData[1]);

val = strtol(flags.c_str(), &endp, 0);
val = (uint32_t)strtol(flags.c_str(), &endp, 0);
if (errno || (endp != flags.c_str() + flags.size()) ||
(val < 0) || (val > UCHAR_MAX))
{
SWSS_LOG_ERROR("TCP flags parse error, value: %s(=%d), errno: %d", flags.c_str(), val, errno);
return false;
}
value.aclfield.data.u8 = val;
value.aclfield.data.u8 = (uint8_t)val;

val = strtol(mask.c_str(), &endp, 0);
val = (uint32_t)strtol(mask.c_str(), &endp, 0);
if (errno || (endp != mask.c_str() + mask.size()) ||
(val < 0) || (val > UCHAR_MAX))
{
SWSS_LOG_ERROR("TCP mask parse error, value: %s(=%d), errno: %d", mask.c_str(), val, errno);
return false;
}
value.aclfield.mask.u8 = val;
value.aclfield.mask.u8 = (uint8_t)val;
}
else if(attr_name == MATCH_ETHER_TYPE || attr_name == MATCH_L4_SRC_PORT || attr_name == MATCH_L4_DST_PORT)
{
Expand Down Expand Up @@ -344,7 +344,7 @@ bool AclRule::create()
rule_attrs.push_back(attr);
}

status = sai_acl_api->create_acl_entry(&m_ruleOid, gSwitchId, rule_attrs.size(), rule_attrs.data());
status = sai_acl_api->create_acl_entry(&m_ruleOid, gSwitchId, (uint32_t)rule_attrs.size(), rule_attrs.data());
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create ACL rule");
Expand Down Expand Up @@ -483,7 +483,7 @@ bool AclRule::createCounter()
attr.value.booldata = true;
counter_attrs.push_back(attr);

if (sai_acl_api->create_acl_counter(&m_counterOid, gSwitchId, counter_attrs.size(), counter_attrs.data()) != SAI_STATUS_SUCCESS)
if (sai_acl_api->create_acl_counter(&m_counterOid, gSwitchId, (uint32_t)counter_attrs.size(), counter_attrs.data()) != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create counter for the rule %s in table %s", m_id.c_str(), m_tableId.c_str());
return false;
Expand Down Expand Up @@ -891,7 +891,7 @@ AclRange *AclRange::create(sai_acl_range_type_t type, int min, int max)
attr.value.u32range.max = max;
range_attrs.push_back(attr);

status = sai_acl_api->create_acl_range(&range_oid, gSwitchId, range_attrs.size(), range_attrs.data());
status = sai_acl_api->create_acl_range(&range_oid, gSwitchId, (uint32_t)range_attrs.size(), range_attrs.data());
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create range object");
Expand Down Expand Up @@ -985,14 +985,13 @@ AclOrch::AclOrch(DBConnector *db, vector<string> tableNames, PortsOrch *portOrch
{
SWSS_LOG_ENTER();

sai_attribute_t attrs[] =
{
{ SAI_SWITCH_ATTR_ACL_ENTRY_MINIMUM_PRIORITY },
{ SAI_SWITCH_ATTR_ACL_ENTRY_MAXIMUM_PRIORITY }
};
sai_attribute_t attrs[2];

attrs[0].id = SAI_SWITCH_ATTR_ACL_ENTRY_MINIMUM_PRIORITY;
attrs[1].id = SAI_SWITCH_ATTR_ACL_ENTRY_MAXIMUM_PRIORITY;

// get min/max allowed priority
if (sai_switch_api->get_switch_attribute(gSwitchId, sizeof(attrs)/sizeof(attrs[0]), attrs) == SAI_STATUS_SUCCESS)
if (sai_switch_api->get_switch_attribute(gSwitchId, 2, attrs) == SAI_STATUS_SUCCESS)
{
SWSS_LOG_INFO("Got ACL entry priority values, min: %u, max: %u", attrs[0].value.u32, attrs[1].value.u32);
AclRule::setRulePriorities(attrs[0].value.u32, attrs[1].value.u32);
Expand Down Expand Up @@ -1454,11 +1453,11 @@ sai_status_t AclOrch::createBindAclTable(AclTable &aclTable, sai_object_id_t &ta
}

attr.id = SAI_ACL_TABLE_ATTR_FIELD_ACL_RANGE_TYPE;
attr.value.s32list.count = sizeof(range_types_list) / sizeof(range_types_list[0]);
attr.value.s32list.count = (uint32_t)(sizeof(range_types_list) / sizeof(range_types_list[0]));
attr.value.s32list.list = range_types_list;
table_attrs.push_back(attr);

status = sai_acl_api->create_acl_table(&table_oid, gSwitchId, table_attrs.size(), table_attrs.data());
status = sai_acl_api->create_acl_table(&table_oid, gSwitchId, (uint32_t)table_attrs.size(), table_attrs.data());

if (status == SAI_STATUS_SUCCESS)
{
Expand Down
20 changes: 10 additions & 10 deletions orchagent/bufferorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ task_process_status BufferOrch::processBufferPool(Consumer &consumer)
if (fvField(*i) == buffer_size_field_name)
{
attr.id = SAI_BUFFER_POOL_ATTR_SIZE;
attr.value.u32 = stoul(fvValue(*i));
attr.value.u32 = (uint32_t)stoul(fvValue(*i));
attribs.push_back(attr);
}
else if (fvField(*i) == buffer_pool_type_field_name)
Expand Down Expand Up @@ -129,7 +129,7 @@ task_process_status BufferOrch::processBufferPool(Consumer &consumer)
}
else
{
sai_status = sai_buffer_api->create_buffer_pool(&sai_object, gSwitchId, attribs.size(), attribs.data());
sai_status = sai_buffer_api->create_buffer_pool(&sai_object, gSwitchId, (uint32_t)attribs.size(), attribs.data());
if (SAI_STATUS_SUCCESS != sai_status)
{
SWSS_LOG_ERROR("Failed to create buffer pool %s with type %s, rv:%d", object_name.c_str(), map_type_name.c_str(), sai_status);
Expand Down Expand Up @@ -204,32 +204,32 @@ task_process_status BufferOrch::processBufferProfile(Consumer &consumer)
}
else if (fvField(*i) == buffer_xon_field_name)
{
attr.value.u32 = stoul(fvValue(*i));
attr.value.u32 = (uint32_t)stoul(fvValue(*i));
attr.id = SAI_BUFFER_PROFILE_ATTR_XON_TH;
attribs.push_back(attr);
}
else if (fvField(*i) == buffer_xoff_field_name)
{
attr.value.u32 = stoul(fvValue(*i));
attr.value.u32 = (uint32_t)stoul(fvValue(*i));
attr.id = SAI_BUFFER_PROFILE_ATTR_XOFF_TH;
attribs.push_back(attr);
}
else if (fvField(*i) == buffer_size_field_name)
{
attr.id = SAI_BUFFER_PROFILE_ATTR_BUFFER_SIZE;
attr.value.u32 = stoul(fvValue(*i));
attr.value.u32 = (uint32_t)stoul(fvValue(*i));
attribs.push_back(attr);
}
else if (fvField(*i) == buffer_dynamic_th_field_name)
{
attr.id = SAI_BUFFER_PROFILE_ATTR_SHARED_DYNAMIC_TH;
attr.value.u32 = stoul(fvValue(*i));
attr.value.u32 = (uint32_t)stoul(fvValue(*i));
attribs.push_back(attr);
}
else if (fvField(*i) == buffer_static_th_field_name)
{
attr.id = SAI_BUFFER_PROFILE_ATTR_SHARED_STATIC_TH;
attr.value.u32 = stoul(fvValue(*i));
attr.value.u32 = (uint32_t)stoul(fvValue(*i));
attribs.push_back(attr);
}
else
Expand All @@ -250,7 +250,7 @@ task_process_status BufferOrch::processBufferProfile(Consumer &consumer)
}
else
{
sai_status = sai_buffer_api->create_buffer_profile(&sai_object, gSwitchId, attribs.size(), attribs.data());
sai_status = sai_buffer_api->create_buffer_profile(&sai_object, gSwitchId, (uint32_t)attribs.size(), attribs.data());
if (SAI_STATUS_SUCCESS != sai_status)
{
SWSS_LOG_ERROR("Failed to create buffer profile %s with type %s, rv:%d", object_name.c_str(), map_type_name.c_str(), sai_status);
Expand Down Expand Up @@ -456,7 +456,7 @@ task_process_status BufferOrch::processIngressBufferProfileList(Consumer &consum
}
sai_attribute_t attr;
attr.id = SAI_PORT_ATTR_QOS_INGRESS_BUFFER_PROFILE_LIST;
attr.value.objlist.count = profile_list.size();
attr.value.objlist.count = (uint32_t)profile_list.size();
attr.value.objlist.list = profile_list.data();
for (string port_name : port_names)
{
Expand Down Expand Up @@ -502,7 +502,7 @@ task_process_status BufferOrch::processEgressBufferProfileList(Consumer &consume
}
sai_attribute_t attr;
attr.id = SAI_PORT_ATTR_QOS_EGRESS_BUFFER_PROFILE_LIST;
attr.value.objlist.count = profile_list.size();
attr.value.objlist.count = (uint32_t)profile_list.size();
attr.value.objlist.list = profile_list.data();
for (string port_name : port_names)
{
Expand Down
10 changes: 5 additions & 5 deletions orchagent/copporch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void CoppOrch::initDefaultHostTable()
sai_if_channel_attrs.push_back(sai_if_channel_attr);

sai_status_t status = sai_hostif_api->create_hostif_table_entry(
&host_table_entry[0], gSwitchId, sai_if_channel_attrs.size(), sai_if_channel_attrs.data());
&host_table_entry[0], gSwitchId, (uint32_t)sai_if_channel_attrs.size(), sai_if_channel_attrs.data());
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create hostif table entry, rc=%d", status);
Expand Down Expand Up @@ -189,7 +189,7 @@ bool CoppOrch::applyAttributesToTrapIds(sai_object_id_t trap_group_id,
attrs.insert(attrs.end(), trap_id_attribs.begin(), trap_id_attribs.end());

sai_object_id_t hostif_trap_id;
status = sai_hostif_api->create_hostif_trap(&hostif_trap_id, gSwitchId, attrs.size(), attrs.data());
status = sai_hostif_api->create_hostif_trap(&hostif_trap_id, gSwitchId, (uint32_t)attrs.size(), attrs.data());
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create trap %d, rc=%d", trap_id, status);
Expand Down Expand Up @@ -300,7 +300,7 @@ bool CoppOrch::createPolicer(string trap_group_name, vector<sai_attribute_t> &po
sai_object_id_t policer_id;
sai_status_t sai_status;

sai_status = sai_policer_api->create_policer(&policer_id, gSwitchId, policer_attribs.size(), policer_attribs.data());
sai_status = sai_policer_api->create_policer(&policer_id, gSwitchId, (uint32_t)policer_attribs.size(), policer_attribs.data());
if (sai_status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create policer trap group %s, rc=%d", trap_group_name.c_str(), sai_status);
Expand Down Expand Up @@ -356,7 +356,7 @@ task_process_status CoppOrch::processCoppRule(Consumer& consumer)
queue_ind = fvValue(*i);
SWSS_LOG_DEBUG("queue data:%s", queue_ind.c_str());
attr.id = SAI_HOSTIF_TRAP_GROUP_ATTR_QUEUE;
attr.value.u32 = stoul(queue_ind);
attr.value.u32 = (uint32_t)stoul(queue_ind);
trap_gr_attribs.push_back(attr);
}
//
Expand Down Expand Up @@ -507,7 +507,7 @@ task_process_status CoppOrch::processCoppRule(Consumer& consumer)
{
sai_object_id_t new_trap;

sai_status = sai_hostif_api->create_hostif_trap_group(&new_trap, gSwitchId, trap_gr_attribs.size(), trap_gr_attribs.data());
sai_status = sai_hostif_api->create_hostif_trap_group(&new_trap, gSwitchId, (uint32_t)trap_gr_attribs.size(), trap_gr_attribs.data());
if (sai_status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create host interface trap group %s, rc=%d", trap_group_name.c_str(), sai_status);
Expand Down
2 changes: 1 addition & 1 deletion orchagent/fdborch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ bool FdbOrch::addFdbEntry(const FdbEntry& entry, const string& port_name, const
attr.value.s32 = SAI_PACKET_ACTION_FORWARD;
attrs.push_back(attr);

status = sai_fdb_api->create_fdb_entry(&fdb_entry, attrs.size(), attrs.data());
status = sai_fdb_api->create_fdb_entry(&fdb_entry, (uint32_t)attrs.size(), attrs.data());
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to add FDB entry. mac=%s, vlan=%d. port_name %s. type %s",
Expand Down
6 changes: 3 additions & 3 deletions orchagent/intfsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ bool IntfsOrch::addRouterIntfs(Port &port)
}
attrs.push_back(attr);

sai_status_t status = sai_router_intfs_api->create_router_interface(&port.m_rif_id, gSwitchId, attrs.size(), attrs.data());
sai_status_t status = sai_router_intfs_api->create_router_interface(&port.m_rif_id, gSwitchId, (uint32_t)attrs.size(), attrs.data());
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create router interface for port %s, rv:%d", port.m_alias.c_str(), status);
Expand Down Expand Up @@ -312,7 +312,7 @@ void IntfsOrch::addSubnetRoute(const Port &port, const IpPrefix &ip_prefix)
attr.value.oid = port.m_rif_id;
attrs.push_back(attr);

sai_status_t status = sai_route_api->create_route_entry(&unicast_route_entry, attrs.size(), attrs.data());
sai_status_t status = sai_route_api->create_route_entry(&unicast_route_entry, (uint32_t)attrs.size(), attrs.data());
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create subnet route to %s from %s, rv:%d",
Expand Down Expand Up @@ -367,7 +367,7 @@ void IntfsOrch::addIp2MeRoute(const IpPrefix &ip_prefix)
attr.value.oid = cpu_port.m_port_id;
attrs.push_back(attr);

sai_status_t status = sai_route_api->create_route_entry(&unicast_route_entry, attrs.size(), attrs.data());
sai_status_t status = sai_route_api->create_route_entry(&unicast_route_entry, (uint32_t)attrs.size(), attrs.data());
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create IP2me route ip:%s, rv:%d", ip_prefix.getIp().to_string().c_str(), status);
Expand Down
4 changes: 2 additions & 2 deletions orchagent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ int main(int argc, char **argv)
attrs.push_back(attr);
}

status = sai_switch_api->create_switch(&gSwitchId, attrs.size(), attrs.data());
status = sai_switch_api->create_switch(&gSwitchId, (uint32_t)attrs.size(), attrs.data());
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create a switch, rv:%d", status);
Expand Down Expand Up @@ -224,7 +224,7 @@ int main(int argc, char **argv)
underlay_intf_attr.value.s32 = SAI_ROUTER_INTERFACE_TYPE_LOOPBACK;
underlay_intf_attrs.push_back(underlay_intf_attr);

status = sai_router_intfs_api->create_router_interface(&gUnderlayIfId, gSwitchId, underlay_intf_attrs.size(), underlay_intf_attrs.data());
status = sai_router_intfs_api->create_router_interface(&gUnderlayIfId, gSwitchId, (uint32_t)underlay_intf_attrs.size(), underlay_intf_attrs.data());
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create underlay router interface %d", status);
Expand Down
4 changes: 2 additions & 2 deletions orchagent/mirrororch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ bool MirrorOrch::activateSession(const string& name, MirrorEntry& session)
// TOS value format is the following:
// DSCP 6 bits | ECN 2 bits
attr.id =SAI_MIRROR_SESSION_ATTR_TOS;
attr.value.u16 = session.dscp << MIRROR_SESSION_DSCP_SHIFT;
attr.value.u16 = (uint16_t)(session.dscp << MIRROR_SESSION_DSCP_SHIFT);
attrs.push_back(attr);

attr.id =SAI_MIRROR_SESSION_ATTR_TTL;
Expand Down Expand Up @@ -452,7 +452,7 @@ bool MirrorOrch::activateSession(const string& name, MirrorEntry& session)

session.status = true;

status = sai_mirror_api->create_mirror_session(&session.sessionId, gSwitchId, attrs.size(), attrs.data());
status = sai_mirror_api->create_mirror_session(&session.sessionId, gSwitchId, (uint32_t)attrs.size(), attrs.data());
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to activate mirroring session %s\n", name.c_str());
Expand Down
2 changes: 1 addition & 1 deletion orchagent/neighorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ bool NeighOrch::addNextHop(IpAddress ipAddress, string alias)
next_hop_attrs.push_back(next_hop_attr);

sai_object_id_t next_hop_id;
sai_status_t status = sai_next_hop_api->create_next_hop(&next_hop_id, gSwitchId, next_hop_attrs.size(), next_hop_attrs.data());
sai_status_t status = sai_next_hop_api->create_next_hop(&next_hop_id, gSwitchId, (uint32_t)next_hop_attrs.size(), next_hop_attrs.data());
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create next hop %s on %s, rv:%d",
Expand Down
6 changes: 3 additions & 3 deletions orchagent/orch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ bool Orch::parseIndexRange(const string &input, sai_uint32_t &range_low, sai_uin
SWSS_LOG_ERROR("malformed index range in:%s. Must contain 2 tokens\n", input.c_str());
return false;
}
range_low = stoul(range_values[0]);
range_high = stoul(range_values[1]);
range_low = (uint32_t)stoul(range_values[0]);
range_high = (uint32_t)stoul(range_values[1]);
if (range_low >= range_high)
{
SWSS_LOG_ERROR("malformed index range in:%s. left value must be less than righ value.\n", input.c_str());
Expand All @@ -346,7 +346,7 @@ bool Orch::parseIndexRange(const string &input, sai_uint32_t &range_low, sai_uin
}
else
{
range_low = range_high = stoul(input);
range_low = range_high = (uint32_t)stoul(input);
}
SWSS_LOG_DEBUG("resulting range:%d-%d", range_low, range_high);
return true;
Expand Down
Loading

0 comments on commit 8f13f8e

Please sign in to comment.