[WARNING] strtok limit!!
#1

Hi pawner,

I'm doing this post, for advise all scripter that strtock function, that there is in default server kit includes (gl_common.inc), have limited function.

If we want for example, take a parameter of normal /command, if parameter is longer than 19 characters, strtock SEE ONLY FIRST 19 characters.

This because temp variables on strtock function is smaller: new result[20];

Than i recommend all that if you use gl_common.inc and you want take a long name/parameter (as a PlayerName that is 20 char max now) on your GM, you must change This:

Код:
new result[20];
On for example, this:
Код:
new result[64];
I have seen this problem before creating this post: http://forum.sa-mp.com/index.php?top...1242#msg781242

Quote:
Originally Posted by SoeH
I don't know why....

I have this:

Код:
if (strcmp(cmd, "/changenick", true)==0)
{
	tmp = strtok(cmdtext, idx);
	printf("length: %d",strlen(tmp));
	return 1;
}
If i insert this:



My log say:

Код:
[20:19:32] length: 19
should not be 21?



Good work.
Reply
#2

nice. we had heaps of problems already with this in 0.3 beta's too.
Reply
#3

Quote:
Originally Posted by uncle_nutsy
nice. we had heaps of problems already with this in 0.3 beta's too.
Yes, All my topic are 0.3 bug , look my Signature.
Reply
#4

Quote:
Originally Posted by Y_Leѕѕ
Firsly - strtok has ALWAYS had a limit, and if you don't like it then it's in an open source library, so just change it.

Secondly - use sscanf!
Strtok has ALWAYS had a limit? YES THIS WAS MINE:
-------------------------------------
stock strtok(const string[], &index)
{
new length = strlen(string);
while ((index < length) && (string[index] <= ' '))
{
index++;
}
new offset = index;
new result[128];
while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
return result;
}
--------------------------------------
And I'd never changed. But this is other....


I think that all joung nub scripter can't change the libraries. And than:
For me, to have a default lower limit to the maximum limit of characters of a PlayerName is ridiculous.

Reply
#5

Give strtok a peace, start using sscanf.

I don't know why people still use strok (and strcmp for commands) while we have much better solustions such as sscanf (and zcmd for commands); it's like oyu would still prefer SA:MP 0.1b while we have 0.3a.
Reply
#6

Quote:
Originally Posted by $ЂЯĢ
Give strtok a peace, start using sscanf.

I don't know why people still use strok (and strcmp for commands) while we have much better solustions such as sscanf (and zcmd for commands); it's like oyu would still prefer SA:MP 0.1b while we have 0.3a.
Ahahahahahah
My GM have 30 000 lines, do you want traslate in zcmd or scanf etc...?
Reply
#7

Quote:
Originally Posted by SoeH
Quote:
Originally Posted by $ЂЯĢ
Give strtok a peace, start using sscanf.

I don't know why people still use strok (and strcmp for commands) while we have much better solustions such as sscanf (and zcmd for commands); it's like oyu would still prefer SA:MP 0.1b while we have 0.3a.
Ahahahahahah
My GM have 30 000 lines, do you want traslate in zcmd or scanf etc...?
Holy shit. That is your task #1 then.
Reply
#8

Quote:
Originally Posted by $ЂЯĢ
Quote:
Originally Posted by SoeH
Quote:
Originally Posted by $ЂЯĢ
Give strtok a peace, start using sscanf.

I don't know why people still use strok (and strcmp for commands) while we have much better solustions such as sscanf (and zcmd for commands); it's like oyu would still prefer SA:MP 0.1b while we have 0.3a.
Ahahahahahah
My GM have 30 000 lines, do you want traslate in zcmd or scanf etc...?
Holy shit. That is your task #1 then.
"Holy shit" ASUDHUAEHDUAHUDAHUDHEUHSDUHUDHSUHDUHHE
However my task #1 is traslate on BD MySQL for now.
Reply
#9

Your server will use like 100x less resources and your code will be 200x times more efficient if you take a single hour or two and convert the whole server from strtok to dcmd.
Reply
#10

I think that of course something will be faster, but not exaggerate.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)