Raised This Month: $51 Target: $400
 12% 

[SQLx.inc] possible typo?


  
 
 
Thread Tools Display Modes
Author Message
jRaven
AMX Mod X Beta Tester
Join Date: Jan 2006
Location: IA, USA
Old 12-09-2006 , 13:34   [SQLx.inc] possible typo?
#1

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.
jRaven is offline
Send a message via ICQ to jRaven Send a message via AIM to jRaven
MaximusBrood
Veteran Member
Join Date: Sep 2005
Location: The Netherlands
Old 12-10-2006 , 05:56   Re: [SQLx.inc] possible typo?
#2

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.
__________________
Released six formerly private plugins. Not active here since ages.
MaximusBrood is offline
Zenith77
Veteran Member
Join Date: Aug 2005
Old 12-10-2006 , 12:41   Re: [SQLx.inc] possible typo?
#3

It should be 11, however using sizeof really wouldn't make sense since you know the size.
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred

Last edited by Zenith77; 12-10-2006 at 13:10.
Zenith77 is offline
BAILOPAN
Join Date: Jan 2004
Old 12-10-2006 , 13:02   Re: [SQLx.inc] possible typo?
#4

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.
__________________
egg
BAILOPAN is offline
BAILOPAN
Join Date: Jan 2004
Old 12-18-2006 , 21:00   Re: [SQLx.inc] possible typo?
#5

Thanks for the report. This is fixed as revision 3174.
__________________
egg
BAILOPAN is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:53.


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