sscanf warning.
#1

Hi,

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

Command:

pawn Код:
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;
}
Reply
#2

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

Okay, thanks you

I have question about mktime

If the date is 2011-4-10 mktime makes that date to 2011410?
Reply
#4

bump
Reply
#5

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 Код:
native gettime(&hour=0, &minute=0, &second=0);
native getdate(&year=0, &month=0, &day=0);
native tickcount(&granularity=0);
Reply
#6

Oh, sorry.

It's from dutils.inc:

pawn Код:
/*
 * 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;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)