Ethereum wiki shows this example function:
14 // Transfer the balance from owner's account to another account
15 function transfer(address _to, uint256 _amount) returns (bool success) {
16 if (balances[msg.sender] >= _amount
17 && _amount > 0
18 && balances[_to] + _amount > balances[_to]) {
19 balances[msg.sender] -= _amount;
20 balances[_to] += _amount;
21 return true;
22 } else {
23 return false;
24 }
25 }
Notice that there are two checks here: _amount > 0 and balances[_to] + _amount > balances[_to]. I understand these two are for preventing the integer overflow attack.
But isn't the balances[_to] + _amount > balances[_to] check enough? Can we remove the _amount > 0 check?
balances[_to] + _amount > balances[_to]already can handle this 0-value scenario._amount > 0is not necessary and adds gas costs. Agree? – user10375 Dec 28 '17 at 01:58