[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Development
. . -> [Subject]  lua gen_inputbox message length check order
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

lua gen_inputbox message length check order

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


Posted by Fiendish   USA  (1,641 posts)  [Biography] 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
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] 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
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] 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
[Go to top] top

Posted by Fiendish   USA  (1,641 posts)  [Biography] 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
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] 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
[Go to top] 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.


4,991 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]