Skip to content

Commit

Permalink
Merge pull request OpenEtherCATsociety#347 from jjguti/master
Browse files Browse the repository at this point in the history
fix warning with strncpy on newer GCC's
  • Loading branch information
hefloryd authored Oct 21, 2019
2 parents 09d48ac + cffd3ba commit f8b0029
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 47 deletions.
14 changes: 4 additions & 10 deletions oshw/linux/oshw.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ uint16 oshw_ntohs(uint16 network)
ec_adaptert * oshw_find_adapters(void)
{
int i;
int string_len;
struct if_nameindex *ids;
ec_adaptert * adapter;
ec_adaptert * prev_adapter;
Expand Down Expand Up @@ -75,15 +74,10 @@ ec_adaptert * oshw_find_adapters(void)

if (ids[i].if_name)
{
string_len = strlen(ids[i].if_name);
if (string_len > (EC_MAXLEN_ADAPTERNAME - 1))
{
string_len = EC_MAXLEN_ADAPTERNAME - 1;
}
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';
strncpy(adapter->name, ids[i].if_name, EC_MAXLEN_ADAPTERNAME);
adapter->name[EC_MAXLEN_ADAPTERNAME-1] = '\0';
strncpy(adapter->desc, ids[i].if_name, EC_MAXLEN_ADAPTERNAME);
adapter->desc[EC_MAXLEN_ADAPTERNAME-1] = '\0';
}
else
{
Expand Down
16 changes: 5 additions & 11 deletions oshw/macosx/oshw.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ uint16 oshw_ntohs(uint16 network)
ec_adaptert * oshw_find_adapters(void)
{
int i;
int string_len;
struct if_nameindex *ids;
ec_adaptert * adapter;
ec_adaptert * prev_adapter;
Expand Down Expand Up @@ -70,20 +69,15 @@ ec_adaptert * oshw_find_adapters(void)
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;

if (ids[i].if_name)
{
string_len = strlen(ids[i].if_name);
if (string_len > (EC_MAXLEN_ADAPTERNAME - 1))
{
string_len = EC_MAXLEN_ADAPTERNAME - 1;
}
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';
strncpy(adapter->name, ids[i].if_name, EC_MAXLEN_ADAPTERNAME);
adapter->name[EC_MAXLEN_ADAPTERNAME-1] = '\0';
strncpy(adapter->desc, ids[i].if_name, EC_MAXLEN_ADAPTERNAME);
adapter->desc[EC_MAXLEN_ADAPTERNAME-1] = '\0';
}
else
{
Expand Down
16 changes: 5 additions & 11 deletions oshw/rtems/oshw.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ uint16 oshw_ntohs(uint16 network)
ec_adaptert * oshw_find_adapters(void)
{
int i;
int string_len;
struct if_nameindex *ids;
ec_adaptert * adapter;
ec_adaptert * prev_adapter;
Expand Down Expand Up @@ -70,20 +69,15 @@ ec_adaptert * oshw_find_adapters(void)
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;

if (ids[i].if_name)
{
string_len = strlen(ids[i].if_name);
if (string_len > (EC_MAXLEN_ADAPTERNAME - 1))
{
string_len = EC_MAXLEN_ADAPTERNAME - 1;
}
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';
strncpy(adapter->name, ids[i].if_name, EC_MAXLEN_ADAPTERNAME);
adapter->name[EC_MAXLEN_ADAPTERNAME-1] = '\0';
strncpy(adapter->desc, ids[i].if_name, EC_MAXLEN_ADAPTERNAME);
adapter->desc[EC_MAXLEN_ADAPTERNAME-1] = '\0';
}
else
{
Expand Down
19 changes: 4 additions & 15 deletions oshw/win32/oshw.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ ec_adaptert * oshw_find_adapters (void)
ec_adaptert * prev_adapter;
ec_adaptert * ret_adapter = NULL;
char errbuf[PCAP_ERRBUF_SIZE];
size_t string_len;

/* find all devices */
if (pcap_findalldevs(&alldevs, errbuf) == -1)
Expand Down Expand Up @@ -73,27 +72,17 @@ ec_adaptert * oshw_find_adapters (void)
adapter->next = NULL;
if (d->name)
{
string_len = strlen(d->name);
if (string_len > (EC_MAXLEN_ADAPTERNAME - 1))
{
string_len = EC_MAXLEN_ADAPTERNAME - 1;
}
strncpy(adapter->name, d->name,string_len);
adapter->name[string_len] = '\0';
strncpy(adapter->name, d->name, EC_MAXLEN_ADAPTERNAME);
adapter->name[EC_MAXLEN_ADAPTERNAME-1] = '\0';
}
else
{
adapter->name[0] = '\0';
}
if (d->description)
{
string_len = strlen(d->description);
if (string_len > (EC_MAXLEN_ADAPTERNAME - 1))
{
string_len = EC_MAXLEN_ADAPTERNAME - 1;
}
strncpy(adapter->desc, d->description,string_len);
adapter->desc[string_len] = '\0';
strncpy(adapter->desc, d->description, EC_MAXLEN_ADAPTERNAME);
adapter->desc[EC_MAXLEN_ADAPTERNAME-1] = '\0';
}
else
{
Expand Down

0 comments on commit f8b0029

Please sign in to comment.