summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/Makefile.in9
-rw-r--r--src/common/cbasetypes.h7
-rw-r--r--src/common/core.c3
-rw-r--r--src/common/db.h6
-rw-r--r--src/common/grfio.c23
-rw-r--r--src/common/malloc.c2
-rw-r--r--src/common/mmo.h3
-rw-r--r--src/common/socket.c12
-rw-r--r--src/common/sql.c4
-rw-r--r--src/common/strlib.c19
10 files changed, 53 insertions, 35 deletions
diff --git a/src/common/Makefile.in b/src/common/Makefile.in
index 1e23ab5e8..7bb9ae630 100644
--- a/src/common/Makefile.in
+++ b/src/common/Makefile.in
@@ -15,8 +15,8 @@ MT19937AR_H = $(MT19937AR_D)/mt19937ar.h
MT19937AR_INCLUDE = -I$(MT19937AR_D)
COMMON_SHARED_C = conf.c db.c des.c ers.c grfio.c HPM.c mapindex.c md5calc.c \
- mempool.c mutex.c nullpo.c raconf.c random.c showmsg.c strlib.c \
- thread.c timer.c utils.c
+ mutex.c nullpo.c random.c showmsg.c strlib.c thread.c \
+ timer.c utils.c
COMMON_C = $(COMMON_SHARED_C)
COMMON_SHARED_OBJ = $(patsubst %.c,%.o,$(COMMON_SHARED_C))
COMMON_OBJ = $(addprefix obj_all/, $(COMMON_SHARED_OBJ) \
@@ -25,9 +25,8 @@ COMMON_MINI_OBJ = $(addprefix obj_all/, $(COMMON_SHARED_OBJ) \
miniconsole.o minicore.o minimalloc.o minisocket.o)
COMMON_C += console.c core.c malloc.c socket.c
COMMON_H = atomic.h cbasetypes.h conf.h console.h core.h db.h des.h ers.h \
- evdp.h grfio.h HPM.h HPMi.h malloc.h mapindex.h md5calc.h \
- mempool.h mmo.h mutex.h netbuffer.h network.h nullpo.h raconf.h \
- random.h showmsg.h socket.h spinlock.h sql.h strlib.h \
+ grfio.h HPM.h HPMi.h malloc.h mapindex.h md5calc.h mmo.h mutex.h \
+ nullpo.h random.h showmsg.h socket.h spinlock.h sql.h strlib.h \
thread.h timer.h utils.h winapi.h
COMMON_SQL_OBJ = obj_sql/sql.o
diff --git a/src/common/cbasetypes.h b/src/common/cbasetypes.h
index d00f49864..120f4f861 100644
--- a/src/common/cbasetypes.h
+++ b/src/common/cbasetypes.h
@@ -255,6 +255,13 @@ typedef uintptr_t uintptr;
#define ra_align(n) __attribute__(( aligned(n) ))
#endif
+// Directives for the (clang) static analyzer
+#ifdef __clang__
+#define analyzer_noreturn __attribute__((analyzer_noreturn))
+#else
+#define analyzer_noreturn
+#endif
+
/////////////////////////////
// for those still not building c++
diff --git a/src/common/core.c b/src/common/core.c
index dd839b372..8178a48a5 100644
--- a/src/common/core.c
+++ b/src/common/core.c
@@ -15,7 +15,6 @@
#include "../common/socket.h"
#include "../common/timer.h"
#include "../common/thread.h"
- #include "../common/mempool.h"
#include "../common/sql.h"
#include "../config/core.h"
#include "../common/HPM.h"
@@ -328,7 +327,6 @@ int main (int argc, char **argv) {
Sql_Init();
rathread_init();
- mempool_init();
DB->init();
signals_init();
@@ -370,7 +368,6 @@ int main (int argc, char **argv) {
timer->final();
socket_final();
DB->final();
- mempool_final();
rathread_final();
#endif
diff --git a/src/common/db.h b/src/common/db.h
index b9d6af382..5f4478909 100644
--- a/src/common/db.h
+++ b/src/common/db.h
@@ -1121,8 +1121,10 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...);
#define VECTOR_ENSURE(__vec,__n,__step) \
do{ \
size_t _empty_ = VECTOR_CAPACITY(__vec)-VECTOR_LENGTH(__vec); \
- while( (__n) > _empty_ ) _empty_ += (__step); \
- if( _empty_ != VECTOR_CAPACITY(__vec)-VECTOR_LENGTH(__vec) ) VECTOR_RESIZE(__vec,_empty_+VECTOR_LENGTH(__vec)); \
+ if( (__n) > _empty_ ) { \
+ while( (__n) > _empty_ ) _empty_ += (__step); \
+ VECTOR_RESIZE(__vec,_empty_+VECTOR_LENGTH(__vec)); \
+ } \
}while(0)
diff --git a/src/common/grfio.c b/src/common/grfio.c
index 77b976926..57e8a5187 100644
--- a/src/common/grfio.c
+++ b/src/common/grfio.c
@@ -8,6 +8,7 @@
#include "../common/showmsg.h"
#include "../common/strlib.h"
#include "../common/utils.h"
+#include "../common/nullpo.h"
#include "grfio.h"
#include <stdio.h>
@@ -305,17 +306,21 @@ static FILELIST* filelist_find(const char* fname)
// returns the original file name
char* grfio_find_file(const char* fname)
{
- FILELIST *filelist = filelist_find(fname);
- if (!filelist) return NULL;
- return (!filelist->fnd ? filelist->fn : filelist->fnd);
+ FILELIST *flist = filelist_find(fname);
+ if (!flist) return NULL;
+ return (!flist->fnd ? flist->fn : flist->fnd);
}
// adds a FILELIST entry into the list of loaded files
-static FILELIST* filelist_add(FILELIST* entry)
-{
+static FILELIST* filelist_add(FILELIST* entry) {
int hash;
+ nullpo_ret(entry);
+#ifdef __clang_analyzer__
+ // Make clang's static analyzer shut up about a possible NULL pointer in &filelist[filelist_entrys]
+ nullpo_ret(&filelist[filelist_entrys]);
+#endif // __clang_analyzer__
- #define FILELIST_ADDS 1024 // number increment of file lists `
+#define FILELIST_ADDS 1024 // number increment of file lists `
if (filelist_entrys >= filelist_maxentry) {
filelist = (FILELIST *)aRealloc(filelist, (filelist_maxentry + FILELIST_ADDS) * sizeof(FILELIST));
@@ -323,7 +328,9 @@ static FILELIST* filelist_add(FILELIST* entry)
filelist_maxentry += FILELIST_ADDS;
}
- memcpy (&filelist[filelist_entrys], entry, sizeof(FILELIST));
+#undef FILELIST_ADDS
+
+ memcpy(&filelist[filelist_entrys], entry, sizeof(FILELIST));
hash = filehash(entry->fn);
filelist[filelist_entrys].next = filelist_hash[hash];
@@ -405,7 +412,7 @@ void* grfio_reads(const char* fname, int* size)
if( in != NULL ) {
int declen;
fseek(in,0,SEEK_END);
- declen = ftell(in);
+ declen = (int)ftell(in);
fseek(in,0,SEEK_SET);
buf2 = (unsigned char *)aMalloc(declen+1); // +1 for resnametable zero-termination
if(fread(buf2, 1, declen, in) != (size_t)declen) ShowError("An error occured in fread grfio_reads, fname=%s \n",fname);
diff --git a/src/common/malloc.c b/src/common/malloc.c
index 1cb7836ab..23e28a65f 100644
--- a/src/common/malloc.c
+++ b/src/common/malloc.c
@@ -669,7 +669,7 @@ void memmgr_report (int extra) {
struct {
const char *file;
unsigned short line;
- unsigned int size;
+ size_t size;
unsigned int count;
} data[100];
memset(&data, 0, sizeof(data));
diff --git a/src/common/mmo.h b/src/common/mmo.h
index 47257265f..b33b01fa7 100644
--- a/src/common/mmo.h
+++ b/src/common/mmo.h
@@ -284,7 +284,8 @@ struct accreg {
// For saving status changes across sessions. [Skotlex]
struct status_change_data {
unsigned short type; //SC_type
- long val1, val2, val3, val4, tick; //Remaining duration.
+ int val1, val2, val3, val4;
+ unsigned int tick; //Remaining duration.
};
struct storage_data {
diff --git a/src/common/socket.c b/src/common/socket.c
index 2ae9d44b3..9c6938008 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -340,7 +340,7 @@ void set_eof(int fd)
int recv_to_fifo(int fd)
{
- int len;
+ ssize_t len;
if( !session_isActive(fd) )
return -1;
@@ -377,7 +377,7 @@ int recv_to_fifo(int fd)
int send_from_fifo(int fd)
{
- int len;
+ ssize_t len;
if( !session_isValid(fd) )
return -1;
@@ -855,6 +855,10 @@ int do_sockets(int next)
}
}
+#ifdef __clang_analyzer__
+ // Let Clang's static analyzer know this never happens (it thinks it might because of a NULL check in session_isValid)
+ if (!session[i]) continue;
+#endif // __clang_analyzer__
session[i]->func_parse(i);
if(!session[i])
@@ -1330,7 +1334,7 @@ int socket_getips(uint32* ips, int max)
void socket_init(void)
{
char *SOCKET_CONF_FILENAME = "conf/packet.conf";
- unsigned int rlim_cur = FD_SETSIZE;
+ uint64 rlim_cur = FD_SETSIZE;
#ifdef WIN32
{// Start up windows networking
@@ -1403,7 +1407,7 @@ void socket_init(void)
timer->add_interval(timer->gettick()+1000, connect_check_clear, 0, 0, 5*60*1000);
#endif
- ShowInfo("Server supports up to '"CL_WHITE"%u"CL_RESET"' concurrent connections.\n", rlim_cur);
+ ShowInfo("Server supports up to '"CL_WHITE"%lld"CL_RESET"' concurrent connections.\n", rlim_cur);
/* Hercules Plugin Manager */
HPM->share(session,"session");
diff --git a/src/common/sql.c b/src/common/sql.c
index 0e06d6d18..79ccc8e92 100644
--- a/src/common/sql.c
+++ b/src/common/sql.c
@@ -1036,7 +1036,7 @@ void Sql_HerculesUpdateCheck(Sql* self) {
fseek (ufp,1,SEEK_SET);/* woo. skip the # */
if( fgets(timestamp,sizeof(timestamp),ufp) ) {
- unsigned int timestampui = atol(timestamp);
+ unsigned int timestampui = (unsigned int)atol(timestamp);
if( SQL_ERROR == SQL->Query(self, "SELECT 1 FROM `sql_updates` WHERE `timestamp` = '%u' LIMIT 1", timestampui) )
Sql_ShowDebug(self);
if( Sql_NumRows(self) != 1 ) {
@@ -1079,7 +1079,7 @@ void Sql_HerculesUpdateSkip(Sql* self,const char *filename) {
fseek (ifp,1,SEEK_SET);/* woo. skip the # */
if( fgets(timestamp,sizeof(timestamp),ifp) ) {
- unsigned int timestampui = atol(timestamp);
+ unsigned int timestampui = (unsigned int)atol(timestamp);
if( SQL_ERROR == SQL->Query(self, "SELECT 1 FROM `sql_updates` WHERE `timestamp` = '%u' LIMIT 1", timestampui) )
Sql_ShowDebug(self);
else if( Sql_NumRows(self) == 1 ) {
diff --git a/src/common/strlib.c b/src/common/strlib.c
index e45cb0789..0f68eb206 100644
--- a/src/common/strlib.c
+++ b/src/common/strlib.c
@@ -952,7 +952,7 @@ bool sv_readdb(const char* directory, const char* filename, char delim, int minc
if( line[0] == '\0' || line[0] == '\n' || line[0] == '\r')
continue;
- columns = sv_split(line, strlen(line), 0, delim, fields, fields_length, (e_svopt)(SV_TERMINATE_LF|SV_TERMINATE_CRLF));
+ columns = sv_split(line, (int)strlen(line), 0, delim, fields, fields_length, (e_svopt)(SV_TERMINATE_LF|SV_TERMINATE_CRLF));
if( columns < mincols ) {
ShowError("sv_readdb: Insufficient columns in line %d of \"%s\" (found %d, need at least %d).\n", lines, path, columns, mincols);
@@ -1018,7 +1018,8 @@ int StringBuf_Printf(StringBuf* self, const char* fmt, ...) {
/// Appends the result of vprintf to the StringBuf
int StringBuf_Vprintf(StringBuf* self, const char* fmt, va_list ap) {
- int n, size, off;
+ int n, off;
+ size_t size;
for(;;) {
va_list apcopy;
@@ -1028,7 +1029,7 @@ int StringBuf_Vprintf(StringBuf* self, const char* fmt, va_list ap) {
n = vsnprintf(self->ptr_, size, fmt, apcopy);
va_end(apcopy);
/* If that worked, return the length. */
- if( n > -1 && n < size ) {
+ if( n > -1 && (size_t)n < size ) {
self->ptr_ += n;
return (int)(self->ptr_ - self->buf_);
}
@@ -1042,11 +1043,11 @@ int StringBuf_Vprintf(StringBuf* self, const char* fmt, va_list ap) {
/// Appends the contents of another StringBuf to the StringBuf
int StringBuf_Append(StringBuf* self, const StringBuf* sbuf) {
- int available = self->max_ - (self->ptr_ - self->buf_);
- int needed = (int)(sbuf->ptr_ - sbuf->buf_);
+ size_t available = self->max_ - (self->ptr_ - self->buf_);
+ size_t needed = sbuf->ptr_ - sbuf->buf_;
if( needed >= available ) {
- int off = (int)(self->ptr_ - self->buf_);
+ size_t off = (self->ptr_ - self->buf_);
self->max_ += needed;
self->buf_ = (char*)aRealloc(self->buf_, self->max_ + 1);
self->ptr_ = self->buf_ + off;
@@ -1059,12 +1060,12 @@ int StringBuf_Append(StringBuf* self, const StringBuf* sbuf) {
// Appends str to the StringBuf
int StringBuf_AppendStr(StringBuf* self, const char* str) {
- int available = self->max_ - (self->ptr_ - self->buf_);
- int needed = (int)strlen(str);
+ size_t available = self->max_ - (self->ptr_ - self->buf_);
+ size_t needed = strlen(str);
if( needed >= available ) {
// not enough space, expand the buffer (minimum expansion = 1024)
- int off = (int)(self->ptr_ - self->buf_);
+ size_t off = (self->ptr_ - self->buf_);
self->max_ += max(needed, 1024);
self->buf_ = (char*)aRealloc(self->buf_, self->max_ + 1);
self->ptr_ = self->buf_ + off;