Raised This Month: $51 Target: $400
 12% 

Solved [Q] About Dynamic Array Size char, leave old data (garbage ?)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 05-12-2020 , 11:11   [Q] About Dynamic Array Size char, leave old data (garbage ?)
Reply With Quote #1

When creating dynamic array, do we need manually "clear" array before using it ?
At least, in string you still get previous data from array, if you not overwrite it.

PHP Code:

public void OnPluginStart()
{
    
RegConsoleCmd("sm_test"test);
}

public 
Action test(int clientint args)
{

    
int NumberOfSlots 4;
    
int SlotSize 6;
    
    
    
char[][] MyBuffer = new char[NumberOfSlots][SlotSize];
    
    
// clear strings
    //for(int x = 0; x < NumberOfSlots; x++) MyBuffer[x][0] = '\0';


    
for(int x 0<= args && NumberOfSlotsx++)
    {
        
GetCmdArg(xMyBuffer[x], SlotSize);
    }
    
    
    
    for(
int x 0NumberOfSlotsx++)
    {
        
PrintToServer("[%i]%s"xMyBuffer[x]);
    }



    return 
Plugin_Handled;


console output
Code:
sm_test
[0]sm_te
[1]
[2]
[3]
sm_test apina
[0]sm_te
[1]apina
[2]
[3]
sm_test apina orkesteri
[0]sm_te
[1]apina
[2]orkes
[3]
sm_test apina orkesteri simpanssi
[0]sm_te
[1]apina
[2]orkes
[3]simpa
sm_test AA
[0]sm_te
[1]AA
[2]orkes
[3]simpa
sm_test AA or
[0]sm_te
[1]AA
[2]or
[3]simpa
sm_test AA or ""
[0]sm_te
[1]AA
[2]or
[3]
sm_test AA or "asd"
[0]sm_te
[1]AA
[2]or
[3]asd
sm_test A
[0]sm_te
[1]A
[2]or
[3]asd

Last edited by Bacardi; 05-12-2020 at 13:06. Reason: Thanks Devs
Bacardi is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 05-12-2020 , 11:33   Re: [Q] About Dynamic Array Size char, leave old data (garbage ?)
Reply With Quote #2

What spcomp version are you using? This looks like a compiler bug.
__________________
asherkin is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 05-12-2020 , 11:35   Re: [Q] About Dynamic Array Size char, leave old data (garbage ?)
Reply With Quote #3

Code:
SourcePawn Compiler 1.10.0.6488
Copyright (c) 1997-2006 ITB CompuPhase
Copyright (c) 2004-2018 AlliedModders LLC

Code size:             3508 bytes
Data size:             2300 bytes
Stack/heap size:      16384 bytes
Total requirements:   22192 bytes
*edit
I go try new version

*edit
Ok... could it cause by old version of CSGO server ? I try update that for now and try again.

*edit
I have updated server and game. Upgrade SM to 1.11 dev
compiled plugin with
Code:
SourcePawn Compiler 1.11.0.6541
Copyright (c) 1997-2006 ITB CompuPhase
Copyright (c) 2004-2018 AlliedModders LLC

Code size:             4088 bytes
Data size:             2300 bytes
Stack/heap size:      16384 bytes
Total requirements:   22772 bytes
And still same results.


*edit
could this be same problem like in this topic ?
Local variable initialisation
__________________
Do not Private Message @me

Last edited by Bacardi; 05-12-2020 at 12:06.
Bacardi is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 05-12-2020 , 12:32   Re: [Q] About Dynamic Array Size char, leave old data (garbage ?)
Reply With Quote #4

Thanks, I've opened an issue for it.

Quote:
Originally Posted by Bacardi View Post
could this be same problem like in this topic ?
Local variable initialisation
I don't think so - I haven't been able to reproduce that.
__________________
asherkin is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 09:55.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode