소스 검색

core: mem - qmalloc - cast size to unsigned long in debug messages

- better for compatibility with C sepcs older than C99
- newer specs allow %zu, but 'z' specifier is not in older
  specs, %lu being the safer approach
Daniel-Constantin Mierla 9 년 전
부모
커밋
f17ac878a5
1개의 변경된 파일28개의 추가작업 그리고 16개의 파일을 삭제
  1. 28 16
      mem/q_malloc.c

+ 28 - 16
mem/q_malloc.c

@@ -188,8 +188,9 @@ struct qm_block* qm_malloc_init(char* address, unsigned long size, int type)
 	DBG("qm_malloc_init: QM_OPTIMIZE=%lu, /ROUNDTO=%lu\n",
 	DBG("qm_malloc_init: QM_OPTIMIZE=%lu, /ROUNDTO=%lu\n",
 			QM_MALLOC_OPTIMIZE, QM_MALLOC_OPTIMIZE/ROUNDTO);
 			QM_MALLOC_OPTIMIZE, QM_MALLOC_OPTIMIZE/ROUNDTO);
 	DBG("qm_malloc_init: QM_HASH_SIZE=%lu, qm_block size=%lu\n",
 	DBG("qm_malloc_init: QM_HASH_SIZE=%lu, qm_block size=%lu\n",
-			QM_HASH_SIZE, (long)sizeof(struct qm_block));
-	DBG("qm_malloc_init(%p, %lu), start=%p\n", address, size, start);
+			QM_HASH_SIZE, (unsigned long)sizeof(struct qm_block));
+	DBG("qm_malloc_init(%p, %lu), start=%p\n", address,
+			(unsigned long)size, start);
 	if (size<start-address) return 0;
 	if (size<start-address) return 0;
 	size-=(start-address);
 	size-=(start-address);
 	if (size <(MIN_FRAG_SIZE+FRAG_OVERHEAD)) return 0;
 	if (size <(MIN_FRAG_SIZE+FRAG_OVERHEAD)) return 0;
@@ -197,12 +198,14 @@ struct qm_block* qm_malloc_init(char* address, unsigned long size, int type)
 	
 	
 	init_overhead=ROUNDUP(sizeof(struct qm_block))+sizeof(struct qm_frag)+
 	init_overhead=ROUNDUP(sizeof(struct qm_block))+sizeof(struct qm_frag)+
 		sizeof(struct qm_frag_end);
 		sizeof(struct qm_frag_end);
-	DBG("qm_malloc_init: size= %lu, init_overhead=%lu\n", size, init_overhead);
+	DBG("qm_malloc_init: size= %lu, init_overhead=%lu\n",
+			(unsigned long)size, init_overhead);
 	
 	
 	if (size < init_overhead)
 	if (size < init_overhead)
 	{
 	{
 		/* not enough mem to create our control structures !!!*/
 		/* not enough mem to create our control structures !!!*/
-		LOG(L_ERR, "qm_malloc_init(%lu); No memory left to create control structures!\n", size);
+		LOG(L_ERR, "qm_malloc_init(%lu); No memory left to create control structures!\n",
+				(unsigned long)size);
 		return 0;
 		return 0;
 	}
 	}
 	end=start+size;
 	end=start+size;
@@ -286,7 +289,8 @@ static inline struct qm_frag* qm_find_free(struct qm_block* qm,
 	/*try in a bigger bucket*/
 	/*try in a bigger bucket*/
 	}
 	}
 	/* not found */
 	/* not found */
-	LOG(L_ERR, "qm_find_free(%p, %lu); Free fragment not found!\n", qm, size);
+	LOG(L_ERR, "qm_find_free(%p, %lu); Free fragment not found!\n",
+			qm, (unsigned long)size);
 	return 0;
 	return 0;
 }
 }
 
 
@@ -361,8 +365,8 @@ void* qm_malloc(void* qmp, size_t size)
 	
 	
 #ifdef DBG_QM_MALLOC
 #ifdef DBG_QM_MALLOC
 	list_cntr = 0;
 	list_cntr = 0;
-	MDBG("qm_malloc(%p, %lu) called from %s: %s(%d)\n", qm, size, file, func,
-			line);
+	MDBG("qm_malloc(%p, %lu) called from %s: %s(%d)\n",
+			qm, (unsigned long)size, file, func, line);
 #endif
 #endif
 	/*malloc(0) should return a valid pointer according to specs*/
 	/*malloc(0) should return a valid pointer according to specs*/
 	if(unlikely(size==0)) size=4;
 	if(unlikely(size==0)) size=4;
@@ -406,7 +410,8 @@ void* qm_malloc(void* qmp, size_t size)
 			FRAG_END(f)->check2=END_CHECK_PATTERN2;*/
 			FRAG_END(f)->check2=END_CHECK_PATTERN2;*/
 		MDBG("qm_malloc(%p, %lu) returns address %p frag. %p (size=%lu) on %d"
 		MDBG("qm_malloc(%p, %lu) returns address %p frag. %p (size=%lu) on %d"
 				" -th hit\n",
 				" -th hit\n",
-			 qm, size, (char*)f+sizeof(struct qm_frag), f, f->size, list_cntr );
+			 qm, (unsigned long)size, (char*)f+sizeof(struct qm_frag), f,
+			 f->size, list_cntr);
 #endif
 #endif
 #ifdef MALLOC_STATS
 #ifdef MALLOC_STATS
 		if(qm->type==MEM_TYPE_PKG) {
 		if(qm->type==MEM_TYPE_PKG) {
@@ -417,9 +422,11 @@ void* qm_malloc(void* qmp, size_t size)
 	}
 	}
 
 
 #ifdef DBG_QM_MALLOC
 #ifdef DBG_QM_MALLOC
