SA-MP Forums Archive
strmid has a bug - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: strmid has a bug (/showthread.php?tid=581933)



strmid has a bug [Solved] - liquor - 16.07.2015

pawn Код:
new DEBUG[10],ABC[3],DEF[3];
format(DEBUG,10,"ABCDEF");
strmid(ABC,DEBUG,0,2);
strmid(DEF,DEBUG,3,5);
printf("Should be ABC: '%s'\nShould be DEF: '%s'",ABC,DEF);
Output is:

Код:
Should be ABC: 'AB'
Should be DEF: 'DE'
Any solutions to this? It worked fine the first time i tested it, but after a server restart it got like this...


Re: strmid has a bug - Vince - 16.07.2015

You are not including the space required for the null terminator, which results in stack overflow. The arrays "ABC" and "DEF" should each be 4 cells wide to hold a string of length 3 + null terminator.

On another note, don't write variable names in all caps. By convention, all caps is reserved for constants (#define and const).


Re: strmid has a bug - liquor - 16.07.2015

Quote:
Originally Posted by Vince
Посмотреть сообщение
You are not including the space required for the null terminator, which results in stack overflow. The arrays "ABC" and "DEF" should each be 4 cells wide to hold a string of length 3 + null terminator.

On another note, don't write variable names in all caps. By convention, all caps is reserved for constants (#define and const).
I know all that, i just threw this together and put it inside main() to see whether it was interfered by whatever I'm doing. Yeah, forgot about the null char, but the array size doesn't matter, the result remains the same.... (just tested)


Re: strmid has a bug - liquor - 16.07.2015

I got it working, got help via PM. I never thought about including the null char in the strmid 'end' :P