Wiznet / ioLibrary_Driver

ioLibrary_Driver can be used for the application design of WIZnet TCP/IP chips as W5500, W5300, W5200, W5100 W5100S.
MIT License
603 stars 331 forks source link

socket.c no SOCKERR_SOCKNUM on invalid socket number #84

Open edwin-oetelaar opened 5 years ago

edwin-oetelaar commented 5 years ago

The macro is incorrect.

Suppose we have a W5500 with 8 sockets ... these are numbered 0..7

8 is not a valid socket number.. This macro does not respect this, it does not return SOCKERR_SOCKNUM on an invalid socket number.


#define CHECK_SOCKNUM()   \
   do{                    \
      if(sn > _WIZCHIP_SOCK_NUM_) return SOCKERR_SOCKNUM;   \
   }while(0);             \

I personally find all this way of coding (macros which assume parameters to be named a certain way, like sn) very ugly and I am rewriting all wiznet code for my own project into clean C code.

Here is a quick fix, just as ugly

#define CHECK_SOCKNUM()   do{ if(!(sn < _WIZCHIP_SOCK_NUM_)) return SOCKERR_SOCKNUM;  } while(0);   
KoynovStas commented 4 years ago

I think a more visual and easy way is to use >=

#define CHECK_SOCKNUM()   \
   do{                    \
      if(sn >= _WIZCHIP_SOCK_NUM_) return SOCKERR_SOCKNUM;   \
   }while(0);             \