Squirrel print() function crashes when printing >514 chars

vcmptr

  • Jr. Member
  • This user novice scripter.
  • Posts: 60
Squirrel print() function crashes when printing >514 chars
« on March 6th, 2015, 09:50 PM »Last edited on April 17th, 2015, 10:47 PM by stormeus
If print() length greater than 514 characters server crashes.
I have try this:
Code: [Select]
print("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eie");
My English is not good.

.

  • VC:MP Beta Tester
  • .
  • Posts: 1,807
Re: Print Function
« Reply #1, on March 6th, 2015, 10:34 PM »Last edited on March 7th, 2015, 03:47 AM
Aah yes, the internal implementation of that isn't very pretty and the initial buffer is set to 512 characters. Probably something goes wrong when resizing that buffer to adjust for the new size. I'd suggest std::vector<char> buffer; instead of malloc(); in that implementation. Makes things more easy to control and upon failed resize(); that vector reacts much better :)

At least when that vector fails to resize you can react to that and still keep the old incomplete string instead of a crash. But I might be wrong and there's something else causing the problems here. Anyway, I don't plan on bothering about it. If you need a 512+ characters message then you're doing something wrong :P
.

Kratos_

  • Jr. Member
  • Mutaros Apotheoses
  • Posts: 86
In the middle of chaos , lies opportunity.

vcmptr

  • Jr. Member
  • This user novice scripter.
  • Posts: 60
Re: Print Function
« Reply #3, on March 7th, 2015, 08:27 AM »
Yes I need 512 characters for errors. I'm using this. In some cases errors can be longer than 512 characters.
My English is not good.

MacTavish

  • Hero Member
  • Nicks( Kusanagi, Beztone, RATHORE )
  • Posts: 809
Re: Print Function
« Reply #4, on March 7th, 2015, 10:02 AM »
I am not sure it can be done or not its just and Idea. If error is big more than 512 chars then why dont you try to joint double print

I don't know how to make code. its an example

Code: [Select]
if ( error.len () >= 1024)
{
print( 512 error chars here ); print( and 512 error chars here );
}
else print ( if less then 512 chars here );

I really dont know it can be done or not But maybe you guys can make it

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

.

  • VC:MP Beta Tester
  • .
  • Posts: 1,807
Re: Print Function
« Reply #5, on March 7th, 2015, 10:09 AM »Last edited on March 7th, 2015, 10:11 AM
Quote from Beztone on March 7th, 2015, 10:02 AM
I really dont know it can be done or not But maybe you guys can make it
Truth is you can't really control or know the final size of a printf message. Also the reason why the internal implementation also has to do some tricks to adjust in case the initial buffer size is small. On your side however, you know the size of the strings that you'll format since I'm imagining that those are quite big. And you could format them in segments then add them all in one big string. However, my advice is that you shouldn't complicate your self too much because this bug will eventually get fixed. And shouldn't be too hard to fix it. I'm too lazy right now to bother making a pull request :D
.

Sk

  • Jr. Member
  • Posts: 67
Re: Print Function
« Reply #6, on March 7th, 2015, 03:37 PM »
string.slice(starting_point,ending_point);
can do the job + you will need to add some checks about size and about slicing the text but i guess its better to wait for devs to fix it.

vcmptr

  • Jr. Member
  • This user novice scripter.
  • Posts: 60
Re: Print Function
« Reply #7, on March 7th, 2015, 05:19 PM »Last edited on March 14th, 2015, 04:12 PM
Thank you S.L.C, Kratos, Gudio and Sk. :) And Beztone.
 I will wait fix.
My English is not good.

MacTavish

  • Hero Member
  • Nicks( Kusanagi, Beztone, RATHORE )
  • Posts: 809

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

vcmptr

  • Jr. Member
  • This user novice scripter.
  • Posts: 60
My English is not good.