pawn-lang / compiler

Pawn compiler for SA-MP with bug fixes and new features - runs on Windows, Linux, macOS
Other
306 stars 72 forks source link

Assertion `retsize>0' failed #177

Closed tmp64 closed 6 years ago

tmp64 commented 7 years ago

This code causes "Assertion `retsize>0' failed" error under Linux:

GetVehName(id)
{
    return VehicleModel[id-400];
}

Everything compiles fine under Windows.

Compiler log:

Pawn compiler 3.10.2                    Copyright (c) 1997-2006, ITB CompuPhase

pawncc: /home/travis/build/Zeex/pawn/source/compiler/sc3.c:1986: callfunction: Assertion `retsize>0' failed.
Aborted
YashasSamaga commented 7 years ago

You are probably using the debug build in your Linux machine and the release build in the Windows machine.

Can you show your VehicleModel definition? I suspect that VehicleModel array does not have fixed minor dimension size.

tmp64 commented 7 years ago
new VehicleModel[212][] =
{
    "Landstalker","Bravura","Buffalo","Linerunner","Perrenial","Sentinel","Dumper","Firetruck","Trashmaster","Stretch","Manana","Infernus",
    "Voodoo","Pony","Mule","Cheetah","Ambulance","Leviathan","Moonbeam","Esperanto","Taxi","Washington","Bobcat","Mr.Whoopee","BF Injection",
    "Hunter","Premier","Enforcer","Securicar","Banshee","Predator","Bus","Rhino","Barracks","Hotknife","Trailer","Previon","Coach","Cabbie",
    "Stallion","Rumpo","RC Bandit","Romero","Packer","Monster","Admiral","Squalo","Seasparrow","Pizzaboy","Tram","Trailer","Turismo","Speeder",
    "Reefer","Tropic","Flatbed","Yankee","Caddy","Solair","Berkley's RC Van","Skimmer","PCJ-600","Faggio","Freeway","RC Barron","RC Raider",
    "Glendale","Oceanic","Sanchez","Sparrow","Patriot","Quad","Coastguard","Dinghy","Hermes","Sabre","Rustler","Zr-350","Walton","Regina",
    "Comet","BMX","Burrito","Camper","Marquis","Baggage","Dozer","Maverick","News Chopper","Rancher","FBI Rancher","Virgo","Greenwood",
    "Jetmax","Hotring","Sandking","Blista Compact","Police Maverick","Boxville","Benson","Mesa","RC Goblin","Hotring A","Hotring B",
    "Bloodring Banger","Rancher","Super GT","Elegant","Journey","Bike","Mountain Bike","Beagle","Cropdust","Stunt","Tanker","RoadTrain",
    "Nebula","Majestic","Buccaneer","Shamal","Hydra","FCR-900","NRG-500","HPV1000","Cement Truck","Tow Truck","Fortune","Cadrona","FBI Truck",
    "Willard","Forklift","Tractor","Combine","Feltzer","Remington","Slamvan","Blade","Freight","Streak","Vortex","Vincent","Bullet","Clover",
    "Sadler","Firetruck","Hustler","Intruder","Primo","Cargobob","Tampa","Sunrise","Merit","Utility","Nevada","Yosemite","Windsor","Monster A",
    "Monster B","Uranus","Jester","Sultan","Stratum","Elegy","Raindance","RC Tiger","Flash","Tahoma","Savanna","Bandito","Freight","Trailer",
    "Kart","Mower","Duneride","Sweeper","Broadway","Tornado","AT-400","DFT-30","Huntley","Stafford","BF-400","Newsvan","Tug","Trailer A","Emperor",
    "Wayfarer","Euros","Hotdog","Club","Trailer B","Trailer C","Andromada","Dodo","RC Cam","Launch","Police Car","Police Car",
    "Police Car","Police Ranger","Picador","S.W.A.T.","Alpha","Phoenix","Glendale","Sadler","L Trailer A","L Trailer B",
    "Stair Trailer","Boxville","Farm Plow","U Trailer"
};

Well, I'm using the build from the releases page.

YashasSamaga commented 7 years ago

The compiler uses the value 0 (as a convention) for array dimensions which do not have a fixed size. As your vehicle array has a variable minor dimension, the compiler stores 0 as the array size but returning zero sized arrays is meaningless. This is why the assertion was triggered.

Giving a minor dimension size should stop the assertion from appearing but it would increase your AMX size (as every vehicle name now has to take up fixed number of cells irrespective of its actual length).

IMO, an error should be put in place when arrays of variable length is being returned.

Related Issue: #154

EDIT: Alternatively, you could use a define.

#define GetVehicleName(%0) VehicleModel[%0-400]

YashasSamaga commented 6 years ago

@Southclaws close?

Southclaws commented 6 years ago

It would be useful to catch this at the compile stage, but I'm not super sure how to do that yet. Closing for now.

YashasSamaga commented 6 years ago

@Southclaws It's already fixed in https://github.com/Southclaws/pawn/pull/190. An error is triggered if an array of unknown size is being returned.