summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2013-12-02 17:24:31 +0100
committerHaru <haru@dotalux.com>2013-12-02 17:26:44 +0100
commitff5779033a7d45bbd306b2bf62759152a72cbe79 (patch)
tree28f1132eab6bd571f181509ccfaa9e5a1da685a5 /src
parent95581cedd9a89d8eac918bdc77c1a98e017abc46 (diff)
downloadhercules-ff5779033a7d45bbd306b2bf62759152a72cbe79.tar.gz
hercules-ff5779033a7d45bbd306b2bf62759152a72cbe79.tar.bz2
hercules-ff5779033a7d45bbd306b2bf62759152a72cbe79.tar.xz
hercules-ff5779033a7d45bbd306b2bf62759152a72cbe79.zip
Fixed an uninitialized variable / broken code.
- Follow up to c6c2ad187c386d8d27d3336dcbdd5a92555493d2 - Special thanks to Ind Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src')
-rw-r--r--src/map/script.c43
-rw-r--r--src/map/script.h2
2 files changed, 22 insertions, 23 deletions
diff --git a/src/map/script.c b/src/map/script.c
index 3982513d5..853f0c44f 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -420,7 +420,7 @@ void script_local_casecheck_clear(void) {
script_casecheck_clear_sub(&script->local_casecheck);
}
-bool script_casecheck_add_str_sub(struct casecheck_data *ccd, const char *p) {
+const char *script_casecheck_add_str_sub(struct casecheck_data *ccd, const char *p) {
#ifdef ENABLE_CASE_CHECK
int len, i;
int h = script->calc_hash_ci(p);
@@ -432,7 +432,7 @@ bool script_casecheck_add_str_sub(struct casecheck_data *ccd, const char *p) {
Assert( i >= 0 && i < ccd->str_size );
s = ccd->str_buf+ccd->str_data[i].str;
if( strcasecmp(s,p) == 0 ) {
- return true; // string already in list
+ return s; // string already in list
}
if( ccd->str_data[i].next == 0 )
break; // reached the end
@@ -470,14 +470,14 @@ bool script_casecheck_add_str_sub(struct casecheck_data *ccd, const char *p) {
ccd->str_num++;
#endif // ENABLE_CASE_CHECK
- return false;
+ return NULL;
}
-bool script_global_casecheck_add_str(const char *p) {
+const char *script_global_casecheck_add_str(const char *p) {
return script_casecheck_add_str_sub(&script->global_casecheck, p);
}
-bool script_local_casecheck_add_str(const char *p) {
+const char *script_local_casecheck_add_str(const char *p) {
return script_casecheck_add_str_sub(&script->local_casecheck, p);
}
@@ -486,22 +486,8 @@ bool script_local_casecheck_add_str(const char *p) {
int script_add_str(const char* p)
{
int i, len, h = script->calc_hash(p);
-
#ifdef ENABLE_CASE_CHECK
- bool alreadyexists = false;
- if( (strncmp(p, ".@", 2) == 0) ) // Local scope vars are checked separately to decrease false positives
- alreadyexists = script->local_casecheck.add_str(p);
- else {
- alreadyexists = script->global_casecheck.add_str(p);
- if( alreadyexists ) {
- if( strcasecmp(p, "disguise") == 0 || strcasecmp(p, "Poison_Spore") == 0
- || strcasecmp(p, "PecoPeco_Egg") == 0 || strcasecmp(p, "Soccer_Ball") == 0
- || strcasecmp(p, "Horn") == 0 || strcasecmp(p, "Treasure_Box_") == 0
- || strcasecmp(p, "Lord_of_Death") == 0
- ) // Known duplicates, don't bother warning the user
- alreadyexists = false;
- }
- }
+ const char *existingentry = NULL;
#endif // ENABLE_CASE_CHECK
if( script->str_hash[h] == 0 ) {// empty bucket, add new node here
@@ -520,8 +506,21 @@ int script_add_str(const char* p)
}
#ifdef ENABLE_CASE_CHECK
- if( alreadyexists ) {
- DeprecationWarning2("script_add_str", p, script->get_str(i), script->parser_current_file); // TODO
+ if( (strncmp(p, ".@", 2) == 0) ) // Local scope vars are checked separately to decrease false positives
+ existingentry = script->local_casecheck.add_str(p);
+ else {
+ existingentry = script->global_casecheck.add_str(p);
+ if( existingentry ) {
+ if( strcasecmp(p, "disguise") == 0 || strcasecmp(p, "Poison_Spore") == 0
+ || strcasecmp(p, "PecoPeco_Egg") == 0 || strcasecmp(p, "Soccer_Ball") == 0
+ || strcasecmp(p, "Horn") == 0 || strcasecmp(p, "Treasure_Box_") == 0
+ || strcasecmp(p, "Lord_of_Death") == 0
+ ) // Known duplicates, don't bother warning the user
+ existingentry = NULL;
+ }
+ }
+ if( existingentry ) {
+ DeprecationWarning2("script_add_str", p, existingentry, script->parser_current_file); // TODO
}
#endif // ENABLE_CASE_CHECK
diff --git a/src/map/script.h b/src/map/script.h
index 4d2c59d92..17120cd87 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -452,7 +452,7 @@ struct casecheck_data {
int str_size; // size of the buffer
int str_pos; // next position to be assigned
int str_hash[SCRIPT_HASH_SIZE];
- bool (*add_str) (const char* p);
+ const char *(*add_str) (const char* p);
void (*clear) (void);
};