Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Development ➜ lua gen_inputbox message length check order

lua gen_inputbox message length check order

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Fiendish   USA  (2,537 posts)  Bio   Global Moderator
Date Sat 30 Apr 2011 11:51 PM (UTC)
Message
I was looking through scripting/lua_utils.cpp and saw this in gen_inputbox


  // if we leave in & it will make the next letter underlined
  string sInputMsg = FindAndReplace (inputmsg, "&", "&&");

  if (sInputMsg.length () > 1000)
     luaL_error (L, "inputbox message too long (max 1000 characters)");


Unless I'm misinterpreting the "&" comment, that length check seems like it should come before the FindAndReplace.

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #1 on Sun 01 May 2011 12:10 AM (UTC)
Message
I suppose it depends *which* string we are applying the restraint to. In any case from memory the 1000 is just the Sanity Clause.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #2 on Sun 01 May 2011 12:44 AM (UTC)
Message
It doesn't exactly represent the intent of the code very well, though. It either wants to limit the memory used by the string, or the amount of information seen on-screen. The former doesn't make too much sense (it's a fairly transient string, and the memory's already there when you check the length), so the latter seems to be right.

However, the &-escaping causes the string to expand, without changing the amount of data actually visible on-screen. If you have no &'s in your message you can fit 1000 characters, but with two &'s you're down to 998 for no immediately obvious reason. At the most ridiculous end, a string composed only of &'s can only be 500 characters long.

If the check came first, the visible data is always limited to 1000 characters. No surprises, clearer code.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Fiendish   USA  (2,537 posts)  Bio   Global Moderator
Date Reply #3 on Sun 01 May 2011 12:46 AM (UTC)
Message
The documentation for utils.msgbox says:

Quote:
message to display (max 1000 characters)


The simplest change is obviously to make it say

Quote:
message to display (max 1000 minus the number of ampersands characters)


:D

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #4 on Sun 01 May 2011 06:23 AM (UTC)
Message
http://github.com/nickgammon/mushclient/commit/97888a35f3

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


21,643 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.