Assume that you send X ERC20 SomeCoins and in exchange, you receive X/2 MyCoins. Both ERC20 have 4 decimals. My question is, if the user sends the minimum value or, a value that can't be divided by 2, will that result in an underflow attack?
For example, user sends 0.0001 SomeCoins which if you divide by 2, your smartcontract should return them 0.00005 MyCoins
Another scenario is when you return X/3 MyCoins. For example, user sends 1.0000 SomeCoins and your smart contract should return them 1/3 MyCoins, or 0.33333333333333333
Does an underflow attack happen in any of these cases? If yes, is there a way to avoid it? Would OpenZeppelin's safeMath function allow me to mitigate it?