Fix potential bug when the number of slaves is too large

This commit is contained in:
Mikael Heden 2015-12-18 14:39:28 +01:00
parent 1654afc75f
commit eac0acd809
1 changed files with 11 additions and 1 deletions

View File

@ -175,9 +175,19 @@ int ecx_detect_slaves(ecx_contextt *context)
ecx_BWR(context->port, 0x0000, ECT_REG_ALCTL, sizeof(b), &b, EC_TIMEOUTRET3); /* Reset all slaves to Init */
wkc = ecx_BRD(context->port, 0x0000, ECT_REG_TYPE, sizeof(w), &w, EC_TIMEOUTSAFE); /* detect number of slaves */
if (wkc > 0)
{
/* 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;
}