fix warning with strncpy on newer GCC versions
strncpy should not be called with a "length" parameter which is based on the source string since it negates the benefits of using strncpy. this patch fixes the warning for linux, macosx and rtems Fixes #346 Change-Id: Ib2fb7637e9845545e4c15045e6be7c7ce8e0672b
This commit is contained in:
parent
09d48acc32
commit
cffd3ba283
@ -42,7 +42,6 @@ uint16 oshw_ntohs(uint16 network)
|
|||||||
ec_adaptert * oshw_find_adapters(void)
|
ec_adaptert * oshw_find_adapters(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int string_len;
|
|
||||||
struct if_nameindex *ids;
|
struct if_nameindex *ids;
|
||||||
ec_adaptert * adapter;
|
ec_adaptert * adapter;
|
||||||
ec_adaptert * prev_adapter;
|
ec_adaptert * prev_adapter;
|
||||||
@ -75,15 +74,10 @@ ec_adaptert * oshw_find_adapters(void)
|
|||||||
|
|
||||||
if (ids[i].if_name)
|
if (ids[i].if_name)
|
||||||
{
|
{
|
||||||
string_len = strlen(ids[i].if_name);
|
strncpy(adapter->name, ids[i].if_name, EC_MAXLEN_ADAPTERNAME);
|
||||||
if (string_len > (EC_MAXLEN_ADAPTERNAME - 1))
|
adapter->name[EC_MAXLEN_ADAPTERNAME-1] = '\0';
|
||||||
{
|
strncpy(adapter->desc, ids[i].if_name, EC_MAXLEN_ADAPTERNAME);
|
||||||
string_len = EC_MAXLEN_ADAPTERNAME - 1;
|
adapter->desc[EC_MAXLEN_ADAPTERNAME-1] = '\0';
|
||||||
}
|
|
||||||
strncpy(adapter->name, ids[i].if_name,string_len);
|
|
||||||
adapter->name[string_len] = '\0';
|
|
||||||
strncpy(adapter->desc, ids[i].if_name,string_len);
|
|
||||||
adapter->desc[string_len] = '\0';
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -42,7 +42,6 @@ uint16 oshw_ntohs(uint16 network)
|
|||||||
ec_adaptert * oshw_find_adapters(void)
|
ec_adaptert * oshw_find_adapters(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int string_len;
|
|
||||||
struct if_nameindex *ids;
|
struct if_nameindex *ids;
|
||||||
ec_adaptert * adapter;
|
ec_adaptert * adapter;
|
||||||
ec_adaptert * prev_adapter;
|
ec_adaptert * prev_adapter;
|
||||||
@ -70,20 +69,15 @@ ec_adaptert * oshw_find_adapters(void)
|
|||||||
ret_adapter = adapter;
|
ret_adapter = adapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fetch description and name, in Linux we use the same on both */
|
/* fetch description and name, in macosx we use the same on both */
|
||||||
adapter->next = NULL;
|
adapter->next = NULL;
|
||||||
|
|
||||||
if (ids[i].if_name)
|
if (ids[i].if_name)
|
||||||
{
|
{
|
||||||
string_len = strlen(ids[i].if_name);
|
strncpy(adapter->name, ids[i].if_name, EC_MAXLEN_ADAPTERNAME);
|
||||||
if (string_len > (EC_MAXLEN_ADAPTERNAME - 1))
|
adapter->name[EC_MAXLEN_ADAPTERNAME-1] = '\0';
|
||||||
{
|
strncpy(adapter->desc, ids[i].if_name, EC_MAXLEN_ADAPTERNAME);
|
||||||
string_len = EC_MAXLEN_ADAPTERNAME - 1;
|
adapter->desc[EC_MAXLEN_ADAPTERNAME-1] = '\0';
|
||||||
}
|
|
||||||
strncpy(adapter->name, ids[i].if_name,string_len);
|
|
||||||
adapter->name[string_len] = '\0';
|
|
||||||
strncpy(adapter->desc, ids[i].if_name,string_len);
|
|
||||||
adapter->desc[string_len] = '\0';
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -42,7 +42,6 @@ uint16 oshw_ntohs(uint16 network)
|
|||||||
ec_adaptert * oshw_find_adapters(void)
|
ec_adaptert * oshw_find_adapters(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int string_len;
|
|
||||||
struct if_nameindex *ids;
|
struct if_nameindex *ids;
|
||||||
ec_adaptert * adapter;
|
ec_adaptert * adapter;
|
||||||
ec_adaptert * prev_adapter;
|
ec_adaptert * prev_adapter;
|
||||||
@ -70,20 +69,15 @@ ec_adaptert * oshw_find_adapters(void)
|
|||||||
ret_adapter = adapter;
|
ret_adapter = adapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fetch description and name, in Linux we use the same on both */
|
/* fetch description and name, in rtems we use the same on both */
|
||||||
adapter->next = NULL;
|
adapter->next = NULL;
|
||||||
|
|
||||||
if (ids[i].if_name)
|
if (ids[i].if_name)
|
||||||
{
|
{
|
||||||
string_len = strlen(ids[i].if_name);
|
strncpy(adapter->name, ids[i].if_name, EC_MAXLEN_ADAPTERNAME);
|
||||||
if (string_len > (EC_MAXLEN_ADAPTERNAME - 1))
|
adapter->name[EC_MAXLEN_ADAPTERNAME-1] = '\0';
|
||||||
{
|
strncpy(adapter->desc, ids[i].if_name, EC_MAXLEN_ADAPTERNAME);
|
||||||
string_len = EC_MAXLEN_ADAPTERNAME - 1;
|
adapter->desc[EC_MAXLEN_ADAPTERNAME-1] = '\0';
|
||||||
}
|
|
||||||
strncpy(adapter->name, ids[i].if_name,string_len);
|
|
||||||
adapter->name[string_len] = '\0';
|
|
||||||
strncpy(adapter->desc, ids[i].if_name,string_len);
|
|
||||||
adapter->desc[string_len] = '\0';
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -42,7 +42,6 @@ ec_adaptert * oshw_find_adapters (void)
|
|||||||
ec_adaptert * prev_adapter;
|
ec_adaptert * prev_adapter;
|
||||||
ec_adaptert * ret_adapter = NULL;
|
ec_adaptert * ret_adapter = NULL;
|
||||||
char errbuf[PCAP_ERRBUF_SIZE];
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
size_t string_len;
|
|
||||||
|
|
||||||
/* find all devices */
|
/* find all devices */
|
||||||
if (pcap_findalldevs(&alldevs, errbuf) == -1)
|
if (pcap_findalldevs(&alldevs, errbuf) == -1)
|
||||||
@ -73,13 +72,8 @@ ec_adaptert * oshw_find_adapters (void)
|
|||||||
adapter->next = NULL;
|
adapter->next = NULL;
|
||||||
if (d->name)
|
if (d->name)
|
||||||
{
|
{
|
||||||
string_len = strlen(d->name);
|
strncpy(adapter->name, d->name, EC_MAXLEN_ADAPTERNAME);
|
||||||
if (string_len > (EC_MAXLEN_ADAPTERNAME - 1))
|
adapter->name[EC_MAXLEN_ADAPTERNAME-1] = '\0';
|
||||||
{
|
|
||||||
string_len = EC_MAXLEN_ADAPTERNAME - 1;
|
|
||||||
}
|
|
||||||
strncpy(adapter->name, d->name,string_len);
|
|
||||||
adapter->name[string_len] = '\0';
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -87,13 +81,8 @@ ec_adaptert * oshw_find_adapters (void)
|
|||||||
}
|
}
|
||||||
if (d->description)
|
if (d->description)
|
||||||
{
|
{
|
||||||
string_len = strlen(d->description);
|
strncpy(adapter->desc, d->description, EC_MAXLEN_ADAPTERNAME);
|
||||||
if (string_len > (EC_MAXLEN_ADAPTERNAME - 1))
|
adapter->desc[EC_MAXLEN_ADAPTERNAME-1] = '\0';
|
||||||
{
|
|
||||||
string_len = EC_MAXLEN_ADAPTERNAME - 1;
|
|
||||||
}
|
|
||||||
strncpy(adapter->desc, d->description,string_len);
|
|
||||||
adapter->desc[string_len] = '\0';
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user