summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2013-02-18 00:30:28 -0300
committershennetsind <ind@henn.et>2013-02-18 00:30:28 -0300
commit7e72f0cee8867837be53cb2119b610b00e9bd587 (patch)
tree22ab404109fb2def22cf0085fcec2bf174210970 /src/common
parent237d76e7c409251b5fdb9f3eee40ef3fe5dc2b25 (diff)
downloadhercules-7e72f0cee8867837be53cb2119b610b00e9bd587.tar.gz
hercules-7e72f0cee8867837be53cb2119b610b00e9bd587.tar.bz2
hercules-7e72f0cee8867837be53cb2119b610b00e9bd587.tar.xz
hercules-7e72f0cee8867837be53cb2119b610b00e9bd587.zip
Improvements all over the place
Committing on the behalf of mkbu95 who is unable to do it himself, he coded it all and sent me the diff. Thanks mkbu95! Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/common')
-rw-r--r--src/common/core.c2
-rw-r--r--src/common/grfio.c16
-rw-r--r--src/common/raconf.c6
-rw-r--r--src/common/socket.c6
4 files changed, 16 insertions, 14 deletions
diff --git a/src/common/core.c b/src/common/core.c
index 4495cf1a2..b004d2b96 100644
--- a/src/common/core.c
+++ b/src/common/core.c
@@ -272,7 +272,7 @@ const char *get_git_hash (void) {
char line[64];
char *rev = malloc (sizeof (char) * 50);
- if (fgets (line, sizeof (line), fp) && sscanf (line, "%s", rev))
+ if (fgets (line, sizeof (line), fp) && sscanf (line, "%50s", rev))
snprintf (HerculesGitHash, sizeof (HerculesGitHash), "%s", rev);
free (rev);
diff --git a/src/common/grfio.c b/src/common/grfio.c
index 8f430cfb9..cc2f866f7 100644
--- a/src/common/grfio.c
+++ b/src/common/grfio.c
@@ -393,12 +393,12 @@ void* grfio_reads(const char* fname, int* size)
FILELIST* entry = filelist_find(fname);
if( entry == NULL || entry->gentry <= 0 ) {// LocalFileCheck
char lfname[256];
- int declen;
FILE* in;
grfio_localpath_create(lfname, sizeof(lfname), ( entry && entry->fnd ) ? entry->fnd : fname);
in = fopen(lfname, "rb");
if( in != NULL ) {
+ int declen;
fseek(in,0,SEEK_END);
declen = ftell(in);
fseek(in,0,SEEK_SET);
@@ -475,14 +475,14 @@ static char* decode_filename(unsigned char* buf, int len)
/// @return true if the file should undergo full mode 0 decryption, and true otherwise.
static bool isFullEncrypt(const char* fname)
{
- static const char extensions[4][5] = { ".gnd", ".gat", ".act", ".str" };
- size_t i;
-
const char* ext = strrchr(fname, '.');
- if( ext != NULL )
+ if( ext != NULL ) {
+ static const char extensions[4][5] = { ".gnd", ".gat", ".act", ".str" };
+ size_t i;
for( i = 0; i < ARRAYLENGTH(extensions); ++i )
if( strcmpi(ext, extensions[i]) == 0 )
return false;
+ }
return true;
}
@@ -492,7 +492,7 @@ static bool isFullEncrypt(const char* fname)
/// @param gentry index of the grf file name in the gentry_table
static int grfio_entryread(const char* grfname, int gentry)
{
- long grf_size,list_size;
+ long grf_size;
unsigned char grf_header[0x2e];
int entry,entrys,ofs,grf_version;
unsigned char *grf_filelist;
@@ -518,6 +518,7 @@ static int grfio_entryread(const char* grfname, int gentry)
grf_version = getlong(grf_header+0x2a) >> 8;
if( grf_version == 0x01 ) {// ****** Grf version 01xx ******
+ long list_size;
list_size = grf_size - ftell(fp);
grf_filelist = (unsigned char *) aMalloc(list_size);
if(fread(grf_filelist,1,list_size,fp) != list_size) { ShowError("Couldn't read all grf_filelist element of %s \n", grfname); }
@@ -678,7 +679,7 @@ static bool grfio_parse_restable_row(const char* row)
static void grfio_resourcecheck(void)
{
char restable[256];
- char *ptr, *buf;
+ char *buf;
int size;
FILE* fp;
int i = 0;
@@ -705,6 +706,7 @@ static void grfio_resourcecheck(void)
buf = (char *)grfio_reads("data\\resnametable.txt", &size);
if( buf != NULL )
{
+ char *ptr;
buf[size] = '\0';
ptr = buf;
diff --git a/src/common/raconf.c b/src/common/raconf.c
index 2703560ff..f7d1284b7 100644
--- a/src/common/raconf.c
+++ b/src/common/raconf.c
@@ -41,12 +41,11 @@ struct conf_value{
static struct conf_value *makeValue(const char *key, char *val, size_t val_len){
struct conf_value *v;
- char *p;
- size_t sz;
+/* size_t sz;
sz = sizeof(struct conf_value);
if(val_len >= sizeof(v->strval))
- sz += (val_len - sizeof(v->strval) + 1);
+ sz += (val_len - sizeof(v->strval) + 1);*/
v = (struct conf_value*)aCalloc(1, sizeof(struct conf_value));
if(v == NULL){
@@ -106,6 +105,7 @@ static struct conf_value *makeValue(const char *key, char *val, size_t val_len){
}else if( *val >='0' && *val <= '9'){ // begins with normal digit, so assume its dec.
// is it float?
bool is_float = false;
+ char *p;
for(p = val; *p != '\0'; p++){
if(*p == '.'){
diff --git a/src/common/socket.c b/src/common/socket.c
index 6977d4257..72633cf2b 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -1017,14 +1017,14 @@ int access_ipmask(const char* str, AccessControl* acc)
{
uint32 ip;
uint32 mask;
- unsigned int a[4];
- unsigned int m[4];
- int n;
if( strcmp(str,"all") == 0 ) {
ip = 0;
mask = 0;
} else {
+ unsigned int a[4];
+ unsigned int m[4];
+ int n;
if( ((n=sscanf(str,"%u.%u.%u.%u/%u.%u.%u.%u",a,a+1,a+2,a+3,m,m+1,m+2,m+3)) != 8 && // not an ip + standard mask
(n=sscanf(str,"%u.%u.%u.%u/%u",a,a+1,a+2,a+3,m)) != 5 && // not an ip + bit mask
(n=sscanf(str,"%u.%u.%u.%u",a,a+1,a+2,a+3)) != 4 ) || // not an ip