Spawning Private Vehicles[MySQL]
#21

Code:
sscanf warning: Strings without a length are deprecated, please add a destination size.
sscanf warning: String buffer overflow.
I'm still getting buffer overflow without a size on the S integer. I also increased the query string size to 600 cells and that made no difference to the overflow.

Adding a size to the S integer stop it from being deprecated so therefore it's correct by not just being 'S'.
Reply
#22

What's the length of 's' as of now?
Reply
#23

The length of S is [24] cells. I changed your ["#MAX_PLAYER_NAME"] as it made lots of errors for me.
Reply
#24

Quote:
Originally Posted by Peach
View Post
The length of S is [24] cells. I changed your ["#MAX_PLAYER_NAME"] as it made lots of errors for me.
That's really strange, as long as you're sure it's on the aforementioned lines, this line is in your enum
pawn Code:
playerCarOwner[MAX_PLAYER_NAME]
and
pawn Code:
s[24]
is in the sscanf string, there shouldn't be any reason to get a buffer overflow, consult the sscanf topic.
Reply
#25

It may not even be this integer, I think it may be the SSCANF query itself. It's just an assumption of it being the problem.
Reply
#26

Quote:
Originally Posted by Y_Less
View Post
  • sscanf warning: String buffer overflow.
This error comes up when people try and put too much data in to a string. For example:

pawn Code:
new str[10];
sscanf("Hello there, how are you?", "s[10]", str);
That code will try and put the string "Hello there, how are you?" in to the variable called "str". However, "str" is only 10 cells big and can thus only hold the string "Hello ther" (with a NULL terminator). In this case, the rest of the data is ignored - which could be good or bad:
as long as you don't have any other sscanf lines, then I'd say this one is the culprit.
Reply
#27

I am using other sscanf lines but they are not the problem here, I've disabled every callback which loads data through a string so I know that the problem is in the LoadPlayerVehicles callback. I've tried increasing my string size to 600 cells and again even more just for testing. Spawning a car from 600 cells or more is not really needed.
Reply
#28

Can you show the LoadPlayerVehicles function again, please.
Reply
#29

