SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 10/04/2011, 04:15 PM   #1
Gh0sT_
Gangsta
 
Join Date: Sep 2010
Location: Lithuania, Alytus
Posts: 704
Reputation: 0
Default sscanf warning.

Hi,

I can't understand why I get sscanf warning for buffer overflow? Strings sizes - good...

Command:

pawn Code:
COMMAND:direktorius( playerid, params[ ] )
{
    if( GetPVarInt( playerid, "Administratorius" ) < 3 ) return SendClientMessage( playerid, -1, ""#h_Balta"["#h_Melyna"PRANEŠIMAS"#h_Balta"]: Jūs neesate Administratorius" );
    new
        Tikrinimas[ 9 ][ 2 ],
        Stringas[ 213 ]
    ;
    sscanf( params, "s[9]", Tikrinimas[ 0 ] );
    sscanf( params, "s[8]", Tikrinimas[ 1 ] );
    if( ! strcmp( Tikrinimas[ 0 ], "paskirti", true ) )
    {
        new
            ID,
            Direktorius
        ;
        if( sscanf( params[ strlen( Tikrinimas[ 0 ] ) ], "ud", ID, Direktorius ) ) return SendClientMessage( playerid, -1, ""#h_Balta"["#h_Melyna"PRANEŠIMAS"#h_Balta"]: /direktorius paskirti <Vardas> <D. ID>" );
        if( ID == INVALID_PLAYER_ID || ID == playerid ) return SendClientMessage( playerid, -1, ""#h_Balta"["#h_Melyna"PRANEŠIMAS"#h_Balta"]: Žaidėjas yra "#h_Raudona"neprisijungęs" );
        if( Direktorius > 4 ) return SendClientMessage( playerid, -1, ""#h_Balta"["#h_Melyna"PRANEŠIMAS"#h_Balta"]: Darbo ID suvestas blogai" );
        SetPVarInt( ID, "Direktorius", Direktorius );
        new
            dDirektorius[ 23 ]
        ;
        if( Direktorius == 1 ) dDirektorius = "Policijos Departamento";
        else if( Direktorius == 2 ) dDirektorius = "Medicinos Departamento";
        else if( Direktorius == 3 ) dDirektorius = "Taksi firmos";
        else if( Direktorius == 1 ) dDirektorius = "Dizainerių";
        format( Stringas, 174, ""#h_Balta"["#h_Melyna"PRANEŠIMAS"#h_Balta"]: Pagr. Administratorius %s Jus paskyrė kaip "#h_Raudona"%s "#h_Balta"direktoriumi.", ZaidejoVardas( playerid ), dDirektorius );
        SendClientMessage( ID, -1, Stringas );
        format( Stringas, 157, ""#h_Balta"["#h_Melyna"PRANEŠIMAS"#h_Balta"]: Žaidėją %s paskyrėte kaip "#h_Raudona"%s "#h_Balta"direktoriumi.", ZaidejoVardas( ID ), dDirektorius );
        SendClientMessage( playerid, -1, Stringas );
        return true;
    }
    else if( ! strcmp( Tikrinimas[ 1 ], "nuiimti", true ) )
    {
        new
            ID,
            Priezastis[ 76 ]
        ;
        if( sscanf( params[ strlen( Tikrinimas[ 0 ] ) ], "us[76]", ID, Priezastis ) ) return SendClientMessage( playerid, -1, ""#h_Balta"["#h_Melyna"PRANEŠIMAS"#h_Balta"]: /direktorius nuiimti <Vardas> <Priežastis>" );
        if( ID == INVALID_PLAYER_ID || ID == playerid ) return SendClientMessage( playerid, -1, ""#h_Balta"["#h_Melyna"PRANEŠIMAS"#h_Balta"]: Žaidėjas yra "#h_Raudona"neprisijungęs" );
        if( GetPVarInt( ID, "Direktorius" ) < 1 ) return SendClientMessage( playerid, -1, ""#h_Balta"["#h_Melyna"PRANEŠIMAS"#h_Balta"]: Žaidėjas nėra Direktorius" );
        if( strlen( Priezastis ) > 75 ) return SendClientMessage( playerid, -1, ""#h_Balta"["#h_Melyna"PRANEŠIMAS"#h_Balta"]: Priežastis yra "#h_Raudona"per ilga. "#h_Balta"[Iki 75 simbolių]" );
        SetPVarInt( ID, "Direktorius", 0 );
        format( Stringas, 253, ""#h_Balta"["#h_Melyna"PRANEŠIMAS"#h_Balta"]: Pagr. Administratorius %s Jums "#h_Raudona"nuemė "#h_Balta"Direktoriaus statusą. | Priežastis: "#h_Raudona"%s", ZaidejoVardas( playerid ), Priezastis );
        SendClientMessage( ID, -1, Stringas );
        format( Stringas, 200, ""#h_Balta"["#h_Melyna"PRANEŠIMAS"#h_Balta"]: Nuemėte žaidėjui %s Administratoriaus statusą. Priežastis: "#h_Raudona"%s", ZaidejoVardas( ID ), Priezastis );
        SendClientMessage( playerid, -1, Stringas );
    }
    else SendClientMessage( playerid, -1, ""#h_Balta"["#h_Melyna"PRANEŠIMAS"#h_Balta"]: /administratorius paskirti/nuiimti" );
    return true;
}
__________________
Includes
Player/Vehicle Control
Entrances system
Gh0sT_ is offline  
Old 10/04/2011, 06:08 PM   #2
Babul
High-roller
 
Babul's Avatar
 
Join Date: Sep 2009
Location: in a cement block
Posts: 1,781
Reputation: 251
Default Re: sscanf warning.

you defined the Tikrinimas stringlenghts wrong, by creating 9 cells sized 2:
Code:
    new Tikrinimas[9][2],//like {"00","11","22","33","44","55","66","77","88"},
you need 2 strings, sized 9:
Code:
    new Tikrinimas[2][9],// thats what you want: {"000000000","111111111"},
__________________
FireWorks

new sscanf2 custom specifiers available for Download, read the Release Topic
Babul is offline  
Old 10/04/2011, 06:53 PM   #3
Gh0sT_
Gangsta
 
Join Date: Sep 2010
Location: Lithuania, Alytus
Posts: 704
Reputation: 0
Default Re: sscanf warning.

Okay, thanks you

I have question about mktime

If the date is 2011-4-10 mktime makes that date to 2011410?
__________________
Includes
Player/Vehicle Control
Entrances system
Gh0sT_ is offline  
Old 11/04/2011, 12:30 PM   #4
Gh0sT_
Gangsta
 
Join Date: Sep 2010
Location: Lithuania, Alytus
Posts: 704
Reputation: 0
Default Re: sscanf warning.

bump
__________________
Includes
Player/Vehicle Control
Entrances system
Gh0sT_ is offline  
Old 11/04/2011, 12:44 PM   #5
Calgon
Banned
 
Join Date: Jan 2009
Posts: 6,130
Reputation: 1127
Default Re: sscanf warning.

There isn't a native mktime() function in pawn, we can't tell you if we can't see any code.

The only native time functions in pawn are:

pawn Code:
native gettime(&hour=0, &minute=0, &second=0);
native getdate(&year=0, &month=0, &day=0);
native tickcount(&granularity=0);
Calgon is offline  
Old 11/04/2011, 12:53 PM   #6
Gh0sT_
Gangsta
 
Join Date: Sep 2010
Location: Lithuania, Alytus
Posts: 704
Reputation: 0
Default Re: sscanf warning.

Oh, sorry.

It's from dutils.inc:

pawn Code:
/*
 * Originally created by mabako, tuned by DracoBlue
 */

stock mktime(hour,minute,second,day,month,year) {
    new timestamp2;

    timestamp2 = second + (minute * 60) + (hour * 3600);

    new days_of_month[12];

    if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) {
            days_of_month = {31,29,31,30,31,30,31,31,30,31,30,31}; // Schaltjahr
        } else {
            days_of_month = {31,28,31,30,31,30,31,31,30,31,30,31}; // keins
        }
    new days_this_year = 0;
    days_this_year = day;
    if(month > 1) { // No January Calculation, because its always the 0 past months
        for(new i=0; i<month-1;i++) {
            days_this_year += days_of_month[i];
        }
    }
    timestamp2 += days_this_year * 86400;

    for(new j=1970;j<year;j++) {
        timestamp2 += 31536000;
        if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) )  timestamp2 += 86400; // Schaltjahr + 1 Tag
    }

    return timestamp2;
}
__________________
Includes
Player/Vehicle Control
Entrances system
Gh0sT_ is offline  
 

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sscanf plugin warning BuLLeT[LTU] Help Archive 7 07/03/2011 08:00 PM
Strange sscanf warning? Fj0rtizFredde Help Archive 13 06/03/2011 06:59 AM
sscanf warning: String buffer overflow. armyoftwo Help Archive 3 05/12/2010 12:09 PM
sscanf warning [L3th4l] Help Archive 2 14/06/2010 03:38 AM
Warning sscanf Zafire2008 Help Archive 2 28/01/2010 09:56 PM


All times are GMT. The time now is 05:23 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.