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

Gammon Software Solutions 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

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by Fiendish   USA  (849 posts)  [Biography] bio   Global Moderator
Date Sat 30 Apr 2011 11:51 PM (UTC)  quote  ]
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.

http://aardwolfclientpackage.googlecode.com/
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sun 01 May 2011 12:10 AM (UTC)  quote  ]
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,229 posts)  [Biography] bio
Date Reply #2 on Sun 01 May 2011 12:44 AM (UTC)  quote  ]
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  (849 posts)  [Biography] bio   Global Moderator
Date Reply #3 on Sun 01 May 2011 12:46 AM (UTC)  quote  ]
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

http://aardwolfclientpackage.googlecode.com/
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Sun 01 May 2011 06:23 AM (UTC)  quote  ]
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.


1,177 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]