@@ -352,7 +352,11 @@ int ec_coe_sdo_read(ec_t *pec, osal_uint16_t slave, osal_uint16_t index,
352352 assert (pec != NULL );
353353 assert (buf != NULL );
354354 assert (len != NULL );
355- assert (slave < pec -> slave_cnt );
355+
356+ if (slave >= pec -> slave_cnt )
357+ {
358+ return EC_ERROR_SLAVE_NOT_FOUND ;
359+ }
356360
357361 pool_entry_t * p_entry = NULL ;
358362 int ret = EC_ERROR_MAILBOX_TIMEOUT ;
@@ -470,7 +474,11 @@ static int ec_coe_sdo_write_expedited(ec_t *pec, osal_uint16_t slave, osal_uint1
470474{
471475 assert (pec != NULL );
472476 assert (buf != NULL );
473- assert (slave < pec -> slave_cnt );
477+
478+ if (slave >= pec -> slave_cnt )
479+ {
480+ return EC_ERROR_SLAVE_NOT_FOUND ;
481+ }
474482
475483 pool_entry_t * p_entry = NULL ;
476484 int ret = EC_ERROR_MAILBOX_TIMEOUT ;
@@ -566,7 +574,11 @@ static int ec_coe_sdo_write_normal(ec_t *pec, osal_uint16_t slave, osal_uint16_t
566574{
567575 assert (pec != NULL );
568576 assert (buf != NULL );
569- assert (slave < pec -> slave_cnt );
577+
578+ if (slave >= pec -> slave_cnt )
579+ {
580+ return EC_ERROR_SLAVE_NOT_FOUND ;
581+ }
570582
571583 pool_entry_t * p_entry = NULL ;
572584 int ret = EC_ERROR_MAILBOX_TIMEOUT ;
@@ -787,7 +799,11 @@ int ec_coe_odlist_read(ec_t *pec, osal_uint16_t slave, osal_uint8_t *buf, osal_s
787799 assert (pec != NULL );
788800 assert (buf != NULL );
789801 assert (len != NULL );
790- assert (slave < pec -> slave_cnt );
802+
803+ if (slave >= pec -> slave_cnt )
804+ {
805+ return EC_ERROR_SLAVE_NOT_FOUND ;
806+ }
791807
792808 pool_entry_t * p_entry = NULL ;
793809 int ret = EC_OK ;
@@ -904,7 +920,11 @@ int ec_coe_sdo_desc_read(ec_t *pec, osal_uint16_t slave, osal_uint16_t index,
904920 ec_coe_sdo_desc_t * desc , osal_uint32_t * error_code ) {
905921 assert (pec != NULL );
906922 assert (desc != NULL );
907- assert (slave < pec -> slave_cnt );
923+
924+ if (slave >= pec -> slave_cnt )
925+ {
926+ return EC_ERROR_SLAVE_NOT_FOUND ;
927+ }
908928
909929 pool_entry_t * p_entry = NULL ;
910930 int ret = EC_OK ;
@@ -1026,7 +1046,11 @@ int ec_coe_sdo_entry_desc_read(ec_t *pec, osal_uint16_t slave, osal_uint16_t ind
10261046{
10271047 assert (pec != NULL );
10281048 assert (desc != NULL );
1029- assert (slave < pec -> slave_cnt );
1049+
1050+ if (slave >= pec -> slave_cnt )
1051+ {
1052+ return EC_ERROR_SLAVE_NOT_FOUND ;
1053+ }
10301054
10311055 pool_entry_t * p_entry = NULL ;
10321056 int ret = EC_ERROR_MAILBOX_READ ;
@@ -1125,7 +1149,11 @@ int ec_coe_sdo_entry_desc_read(ec_t *pec, osal_uint16_t slave, osal_uint16_t ind
11251149
11261150int ec_coe_generate_mapping (ec_t * pec , osal_uint16_t slave ) {
11271151 assert (pec != NULL );
1128- assert (slave < pec -> slave_cnt );
1152+
1153+ if (slave >= pec -> slave_cnt )
1154+ {
1155+ return EC_ERROR_SLAVE_NOT_FOUND ;
1156+ }
11291157
11301158 int ret = EC_ERROR_MAILBOX_TIMEOUT ;
11311159 osal_uint8_t * buf = NULL ;
@@ -1311,9 +1339,13 @@ void ec_coe_emergency_enqueue(ec_t *pec, osal_uint16_t slave, pool_entry_t *p_en
13111339 */
13121340int ec_coe_emergency_get_next (ec_t * pec , osal_uint16_t slave , ec_coe_emergency_message_t * msg ) {
13131341 assert (pec != NULL );
1314- assert (slave < pec -> slave_cnt );
13151342 assert (msg != NULL );
13161343
1344+ if (slave >= pec -> slave_cnt )
1345+ {
1346+ return EC_ERROR_SLAVE_NOT_FOUND ;
1347+ }
1348+
13171349 ec_slave_ptr (slv , pec , slave );
13181350 int ret = EC_ERROR_UNAVAILABLE ;
13191351
0 commit comments