|
lua gen_inputbox message length check order
|
Reply to this subject
Start a new subject
 
Refresh page
| Posted by |
Fiendish
USA (849 posts) 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/ | top |
|
| Posted by |
Nick Gammon
Australia (18,772 posts) 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 | top |
|
| Posted by |
Twisol
USA (2,229 posts) 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 | top |
|
| Posted by |
Fiendish
USA (849 posts) 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/ | top |
|
| Posted by |
Nick Gammon
Australia (18,772 posts) bio
Forum Administrator |
| Date |
Reply #4 on Sun 01 May 2011 06:23 AM (UTC) [ quote
] |
| Message |
|
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,179 views.
Reply to this subject
Start a new subject
 
Refresh page
top
Comments to:
Gammon Software support
Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )