Is this a StrCat bug? (solved)
Hi, need a little help to understand a problem I'm having with this code:
PHP Code:
Quote:
Quote:
Another funny thing is that if I add PHP Code:
Thanks |
Re: Is this a StrCat bug?
I would only expect that to produce garbage data. Why are you concatenating uninitialized strings in the first place, anyway? What are you trying to do?
|
Re: Is this a StrCat bug?
Quote:
The actual code is bigger, but this replicates the problem. I don't want to repeat some of the instructions in ChangeString() if they are already found. |
Re: Is this a StrCat bug?
In first place, what are you trying to do?
|
Re: Is this a StrCat bug?
Quote:
PHP Code:
|
Re: Is this a StrCat bug?
I just didn't want to initialize 'str', so I could know if the function ChangeString was being run by the first time.
Thanks for the help. I thought using 'decl' instead of 'new' was the best way, since strings are arrays. StrCat was the first function that didn't like it that way. Anyway, it's fixed now. The real function is: PHP Code:
|
Re: Is this a StrCat bug?
Change your 'decl' to 'new' in your real source and see if that fixes it.
decl is allocating memory without clearing the contents of it. So random crap could be left in that memory, or it could be untouched memory (empty) new allocates the memory and then empties its contents. 'decl' is just a more "lean" version of 'new' because it doesn't do any work clearing out the contents. Moral of the story, only use 'decl' if you are going to copy your own known values to it. EDIT: You beat me. But I see you have decl String:game[32] = ""; That is equivalent to using 'new' |
Re: Is this a StrCat bug?
Quote:
|
Re: Is this a StrCat bug?
Use static instead of new.
If you declare a variable in a local function with the 'static' initializer then the value will be remembered. The only change you need to make is changing new to static. |
Re: Is this a StrCat bug?
Quote:
decl String:game[32] = ""; sets game[0] to '\0' and the other chars remain garbage (although they'll never get read) and new String:game[32]; sets everything to '\0' EDIT: I'm saying this because you're better off using decl String:string[value] = ""; rather than new when value is rather high. |
All times are GMT -4. The time now is 21:50. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.