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

Local variable initialisation


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 05-08-2020 , 11:02   Local variable initialisation
Reply With Quote #1

PHP Code:

void ManageDroppedWeapons
()
{
    if (!
g_Cvar_MaxWeapons.IntValue)
    {
        return;
    }
    
    
int ent = -1;
    
int numWeapons;
    
int listWeapons[512];
    
    while ((
ent FindEntityByClassname(ent"weapon_*")) != -1)
    {
        if (!
g_WeaponsInfo[ent].canBePicked || g_WeaponsInfo[ent].isBomb || g_WeaponsInfo[ent].mapPlaced || HasOwner(ent))
        {
            continue;
        }
        
        
listWeapons[numWeapons++] = ent;
    }
    
    
RemoveOldestWeapons(listWeaponsnumWeaponsg_Cvar_MaxWeapons.IntValue);

This code give me errors.
[SM] Exception reported: Array index out-of-bounds (index 512, limit 512).
I receive the error at: listWeapons[numWeapons++] = ent;

If I put, int numWeapons = 0, then there are no errors.
There's no way that there are 512 dropped weapons, because it gives me errors with few weapons in the world.

Does something changed about that? I thought that local variables are initialized with 0 (and strings with all chars on null).
__________________

Last edited by Ilusion9; 05-08-2020 at 11:06.
Ilusion9 is offline
kadet.89
Veteran Member
Join Date: Nov 2012
Location: Serbia
Old 05-08-2020 , 17:03   Re: Local variable initialisation
Reply With Quote #2

Anything can be in int variable unless it's explicitly initialized
kadet.89 is offline
Send a message via Skype™ to kadet.89
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 05-09-2020 , 02:06   Re: Local variable initialisation
Reply With Quote #3

Quote:
Originally Posted by kadet.89 View Post
Anything can be in int variable unless it's explicitly initialized
That can be done with old syntax, example:
Code:
decl MyVar; // contains garbage
But SM 1.7+ always initializes variables with zeros. This might be a bug.
__________________
MAGNAT2645 is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 05-09-2020 , 08:39   Re: Local variable initialisation
Reply With Quote #4

Which version of SP compiler OP is using ?
__________________
Do not Private Message @me
Bacardi is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 05-09-2020 , 09:04   Re: Local variable initialisation
Reply With Quote #5

Quote:
Originally Posted by Bacardi View Post
Which version of SP compiler OP is using ?
PHP Code:
#define SOURCEMOD_VERSION    "1.10.0.6455" 
__________________
Ilusion9 is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 05-09-2020 , 09:24   Re: Local variable initialisation
Reply With Quote #6

...no, not SouceMod version.
SourcePawn Compiler version.

Are you using compiler, inside sourcemod zip file or web compiler ?

You get version after compile.
Code:
SourcePawn Compiler 1.10.0.6488
Copyright (c) 1997-2006 ITB CompuPhase
Copyright (c) 2004-2018 AlliedModders LLC

Code size:             4144 bytes
Data size:             2560 bytes
Stack/heap size:      16384 bytes
Total requirements:   23088 bytes

or use DOS promp
Code:
F:\server\counter-strike global offensive\csgo\addons\sourcemod\scripting>spcomp.exe
SourcePawn Compiler 1.10.0.6488
Copyright (c) 1997-2006 ITB CompuPhase
Copyright (c) 2004-2018 AlliedModders LLC

Usage:   spcomp <filename> [filename...] [options]

Options:
         -a       output assembler code
         -Dpath   active directory path
         -e<name> set name of error file (quiet compile)
         -H<hwnd> window handle to send a notification message on finish
         -h       show included file paths
         -i<name> path for include files
         -l       create list file (preprocess only)
         -o<name> set base name of (P-code) output file
         -O<num>  optimization level (default=-O2)
             0    no optimization
             2    full optimizations
         -p<name> set name of "prefix" file
         -t<num>  TAB indent size (in character positions, default=8)
         -v<num>  verbosity level; 0=quiet, 1=normal, 2=verbose (default=1)
         -w<num>  disable a specific warning by its number
         -z<num>  compression level, default=9 (0=none, 1=worst, 9=best)
         -E       treat warnings as errors
         -\       use '\' for escape characters
         -^       use '^' for escape characters
         -;<+/->  require a semicolon to end each statement (default=-)
         sym=val  define constant "sym" with value "val"
         sym=     define constant "sym" with value 0

Options may start with a dash or a slash; the options "-d0" and "/d0" are
equivalent.

Options with a value may optionally separate the value from the option letter
with a colon (":"), an equal sign ("="), or a space (" "). That is, the options "-d0", "-d=0",
"-d:0", and "-d 0" are all equivalent. "-;" is an exception to this and cannot use a space.
__________________
Do not Private Message @me
Bacardi is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 05-09-2020 , 10:54   Re: Local variable initialisation
Reply With Quote #7

It's the same with that sourcemod version.
__________________
Ilusion9 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 18:02.


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