Skip to content

Commit

Permalink
Fix potential bug when the number of slaves is too large
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikael Heden committed Feb 17, 2016
1 parent 1654afc commit eac0acd
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion soem/ethercatconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,17 @@ int ecx_detect_slaves(ecx_contextt *context)
wkc = ecx_BRD(context->port, 0x0000, ECT_REG_TYPE, sizeof(w), &w, EC_TIMEOUTSAFE); /* detect number of slaves */
if (wkc > 0)
{
*(context->slavecount) = wkc;
/* this is strictly "less than" since the master is "slave 0" */
if (wkc < EC_MAXSLAVE)
{
*(context->slavecount) = wkc;
}
else
{
EC_PRINT("Error: too many slaves on network: num_slaves=%d, EC_MAXSLAVE=%d\n",
wkc, EC_MAXSLAVE);
return -2;
}
}
return wkc;
}
Expand Down

0 comments on commit eac0acd

Please sign in to comment.