alliedmodders / sourcepawn

A small, statically typed scripting language.
Other
369 stars 63 forks source link

return value issues #873

Closed ProjectSky closed 1 year ago

ProjectSky commented 1 year ago

SourcePawn Compiler 1.12.0.6983

float GetEntityDistance(int ent1, int ent2)
{
    float orig1[3], orig2[3], distance;
    GetEntPropVector(ent1, Prop_Send, "m_vecOrigin", orig1);
    GetEntPropVector(ent2, Prop_Send, "m_vecOrigin", orig2);

    distance = GetVectorDistance(orig1, orig2);

    switch (g_hDistanceUnit.IntValue)
    {
        case 0: return distance; // units
        case 1: return distance * 0.01905; // meters
        case 2: return distance / 16; // foot
        default: return 0.0;
    }
}
//  no warning
int FormatDistanceUnit(char[] buffer, int maxlen)
{
    switch (g_hDistanceUnit.IntValue)
    {
        case 0: strcopy(buffer, maxlen, "units");
        case 1: strcopy(buffer, maxlen, "meters");
        case 2: strcopy(buffer, maxlen, "foot");
        default: return 0;
    }
}
// warning 209: function has explicit 'int' tag but does not return a value
asherkin commented 1 year ago

You aren't returning in 3 of the 4 cases in FormatDistanceUnit, and there is no return value after the switch.

Please ask the forum or Discord about your code before opening an issue.

ProjectSky commented 1 year ago

I didn't realize that it was a stupid mistakes. sorry.