mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-11-30 02:47:56 +08:00
use -Wanalyzer in gcc to check some warning in acl
This commit is contained in:
parent
4ce5e20917
commit
dbf91ceca8
@ -22,7 +22,7 @@ extern "C" {
|
||||
# endif
|
||||
#endif
|
||||
|
||||
ACL_API void acl_memory_debug_start(void);
|
||||
ACL_API int *acl_memory_debug_start(void);
|
||||
ACL_API void acl_memory_debug_stop(void);
|
||||
ACL_API void acl_memory_debug_stack(int onoff);
|
||||
ACL_API void acl_memory_stat(void);
|
||||
|
@ -91,6 +91,8 @@ ACL_FIFO *private_fifo_new(void)
|
||||
ACL_FIFO *fifo;
|
||||
|
||||
fifo = (ACL_FIFO *) malloc(sizeof(*fifo));
|
||||
assert(fifo);
|
||||
|
||||
fifo->head = NULL;
|
||||
fifo->tail = NULL;
|
||||
fifo->cnt = 0;
|
||||
@ -119,6 +121,8 @@ ACL_FIFO_INFO *private_fifo_push(ACL_FIFO *fifo, void *data)
|
||||
ACL_FIFO_INFO *info;
|
||||
|
||||
info = (ACL_FIFO_INFO *) malloc(sizeof(*info));
|
||||
assert(info);
|
||||
|
||||
info->data = data;
|
||||
|
||||
if (fifo->tail == NULL) {
|
||||
|
@ -499,8 +499,7 @@ int private_vstream_fflush(ACL_VSTREAM *stream)
|
||||
n = __vstream_sys_write(stream, ptr, (int) stream->wbuf_dlen);
|
||||
if (n <= 0) {
|
||||
if (acl_last_error() == ACL_EINTR
|
||||
|| acl_last_error() == ACL_EAGAIN)
|
||||
{
|
||||
|| acl_last_error() == ACL_EAGAIN) {
|
||||
continue;
|
||||
}
|
||||
return (ACL_VSTREAM_EOF);
|
||||
@ -541,7 +540,7 @@ ACL_VSTREAM *private_vstream_fdopen(ACL_SOCKET fd, unsigned int oflags,
|
||||
ACL_VSTREAM *stream = NULL;
|
||||
|
||||
stream = (ACL_VSTREAM *) calloc(1, sizeof(ACL_VSTREAM));
|
||||
acl_assert(stream);
|
||||
assert(stream);
|
||||
|
||||
if (buflen < ACL_VSTREAM_DEF_MAXLEN)
|
||||
buflen = ACL_VSTREAM_DEF_MAXLEN;
|
||||
@ -549,15 +548,14 @@ ACL_VSTREAM *private_vstream_fdopen(ACL_SOCKET fd, unsigned int oflags,
|
||||
/* XXX: 只有非监听流才需要有读缓冲区 */
|
||||
|
||||
if ((fdtype & ACL_VSTREAM_TYPE_LISTEN_INET)
|
||||
|| (fdtype & ACL_VSTREAM_TYPE_LISTEN_UNIX))
|
||||
{
|
||||
|| (fdtype & ACL_VSTREAM_TYPE_LISTEN_UNIX)) {
|
||||
fdtype |= ACL_VSTREAM_TYPE_LISTEN;
|
||||
stream->read_buf = NULL;
|
||||
} else {
|
||||
stream->read_buf = (unsigned char *) malloc(buflen + 1);
|
||||
acl_assert(stream->read_buf != NULL);
|
||||
}
|
||||
|
||||
stream->read_buf = (unsigned char *) malloc(buflen + 1);
|
||||
assert(stream->read_buf);
|
||||
|
||||
if (fdtype == 0)
|
||||
fdtype = ACL_VSTREAM_TYPE_SOCK;
|
||||
|
||||
@ -594,13 +592,9 @@ ACL_VSTREAM *private_vstream_fdopen(ACL_SOCKET fd, unsigned int oflags,
|
||||
stream->path = NULL;
|
||||
|
||||
stream->close_handle_lnk = private_array_create(5);
|
||||
if (stream->close_handle_lnk == NULL) {
|
||||
free(stream->read_buf);
|
||||
free(stream);
|
||||
return (NULL);
|
||||
}
|
||||
assert(stream->close_handle_lnk);
|
||||
|
||||
return (stream);
|
||||
return stream;
|
||||
}
|
||||
|
||||
ACL_VSTREAM *private_vstream_fopen(const char *path, unsigned int oflags,
|
||||
@ -747,8 +741,9 @@ void private_vstream_free(ACL_VSTREAM *stream)
|
||||
break;
|
||||
if (close_handle->close_fn == NULL)
|
||||
continue;
|
||||
/* 只所将此调用放在 close_fn 前面,是为了防止有人误在 close_fn
|
||||
* 里调用了删除回调函数的操作而造成对同一内存的多次释放
|
||||
/* 只所将此调用放在 close_fn 前面,是为了防止有人误在
|
||||
* close_fn 里调用了删除回调函数的操作而造成对同一内存
|
||||
* 的多次释放
|
||||
*/
|
||||
private_array_delete(stream->close_handle_lnk, i, NULL);
|
||||
close_handle->close_fn(stream, close_handle->context);
|
||||
|
@ -118,6 +118,8 @@ static void init_log_mutex(acl_pthread_mutex_t *lock)
|
||||
int n1, n2;
|
||||
pthread_mutexattr_t attr;
|
||||
|
||||
assert(lock);
|
||||
|
||||
n1 = pthread_mutexattr_init(&attr);
|
||||
|
||||
/* 使用了 pthread_atfork() 来避免 fork 后的死锁,因为在 fork 前调用过
|
||||
@ -232,6 +234,7 @@ static int open_file_log(const char *filename, const char *logpre)
|
||||
#endif
|
||||
|
||||
log = (ACL_LOG*) calloc(1, sizeof(ACL_LOG));
|
||||
assert(log);
|
||||
log->last_open = time(NULL);
|
||||
log->fp = fp;
|
||||
log->path = strdup(filename);
|
||||
|
@ -56,6 +56,7 @@ static ACL_XINETD_NV_PAIR *__nv_pair_new(const char *name, const char *value)
|
||||
acl_array_destroy(pair->values, acl_myfree_fn); \
|
||||
acl_myfree(pair); \
|
||||
} \
|
||||
return (x); \
|
||||
}
|
||||
|
||||
pair = (ACL_XINETD_NV_PAIR *) acl_mycalloc(1, sizeof(ACL_XINETD_NV_PAIR));
|
||||
|
@ -246,12 +246,15 @@ static void debug_dump_atexit(void)
|
||||
|
||||
ACL_DEBUG_MEM *acl_debug_malloc_init(ACL_DEBUG_MEM *debug_mem_ptr, const char *dump_file)
|
||||
{
|
||||
ACL_DEBUG_MEM *mem;
|
||||
if (debug_mem_ptr != NULL) {
|
||||
__debug_mem = debug_mem_ptr;
|
||||
__debug_mem = mem = debug_mem_ptr;
|
||||
} else {
|
||||
ASSERT(dump_file && *dump_file);
|
||||
|
||||
__debug_mem = (ACL_DEBUG_MEM*) calloc(1, sizeof(ACL_DEBUG_MEM));
|
||||
mem = (ACL_DEBUG_MEM*) calloc(1, sizeof(ACL_DEBUG_MEM));
|
||||
assert(mem);
|
||||
__debug_mem = mem;
|
||||
__debug_mem->dump_fp = fopen(dump_file, "wb+");
|
||||
ASSERT(__debug_mem->dump_fp);
|
||||
__debug_mem->table = debug_htable_create(1000);
|
||||
@ -272,5 +275,5 @@ ACL_DEBUG_MEM *acl_debug_malloc_init(ACL_DEBUG_MEM *debug_mem_ptr, const char *d
|
||||
acl_debug_memdup,
|
||||
acl_debug_free);
|
||||
|
||||
return (__debug_mem);
|
||||
return mem;
|
||||
}
|
||||
|
@ -251,6 +251,7 @@ void *acl_default_calloc(const char *filename, int line,
|
||||
#endif
|
||||
n = (int) (nmemb * size);
|
||||
ptr = acl_default_malloc(filename, line, n);
|
||||
assert(ptr);
|
||||
memset(ptr, FILLER, n);
|
||||
return ptr;
|
||||
}
|
||||
|
@ -41,12 +41,15 @@ static int __mem_stack = 0;
|
||||
#define MSTAT_LOCK thread_mutex_lock(&__fastmutex_stat)
|
||||
#define MSTAT_UNLOCK thread_mutex_unlock(&__fastmutex_stat)
|
||||
|
||||
void acl_memory_debug_start(void)
|
||||
int *acl_memory_debug_start(void)
|
||||
{
|
||||
__alloc_stat = calloc(__alloc_max, sizeof(int));
|
||||
acl_assert(__alloc_stat);
|
||||
int *ptr;
|
||||
ptr = calloc(__alloc_max, sizeof(int));
|
||||
__alloc_stat = ptr;
|
||||
assert(__alloc_stat);
|
||||
thread_mutex_init(&__fastmutex_stat, NULL);
|
||||
__debug_mem = 1;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void acl_memory_debug_stop(void)
|
||||
|
@ -1127,7 +1127,9 @@ ACL_SLICE *acl_slice_create(const char *name, int page_size,
|
||||
|
||||
void acl_slice_destroy(ACL_SLICE *slice)
|
||||
{
|
||||
slice->slice_destroy(slice);
|
||||
if (slice) {
|
||||
slice->slice_destroy(slice);
|
||||
}
|
||||
}
|
||||
|
||||
int acl_slice_used(ACL_SLICE *slice)
|
||||
|
@ -528,6 +528,8 @@ static int rfc1035_header_unpack(const char *buf, size_t sz, size_t *off,
|
||||
unsigned short s;
|
||||
unsigned short t;
|
||||
|
||||
assert(h);
|
||||
|
||||
if (*off != 0) {
|
||||
msg_error("%s: *off(%d) != 0", myname, (int) *off);
|
||||
return -RFC1035_UNPACK_ERROR;
|
||||
@ -634,7 +636,7 @@ static int rfc1035_query_unpack(const char *buf, size_t sz, size_t *off,
|
||||
*
|
||||
* Returns 0 (success) or 1 (error)
|
||||
*/
|
||||
static int rfc1035_rr_unpack(const char *buf, size_t sz, size_t *off, RFC1035_RR *RR)
|
||||
static int rfc1035_rr_unpack(const char *buf, size_t sz, size_t *off, RFC1035_RR *rr)
|
||||
{
|
||||
const char *myname = "rfc1035_rr_unpack";
|
||||
unsigned short s;
|
||||
@ -642,11 +644,11 @@ static int rfc1035_rr_unpack(const char *buf, size_t sz, size_t *off, RFC1035_RR
|
||||
unsigned short rdlength;
|
||||
size_t rdata_off;
|
||||
|
||||
if (rfc1035_name_unpack(buf, sz, off, NULL, RR->name,
|
||||
if (rfc1035_name_unpack(buf, sz, off, NULL, rr->name,
|
||||
RFC1035_MAXHOSTNAMESZ, 0)) {
|
||||
|
||||
RFC1035_UNPACK_DEBUG;
|
||||
memset(RR, '\0', sizeof(*RR));
|
||||
memset(rr, '\0', sizeof(*rr));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -655,21 +657,21 @@ static int rfc1035_rr_unpack(const char *buf, size_t sz, size_t *off, RFC1035_RR
|
||||
*/
|
||||
if ((*off) + 10 > sz) {
|
||||
RFC1035_UNPACK_DEBUG;
|
||||
memset(RR, '\0', sizeof(*RR));
|
||||
memset(rr, '\0', sizeof(*rr));
|
||||
return 1;
|
||||
}
|
||||
|
||||
memcpy(&s, buf + (*off), sizeof(s));
|
||||
(*off) += sizeof(s);
|
||||
RR->type = ntohs(s);
|
||||
rr->type = ntohs(s);
|
||||
|
||||
memcpy(&s, buf + (*off), sizeof(s));
|
||||
(*off) += sizeof(s);
|
||||
RR->tclass = ntohs(s);
|
||||
rr->tclass = ntohs(s);
|
||||
|
||||
memcpy(&i, buf + (*off), sizeof(i));
|
||||
(*off) += sizeof(i);
|
||||
RR->ttl = ntohl(i);
|
||||
rr->ttl = ntohl(i);
|
||||
|
||||
memcpy(&s, buf + (*off), sizeof(s));
|
||||
(*off) += sizeof(s);
|
||||
@ -680,24 +682,24 @@ static int rfc1035_rr_unpack(const char *buf, size_t sz, size_t *off, RFC1035_RR
|
||||
* replies at 512 octets, as per RFC 1035.
|
||||
*/
|
||||
RFC1035_UNPACK_DEBUG;
|
||||
memset(RR, '\0', sizeof(*RR));
|
||||
memset(rr, '\0', sizeof(*rr));
|
||||
return 1;
|
||||
}
|
||||
|
||||
RR->rdlength = rdlength;
|
||||
rr->rdlength = rdlength;
|
||||
|
||||
switch (RR->type) {
|
||||
switch (rr->type) {
|
||||
case RFC1035_TYPE_CNAME:
|
||||
case RFC1035_TYPE_NS:
|
||||
case RFC1035_TYPE_TXT:
|
||||
case RFC1035_TYPE_PTR:
|
||||
case RFC1035_TYPE_WKS:
|
||||
RR->rdata = (char*) malloc(RFC1035_MAXHOSTNAMESZ);
|
||||
rr->rdata = (char*) malloc(RFC1035_MAXHOSTNAMESZ);
|
||||
rdata_off = *off;
|
||||
RR->rdlength = 0; /* Filled in by rfc1035_name_unpack */
|
||||
rr->rdlength = 0; /* Filled in by rfc1035_name_unpack */
|
||||
|
||||
if (rfc1035_name_unpack(buf, sz, &rdata_off, &RR->rdlength,
|
||||
RR->rdata, RFC1035_MAXHOSTNAMESZ, 0)) {
|
||||
if (rfc1035_name_unpack(buf, sz, &rdata_off, &rr->rdlength,
|
||||
rr->rdata, RFC1035_MAXHOSTNAMESZ, 0)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -707,8 +709,8 @@ static int rfc1035_rr_unpack(const char *buf, size_t sz, size_t *off, RFC1035_RR
|
||||
* the RDATA area.
|
||||
*/
|
||||
RFC1035_UNPACK_DEBUG;
|
||||
free(RR->rdata);
|
||||
memset(RR, '\0', sizeof(*RR));
|
||||
free(rr->rdata);
|
||||
memset(rr, '\0', sizeof(*rr));
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
@ -716,8 +718,8 @@ static int rfc1035_rr_unpack(const char *buf, size_t sz, size_t *off, RFC1035_RR
|
||||
case RFC1035_TYPE_AAAA:
|
||||
case RFC1035_TYPE_MX:
|
||||
default:
|
||||
RR->rdata = (char*) malloc(rdlength);
|
||||
memcpy(RR->rdata, buf + (*off), rdlength);
|
||||
rr->rdata = (char*) malloc(rdlength);
|
||||
memcpy(rr->rdata, buf + (*off), rdlength);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -900,7 +902,7 @@ RFC1035_MESSAGE *rfc1035_request_unpack(const char *buf, size_t sz)
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static void rfc1035_rr_destroy(RFC1035_RR * rr, int n)
|
||||
static void rfc1035_rr_destroy(RFC1035_RR *rr, int n)
|
||||
{
|
||||
const char *myname = "rfc1035_rr_destroy";
|
||||
|
||||
|
@ -59,6 +59,7 @@ EVENT *event_create(int size)
|
||||
break;
|
||||
}
|
||||
|
||||
assert(ev);
|
||||
ring_init(&ev->events);
|
||||
ev->timeout = -1;
|
||||
ev->setsize = size;
|
||||
|
Loading…
Reference in New Issue
Block a user