5
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.

6

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.

| improve this answer | |
  • 1
    So I can tell my client to limit memberName say to10 it is safe otherwise it might cause some problems. – e.k Mar 6 '18 at 7:34
  • 1
    You could do that, but the benefit is questionable. You would need to hand over a really, really, really long string to break the code by reaching the gas limit. Even if someone manages to accomplish that, nothing bad would happen. The code will just never be executed and the transaction will be stated as "failed". If you want to check the strings' length, you can do it directly inside the function: require(memberName.length <= 10); – Fabian Iwanecki Mar 6 '18 at 7:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.