AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   (OLD) Bug Reports (https://forums.alliedmods.net/forumdisplay.php?f=24)
-   -   [SQLx.inc] possible typo? (https://forums.alliedmods.net/showthread.php?t=48294)

jRaven 12-09-2006 13:34

[SQLx.inc] possible typo?
 
trunk/plugins/include/sqlx.inc
Code:
stock Handle:SQL_MakeStdTuple() {     static host[64], user[32], pass[32], db[128]     static get_type[12], set_type[12]         get_cvar_string("amx_sql_host", host, 63)     get_cvar_string("amx_sql_user", user, 31)     get_cvar_string("amx_sql_pass", pass, 31)     get_cvar_string("amx_sql_type", set_type, 11)     get_cvar_string("amx_sql_db", db, 127)         SQL_GetAffinity(get_type, 12)         if (!equali(get_type, set_type))     {         if (!SQL_SetAffinity(set_type))         {             log_amx("Failed to set affinity from %s to %s.", get_type, set_type)         }     }         return SQL_MakeDbTuple(host, user, pass, db) }

Shouldn't the following pass a value of sizeof(get_type)-1 = 11 instead of 12?
Code:
    SQL_GetAffinity(get_type, 12)

Is there any performance disadvantage to using sizeof directives in stocks like this? It seems like it would be a better or safer practice to have declaration-relative maxlens automatically put in place by the machine.

MaximusBrood 12-10-2006 05:56

Re: [SQLx.inc] possible typo?
 
First of all, I'm not sure if I'm making sense here.
I just wanted to say that sizeof will not affect performance, it's handled at compiletime, not at runtime.

Zenith77 12-10-2006 12:41

Re: [SQLx.inc] possible typo?
 
It should be 11, however using sizeof really wouldn't make sense since you know the size.

BAILOPAN 12-10-2006 13:02

Re: [SQLx.inc] possible typo?
 
This is indeed a typo. sizeof() is encouraged on local variables whose size is pre-defined, since you don't have to update constants throughout code.

BAILOPAN 12-18-2006 21:00

Re: [SQLx.inc] possible typo?
 
Thanks for the report. This is fixed as revision 3174.


All times are GMT -4. The time now is 21:12.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.