-	LOG(L_ERR, "qm_malloc(%p, %lu) called from %s: %s(%d), module: %s; Free fragment not found!\n", qm, size, file, func, line, mname);
+	LOG(L_ERR, "qm_malloc(%p, %lu) called from %s: %s(%d), module: %s; Free fragment not found!\n",
+			qm, (unsigned long)size, file, func, line, mname);
 #else
 #else
-	LOG(L_ERR, "qm_malloc(%p, %lu); Free fragment not found!\n", qm, size);
+	LOG(L_ERR, "qm_malloc(%p, %lu); Free fragment not found!\n",
+			qm, (unsigned long)size);
 #endif
 #endif
 
 
 	return 0;
 	return 0;
@@ -568,7 +575,8 @@ void* qm_realloc(void* qmp, void* p, size_t size)
 	qm = (struct qm_block*)qmp;
 	qm = (struct qm_block*)qmp;
 
 
 #ifdef DBG_QM_MALLOC
 #ifdef DBG_QM_MALLOC
-	MDBG("qm_realloc(%p, %p, %lu) called from %s: %s(%d)\n", qm, p, size,
+	MDBG("qm_realloc(%p, %p, %lu) called from %s: %s(%d)\n",
+			qm, p, (unsigned long)size,
 			file, func, line);
 			file, func, line);
 	if ((p)&&(p>(void*)qm->last_frag_end || p<(void*)qm->first_frag)){
 	if ((p)&&(p>(void*)qm->last_frag_end || p<(void*)qm->first_frag)){
 		LOG(L_CRIT, "BUG: qm_free: bad pointer %p (out of memory block!) - "
 		LOG(L_CRIT, "BUG: qm_free: bad pointer %p (out of memory block!) - "
@@ -609,7 +617,8 @@ void* qm_realloc(void* qmp, void* p, size_t size)
 		orig_size=f->size;
 		orig_size=f->size;
 		/* shrink */
 		/* shrink */
 #ifdef DBG_QM_MALLOC
 #ifdef DBG_QM_MALLOC
-		MDBG("qm_realloc: shrinking from %lu to %lu\n", f->size, size);
+		MDBG("qm_realloc: shrinking from %lu to %lu\n",
+				f->size, (unsigned long)size);
 		if(split_frag(qm, f, size, file, "fragm. from qm_realloc", line, mname)!=0){
 		if(split_frag(qm, f, size, file, "fragm. from qm_realloc", line, mname)!=0){
 		MDBG("qm_realloc : shrinked successful\n");
 		MDBG("qm_realloc : shrinked successful\n");
 #else
 #else
@@ -626,7 +635,8 @@ void* qm_realloc(void* qmp, void* p, size_t size)
 	}else if (f->size < size){
 	}else if (f->size < size){
 		/* grow */
 		/* grow */
 #ifdef DBG_QM_MALLOC
 #ifdef DBG_QM_MALLOC
-		MDBG("qm_realloc: growing from %lu to %lu\n", f->size, size);
+		MDBG("qm_realloc: growing from %lu to %lu\n",
+				f->size, (unsigned long)size);
 #endif
 #endif
 			orig_size=f->size;
 			orig_size=f->size;
 			diff=size-f->size;
 			diff=size-f->size;
@@ -664,9 +674,11 @@ void* qm_realloc(void* qmp, void* p, size_t size)
 					memcpy(ptr, p, orig_size);
 					memcpy(ptr, p, orig_size);
 				} else {
 				} else {
 #ifdef DBG_QM_MALLOC
 #ifdef DBG_QM_MALLOC
-					LOG(L_ERR, "qm_realloc(%p, %lu) called from %s: %s(%d), module: %s; qm_malloc() failed!\n", qm, size, file, func, line, mname);
+					LOG(L_ERR, "qm_realloc(%p, %lu) called from %s: %s(%d), module: %s; qm_malloc() failed!\n",
+							qm, (unsigned long)size, file, func, line, mname);
 #else
 #else
-					LOG(L_ERR, "qm_realloc(%p, %lu); qm_malloc() failed!\n", qm, size);
+					LOG(L_ERR, "qm_realloc(%p, %lu); qm_malloc() failed!\n",
+							qm, (unsigned long)size);
 #endif
 #endif
 				}
 				}
 	#ifdef DBG_QM_MALLOC
 	#ifdef DBG_QM_MALLOC
@@ -680,7 +692,7 @@ void* qm_realloc(void* qmp, void* p, size_t size)
 		/* do nothing */
 		/* do nothing */
 #ifdef DBG_QM_MALLOC
 #ifdef DBG_QM_MALLOC
 		MDBG("qm_realloc: doing nothing, same size: %lu - %lu\n",
 		MDBG("qm_realloc: doing nothing, same size: %lu - %lu\n",
-				f->size, size);
+				f->size, (unsigned long)size);
 #endif
 #endif
 	}
 	}
 #ifdef DBG_QM_MALLOC
 #ifdef DBG_QM_MALLOC