Vice City: Multiplayer

VC:MP Discussion => Bugs and Crashes => Support => Acknowledged Bug Reports => Topic started by: vcmptr on Mar 06, 2015, 09:50 PM

Title: Squirrel print() function crashes when printing >514 chars
Post by: vcmptr on Mar 06, 2015, 09:50 PM
If print() length greater than 514 characters server crashes.
I have try this:
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");
Title: Re: Print Function
Post by: . on Mar 06, 2015, 10:34 PM
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
Title: Re: Print Function
Post by: Kratos_ on Mar 07, 2015, 03:39 AM

Quote from: S.L.C on Mar 06, 2015, 10:34 PMIf you need a 512+ characters message then you're doing something wrong
Title: Re: Print Function
Post by: vcmptr on Mar 07, 2015, 08:27 AM
Yes I need 512 characters for errors. I'm using this (http://forum.vc-mp.org/?topic=316.0). In some cases errors can be longer than 512 characters.
Title: Re: Print Function
Post by: MacTavish on Mar 07, 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

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
Title: Re: Print Function
Post by: . on Mar 07, 2015, 10:09 AM
Quote from: Beztone on Mar 07, 2015, 10:02 AMI 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
Title: Re: Print Function
Post by: Sk on Mar 07, 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.
Title: Re: Print Function
Post by: vcmptr on Mar 07, 2015, 05:19 PM
Thank you S.L.C, Kratos, Gudio and Sk. :) And Beztone. (http://www.en.kolobok.us/smiles/big_standart/sorry.gif)
 I will wait fix.
Title: Re: Print Function
Post by: MacTavish on Mar 07, 2015, 05:21 PM
Quote from: vcmptr on Mar 07, 2015, 05:19 PMThank you S.L.C, Kratos, Gudio and Sk. :) I will wait fix.

Where is He ???
Title: Re: Squirrel print() function crashes when printing >514 chars
Post by: vcmptr on May 06, 2015, 02:53 AM
@stormeus  It's still crashing server.