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

2 Answers 2

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.

2
  • 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, 2018 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); Mar 6, 2018 at 7:38
1

I am getting the same warning even with a pure function using fixed length arguments. Here is the code:

function sumar(int a, int b) public pure returns (int) {
    return a+b;
}

Any ideas?
(Using current version of Remix, compiler version 0.8.13)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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