Solidity Gas Requirement – Understanding Infinite Gas in Functions

mappingremixsolidity

struct userData{
     uint val;
     bool isvalue;
     string name;
}



mapping(uint => address) internal users;
mapping(address => userData) internal bidirectionalUsers;

function addMember(address newMember, string memberName) public{

        if (msg.sender != owner) return;

        if (bidirectionalUsers[newMember].isvalue) return;

        users[memberCount] = newMember;
        bidirectionalUsers[newMember] = userData(memberCount,true,memberName);

    }

Above code is throwing warning in addMember(), gas limit is high:infinite and it can not be executed.

I commented all the lines inside the function but still it throws this warning. What I'm doing wrong here? Can somebody help me in this. Thank you.

Best Answer

You can safely ignore this warning. The problem is your string variable in the parameters string memberName. Because a string has no fixed size, it is theoretically possible to require an infinite amount of gas to fill it with an infinite amount of characters.

Your code will still compile and work if no other errors are being shown.

Related Topic