PHP Code:
stock LoadPlayerVehicles(playerid)
{
    new 
query[600];
    
format(querysizeof(query), "SELECT * FROM `playervehicles` WHERE `OwnerName` = '%s'"PlayerName(playerid));
    
mysql_query(query);
    
mysql_store_result();
    new 
i;
    while(
MAX_PLAYER_OWNED_CARS && mysql_retrieve_row())
    {
        
mysql_fetch_row_format(query);
        
sscanf(query"p<|>s[24]dffffdddddddddddddddddddddddddddddddddddd",
            
PlayerOwnedVehicles[playerid][i][playerCarOwner],
            
PlayerOwnedVehicles[playerid][i][playerCarModel],
            
PlayerOwnedVehicles[playerid][i][playerCarX],
            
PlayerOwnedVehicles[playerid][i][playerCarY],
            
PlayerOwnedVehicles[playerid][i][playerCarZ],
            
PlayerOwnedVehicles[playerid][i][playerCarRot],
            
PlayerOwnedVehicles[playerid][i][playerCarColor1],
            
PlayerOwnedVehicles[playerid][i][playerCarColor2],
            
PlayerOwnedVehicles[playerid][i][playerCarPaintjob],
            
PlayerOwnedVehicles[playerid][i][playerCarMod1],
            
PlayerOwnedVehicles[playerid][i][playerCarMod2],
            
PlayerOwnedVehicles[playerid][i][playerCarMod3],
            
PlayerOwnedVehicles[playerid][i][playerCarMod4],
            
PlayerOwnedVehicles[playerid][i][playerCarMod5],
            
PlayerOwnedVehicles[playerid][i][playerCarMod6],
            
PlayerOwnedVehicles[playerid][i][playerCarMod7],
            
PlayerOwnedVehicles[playerid][i][playerCarMod8],
            
PlayerOwnedVehicles[playerid][i][playerCarMod9],
            
PlayerOwnedVehicles[playerid][i][playerCarMod10],
            
PlayerOwnedVehicles[playerid][i][playerCarMod11],
            
PlayerOwnedVehicles[playerid][i][playerCarMod12],
            
PlayerOwnedVehicles[playerid][i][playerCarMod13],
            
PlayerOwnedVehicles[playerid][i][playerCarMod14],
            
PlayerOwnedVehicles[playerid][i][playerCarMod15],
            
PlayerOwnedVehicles[playerid][i][playerCarMod16],
            
PlayerOwnedVehicles[playerid][i][playerCarMod17],
            
PlayerOwnedVehicles[playerid][i][playerCarHasLock],
            
PlayerOwnedVehicles[playerid][i][playerCarLocked],
            
PlayerOwnedVehicles[playerid][i][playerCarTrunkCash],
            
PlayerOwnedVehicles[playerid][i][playerCarTrunkGun1],
            
PlayerOwnedVehicles[playerid][i][playerCarTrunkGun2],
            
PlayerOwnedVehicles[playerid][i][playerCarTrunkGun3],
            
PlayerOwnedVehicles[playerid][i][playerCarTrunkGun4],
            
PlayerOwnedVehicles[playerid][i][playerCarTrunkAmmo1],
            
PlayerOwnedVehicles[playerid][i][playerCarTrunkAmmo2],
            
PlayerOwnedVehicles[playerid][i][playerCarTrunkAmmo3],
            
PlayerOwnedVehicles[playerid][i][playerCarTrunkAmmo4],
            
PlayerOwnedVehicles[playerid][i][playerCarSpawned],
            
PlayerOwnedVehicles[playerid][i][playerCarOwned],
            
PlayerOwnedVehicles[playerid][i][playerCarOwnerID],
            
PlayerOwnedVehicles[playerid][i][playerCarFuel],
            
PlayerOwnedVehicles[playerid][i][playerCarSlotID]
        );
        
PlayerOwnedVehicles[playerid][i][playerCarID] = CreateVehicle(PlayerOwnedVehicles[playerid][i][playerCarModel], PlayerOwnedVehicles[playerid][i][playerCarX], PlayerOwnedVehicles[playerid][i][playerCarY], PlayerOwnedVehicles[playerid][i][playerCarZ], PlayerOwnedVehicles[playerid][i][playerCarRot], PlayerOwnedVehicles[playerid][i][playerCarColor1], PlayerOwnedVehicles[playerid][i][playerCarColor2], -1);
        
AddVehicleMods(playeridi);
        
i++;
    }
    
mysql_free_result();
    return 
true;

Reply
#30

Change this:
pawn Code:
sscanf(query, "p<|>s[24]dffffdddddddddddddddddddddddddddddddddddd",
To:
pawn Code:
sscanf(query, "p<|>sdffffdddddddddddddddddddddddddddddddddddd",
"S" as a capital is for the length, without ("s") is no need for any length.

And can you maybe show the database structure (If this above doesn't work)?
Reply
#31

The problem is that i'm not getting any vehicles spawning using retrieve but i'm getting 4 with num
Reply
#32

Try this code.
PHP Code:
stock LoadPlayerVehicles(playerid

    new
        
query[600],
        
0
    
format(querysizeof(query), "SELECT * FROM `playervehicles` WHERE `Name` = '%s' LIMIT %d"PlayerName(playerid), MAX_PLAYER_OWNED_CARS); 
    
mysql_query(query); 
    
mysql_store_result(); 
    
    
printf("%s"query); 
    
    while(
mysql_retrieve_row()) 
    { 
        
mysql_fetch_row_format(query);
        
printf("%s"query);
        
sscanf(query"p<|>s[24]dffffdddddddddddddddddddddddddddddddddddd"
            
PlayerOwnedVehicles[playerid][i][playerCarOwner], 
            
PlayerOwnedVehicles[playerid][i][playerCarModel], 
            
PlayerOwnedVehicles[playerid][i][playerCarX], 
            
PlayerOwnedVehicles[playerid][i][playerCarY], 
            
PlayerOwnedVehicles[playerid][i][playerCarZ], 
            
PlayerOwnedVehicles[playerid][i][playerCarRot], 
            
PlayerOwnedVehicles[playerid][i][playerCarColor1], 
            
PlayerOwnedVehicles[playerid][i][playerCarColor2], 
            
PlayerOwnedVehicles[playerid][i][playerCarPaintjob], 
            
PlayerOwnedVehicles[playerid][i][playerCarMod1], 
            
PlayerOwnedVehicles[playerid][i][playerCarMod2], 
            
PlayerOwnedVehicles[playerid][i][playerCarMod3], 
            
PlayerOwnedVehicles[playerid][i][playerCarMod4], 
            
PlayerOwnedVehicles[playerid][i][playerCarMod5], 
            
PlayerOwnedVehicles[playerid][i][playerCarMod6], 
            
PlayerOwnedVehicles[playerid][i][playerCarMod7], 
            
PlayerOwnedVehicles[playerid][i][playerCarMod8], 
            
PlayerOwnedVehicles[playerid][i][playerCarMod9], 
            
PlayerOwnedVehicles[playerid][i][playerCarMod10], 
            
PlayerOwnedVehicles[playerid][i][playerCarMod11], 
            
PlayerOwnedVehicles[playerid][i][playerCarMod12], 
            
PlayerOwnedVehicles[playerid][i][playerCarMod13], 
            
PlayerOwnedVehicles[playerid][i][playerCarMod14], 
            
PlayerOwnedVehicles[playerid][i][playerCarMod15], 
            
PlayerOwnedVehicles[playerid][i][playerCarMod16], 
            
PlayerOwnedVehicles[playerid][i][playerCarMod17], 
            
PlayerOwnedVehicles[playerid][i][playerCarHasLock], 
            
PlayerOwnedVehicles[playerid][i][playerCarLocked], 
            
PlayerOwnedVehicles[playerid][i][playerCarTrunkCash], 
            
PlayerOwnedVehicles[playerid][i][playerCarTrunkGun1], 
            
PlayerOwnedVehicles[playerid][i][playerCarTrunkGun2], 
            
PlayerOwnedVehicles[playerid][i][playerCarTrunkGun3], 
            
PlayerOwnedVehicles[playerid][i][playerCarTrunkGun4], 
            
PlayerOwnedVehicles[playerid][i][playerCarTrunkAmmo1], 
            
PlayerOwnedVehicles[playerid][i][playerCarTrunkAmmo2], 
            
PlayerOwnedVehicles[playerid][i][playerCarTrunkAmmo3], 
            
PlayerOwnedVehicles[playerid][i][playerCarTrunkAmmo4], 
            
PlayerOwnedVehicles[playerid][i][playerCarSpawned], 
            
PlayerOwnedVehicles[playerid][i][playerCarOwned], 
            
PlayerOwnedVehicles[playerid][i][playerCarOwnerID], 
            
PlayerOwnedVehicles[playerid][i][playerCarFuel], 
            
PlayerOwnedVehicles[playerid][i][playerCarSlotID
        );
        
        
printf("%s"query);
        
        
PlayerOwnedVehicles[playerid][i][playerCarID] = CreateVehicle(PlayerOwnedVehicles[playerid][i][playerCarModel], PlayerOwnedVehicles[playerid][i][playerCarX], PlayerOwnedVehicles[playerid][i][playerCarY], PlayerOwnedVehicles[playerid][i][playerCarZ], PlayerOwnedVehicles[playerid][i][playerCarRot], PlayerOwnedVehicles[playerid][i][playerCarColor1], PlayerOwnedVehicles[playerid][i][playerCarColor2], -1); 
        
AddVehicleMods(playeridi);
        
i++;
    } 
    
mysql_free_result();
    return 
1

Reply
#33

I keep getting string buffer overflow. Even with 600 cells it's possible, with the code you sent me.

pawn Code:
stock LoadPlayerVehicles(playerid)
{
    new query[600];
    format(query, sizeof(query), "SELECT * FROM `playervehicles` WHERE `Name` = '%s'", PlayerName(playerid));
    mysql_query(query);
    mysql_store_result();
    new i;
    if(mysql_num_rows() != 0)
    {
        while(i < MAX_PLAYER_OWNED_CARS && mysql_num_rows())
        {
            mysql_fetch_row_format(query);
            sscanf(query, "p<|>s[24]dffffdddddddddddddddddddddddddddddddddddd",
                PlayerOwnedVehicles[playerid][i][playerCarOwner],
                PlayerOwnedVehicles[playerid][i][playerCarModel],
                PlayerOwnedVehicles[playerid][i][playerCarX],
                PlayerOwnedVehicles[playerid][i][playerCarY],
                PlayerOwnedVehicles[playerid][i][playerCarZ],
                PlayerOwnedVehicles[playerid][i][playerCarRot],
                PlayerOwnedVehicles[playerid][i][playerCarColor1],
                PlayerOwnedVehicles[playerid][i][playerCarColor2],
                PlayerOwnedVehicles[playerid][i][playerCarPaintjob],
                PlayerOwnedVehicles[playerid][i][playerCarMod1],
                PlayerOwnedVehicles[playerid][i][playerCarMod2],
                PlayerOwnedVehicles[playerid][i][playerCarMod3],
                PlayerOwnedVehicles[playerid][i][playerCarMod4],
                PlayerOwnedVehicles[playerid][i][playerCarMod5],
                PlayerOwnedVehicles[playerid][i][playerCarMod6],
                PlayerOwnedVehicles[playerid][i][playerCarMod7],
                PlayerOwnedVehicles[playerid][i][playerCarMod8],
                PlayerOwnedVehicles[playerid][i][playerCarMod9],
                PlayerOwnedVehicles[playerid][i][playerCarMod10],
                PlayerOwnedVehicles[playerid][i][playerCarMod11],
                PlayerOwnedVehicles[playerid][i][playerCarMod12],
                PlayerOwnedVehicles[playerid][i][playerCarMod13],
                PlayerOwnedVehicles[playerid][i][playerCarMod14],
                PlayerOwnedVehicles[playerid][i][playerCarMod15],
                PlayerOwnedVehicles[playerid][i][playerCarMod16],
                PlayerOwnedVehicles[playerid][i][playerCarMod17],
                PlayerOwnedVehicles[playerid][i][playerCarHasLock],
                PlayerOwnedVehicles[playerid][i][playerCarLocked],
                PlayerOwnedVehicles[playerid][i][playerCarTrunkCash],
                PlayerOwnedVehicles[playerid][i][playerCarTrunkGun1],
                PlayerOwnedVehicles[playerid][i][playerCarTrunkGun2],
                PlayerOwnedVehicles[playerid][i][playerCarTrunkGun3],
                PlayerOwnedVehicles[playerid][i][playerCarTrunkGun4],
                PlayerOwnedVehicles[playerid][i][playerCarTrunkAmmo1],
                PlayerOwnedVehicles[playerid][i][playerCarTrunkAmmo2],
                PlayerOwnedVehicles[playerid][i][playerCarTrunkAmmo3],
                PlayerOwnedVehicles[playerid][i][playerCarTrunkAmmo4],
                PlayerOwnedVehicles[playerid][i][playerCarSpawned],
                PlayerOwnedVehicles[playerid][i][playerCarOwned],
                PlayerOwnedVehicles[playerid][i][playerCarOwnerID],
                PlayerOwnedVehicles[playerid][i][playerCarFuel],
                PlayerOwnedVehicles[playerid][i][playerCarSlotID]
            );
            PlayerOwnedVehicles[playerid][i][playerCarID] = CreateVehicle(PlayerOwnedVehicles[playerid][i][playerCarModel], PlayerOwnedVehicles[playerid][i][playerCarX], PlayerOwnedVehicles[playerid][i][playerCarY], PlayerOwnedVehicles[playerid][i][playerCarZ], PlayerOwnedVehicles[playerid][i][playerCarRot], PlayerOwnedVehicles[playerid][i][playerCarColor1], PlayerOwnedVehicles[playerid][i][playerCarColor2], -1);
            AddVehicleMods(playerid, i);
            i++;
        }
    }
    mysql_free_result();
    return true;
}
This is the only code that's managed to spawn the vehicles I know i'm loading them through mysql_num_rows as it should be mysql_retrieve_row but this is the closest i've been to spawning vehicles and having it working. Though it spams 4 vehicles of the same kind. I'm not saying leave it like that but it must be a good thing. The [i] is used to get the vehicle slot id. MAX_PLAYER_OWNED_VEHICLES 2 would be slot 2 for the player. I'm trying to do it like that, thankyou all for your help again so far.
Reply
#34

I don't know any solutions more...

Maybe Y_Less can help you with the 'buffer overflow' error.
Reply
#35

The buffer overflow only occurs when i'm using the same query string for everything. Say I used a different string for the sscanf.. the overflow would suddenly go.

Awaiting Y_LESS to respond to this post about buffer overflow.
Reply
#36

The problems seems to be the loop, does anyone have any other suggestions on how to fix this?

I know how to fix the buffer overflow as I have spoken to Y_LESS.
Reply
#37

Quote:
Originally Posted by Peach
View Post
The problems seems to be the loop, does anyone have any other suggestions on how to fix this?

I know how to fix the buffer overflow as I have spoken to Y_LESS.
Can you show what you have now.
Reply
#38

Fixed and working.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)