Skip to content

Commit d6651c3

Browse files
authored
[BOX64] Fixed all true-positive GCC default warnings (#3309)
1 parent 80dafff commit d6651c3

35 files changed

+296
-450
lines changed

src/custommem.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ typedef struct blockmark_s {
133133
#define NEXT_BLOCK(b) (blockmark_t*)((uintptr_t)(b) + (b)->next.offs)
134134
#define PREV_BLOCK(b) (blockmark_t*)(((uintptr_t)(b) - (b)->prev.offs))
135135
#define LAST_BLOCK(b, s) (blockmark_t*)(((uintptr_t)(b)+(s))-sizeof(blockmark_t))
136-
#define SIZE_BLOCK(b) (((ssize_t)b.offs)-sizeof(blockmark_t))
136+
#define SIZE_BLOCK(b) ((size_t)(b).offs-sizeof(blockmark_t))
137137

138138
void printBlock(blockmark_t* b, void* start, size_t sz)
139139
{
@@ -195,7 +195,7 @@ static size_t getMaxFreeBlock(void* block, size_t block_size, void* start)
195195
// get start of block
196196
if(start) {
197197
blockmark_t *m = (blockmark_t*)start;
198-
ssize_t maxsize = 0;
198+
size_t maxsize = 0;
199199
while(m->next.x32) { // while there is a subblock
200200
if(!m->next.fill && SIZE_BLOCK(m->next)>maxsize) {
201201
maxsize = SIZE_BLOCK(m->next);
@@ -205,7 +205,7 @@ static size_t getMaxFreeBlock(void* block, size_t block_size, void* start)
205205
return maxsize;
206206
} else {
207207
blockmark_t *m = LAST_BLOCK(block, block_size); // start with the end
208-
ssize_t maxsize = 0;
208+
size_t maxsize = 0;
209209
while(m->prev.x32 && (((uintptr_t)block+maxsize)<(uintptr_t)m)) { // while there is a subblock
210210
if(!m->prev.fill && SIZE_BLOCK(m->prev)>maxsize) {
211211
maxsize = SIZE_BLOCK(m->prev);
@@ -388,7 +388,7 @@ int printBlockCoherent(int i)
388388
while(m->next.x32) {
389389
blockmark_t* n = NEXT_BLOCK(m);
390390
if(!m->next.fill && !n->next.fill && n!=last) {
391-
printf_log(LOG_NONE, "Chain contains 2 subsequent free blocks %p (%d) and %p (%d) for block %d\n", m, SIZE_BLOCK(m->next), n, SIZE_BLOCK(n->next), i);
391+
printf_log(LOG_NONE, "Chain contains 2 subsequent free blocks %p (%zu) and %p (%zu) for block %d\n", m, SIZE_BLOCK(m->next), n, SIZE_BLOCK(n->next), i);
392392
ret = 0;
393393
}
394394
m = n;
@@ -409,7 +409,7 @@ static char* niceSize(size_t sz)
409409
const char* units[] = {"b", "kb", "Mb", "Gb"};
410410
const size_t vals[] = {1, 1024, 1024*1024, 1024*1024*1024};
411411
int k = 0;
412-
for(int j=0; j<sizeof(vals)/sizeof(vals[0]); ++j)
412+
for(size_t j=0; j<sizeof(vals)/sizeof(vals[0]); ++j)
413413
if(vals[j]<sz)
414414
k = j;
415415
sprintf(rets[i], "%zd %s", sz/vals[k], units[k]);
@@ -658,7 +658,7 @@ void* map128_customMalloc(size_t size, int is32bits)
658658
p_blocks[i].size = allocsize;
659659
// setup marks
660660
uint8_t* map = p_blocks[i].first;
661-
for(int idx=(allocsize-mapsize)>>7; idx<(allocsize>>7); ++idx)
661+
for(size_t idx=(allocsize-mapsize)>>7; idx<(allocsize>>7); ++idx)
662662
map[idx>>3] |= (1<<(idx&7));
663663
// 32bits check - ensure entire allocation fits in 32-bit space
664664
if(is32bits && ((uintptr_t)p + allocsize > 0x100000000ULL)) {
@@ -719,7 +719,7 @@ void* map128_customMalloc(size_t size, int is32bits)
719719
// the bitmap itself is also allocated in that mapping, as a slice of 256bytes, at the end of the mapping (and so marked as allocated)
720720
void* map64_customMalloc(size_t size, int is32bits)
721721
{
722-
size = 64;
722+
size = 64; (void)size;
723723
mutex_lock(&mutex_blocks);
724724
// Try cached hint first
725725
if(last_block_index_map64 >= 0 && last_block_index_map64 < n_blocks) {
@@ -2967,11 +2967,11 @@ void reverveHigMem32(void)
29672967
printf_log(LOG_INFO, "Memory higher than 32bits reserved\n");
29682968
if (BOX64ENV(log)>=LOG_DEBUG) {
29692969
uintptr_t start=0x100000000LL;
2970-
int prot;
2970+
uint32_t prot;
29712971
uintptr_t bend = start;
29722972
while (bend!=0xffffffffffffffffLL) {
29732973
if(rb_get_end(mapallmem, start, &prot, &bend)) {
2974-
printf_log(LOG_NONE, " Reserved: %p - %p (%d)\n", (void*)start, (void*)bend, prot);
2974+
printf_log(LOG_NONE, " Reserved: %p - %p (%u)\n", (void*)start, (void*)bend, prot);
29752975
}
29762976
start = bend;
29772977
}

src/elfs/elfload_dump32.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,9 @@ void DumpSymTab32(elfheader_t *h)
251251
{
252252
if (BOX64ENV(dump) && h->SymTab._32) {
253253
const char* name = ElfName(h);
254-
printf_dump(LOG_NEVER, "ELF Dump SymTab(%d)=\n", h->numSymTab);
255-
for (int i=0; i<h->numSymTab; ++i)
256-
printf_dump(LOG_NEVER, " %s:SymTab[%d] = \"%s\", value=%p, size=%d, info/other=%d/%d index=%d\n", name,
254+
printf_dump(LOG_NEVER, "ELF Dump SymTab(%zu)=\n", h->numSymTab);
255+
for (size_t i=0; i<h->numSymTab; ++i)
256+
printf_dump(LOG_NEVER, " %s:SymTab[%zu] = \"%s\", value=%p, size=%d, info/other=%d/%d index=%d\n", name,
257257
i, h->StrTab+h->SymTab._32[i].st_name, from_ptrv(h->SymTab._32[i].st_value), h->SymTab._32[i].st_size,
258258
h->SymTab._32[i].st_info, h->SymTab._32[i].st_other, h->SymTab._32[i].st_shndx);
259259
printf_dump(LOG_NEVER, "ELF Dump SymTab=====\n");
@@ -264,7 +264,7 @@ void DumpDynamicSections32(elfheader_t *h)
264264
{
265265
if (BOX64ENV(dump) && h->Dynamic._32) {
266266
printf_dump(LOG_NEVER, "ELF Dump Dynamic(%d)=\n", h->numDynamic);
267-
for (int i=0; i<h->numDynamic; ++i)
267+
for (size_t i=0; i<h->numDynamic; ++i)
268268
printf_dump(LOG_NEVER, " Dynamic %04d : %s\n", i, DumpDynamic(h->Dynamic._32+i));
269269
printf_dump(LOG_NEVER, "ELF Dump Dynamic=====\n");
270270
}
@@ -274,10 +274,10 @@ void DumpDynSym32(elfheader_t *h)
274274
{
275275
if (BOX64ENV(dump) && h->DynSym._32) {
276276
const char* name = ElfName(h);
277-
printf_dump(LOG_NEVER, "ELF Dump DynSym(%d)=\n", h->numDynSym);
278-
for (int i=0; i<h->numDynSym; ++i) {
277+
printf_dump(LOG_NEVER, "ELF Dump DynSym(%zu)=\n", h->numDynSym);
278+
for (size_t i=0; i<h->numDynSym; ++i) {
279279
int version = h->VerSym?((Elf32_Half*)((uintptr_t)h->VerSym+h->delta))[i]:-1;
280-
printf_dump(LOG_NEVER, " %s:DynSym[%d] = %s\n", name, i, DumpSym(h, h->DynSym._32+i, version));
280+
printf_dump(LOG_NEVER, " %s:DynSym[%zu] = %s\n", name, i, DumpSym(h, h->DynSym._32+i, version));
281281
}
282282
printf_dump(LOG_NEVER, "ELF Dump DynSym=====\n");
283283
}
@@ -287,7 +287,7 @@ void DumpDynamicNeeded32(elfheader_t *h)
287287
{
288288
if (BOX64ENV(dump) && h->DynStrTab) {
289289
printf_dump(LOG_NEVER, "ELF Dump DT_NEEDED=====\n");
290-
for (int i=0; i<h->numDynamic; ++i)
290+
for (size_t i=0; i<h->numDynamic; ++i)
291291
if(h->Dynamic._32[i].d_tag==DT_NEEDED) {
292292
printf_dump(LOG_NEVER, " Needed : %s\n", h->DynStrTab+h->Dynamic._32[i].d_un.d_val + h->delta);
293293
}
@@ -299,7 +299,7 @@ void DumpDynamicRPath32(elfheader_t *h)
299299
{
300300
if (BOX64ENV(dump) && h->DynStrTab) {
301301
printf_dump(LOG_NEVER, "ELF Dump DT_RPATH/DT_RUNPATH=====\n");
302-
for (int i=0; i<h->numDynamic; ++i) {
302+
for (size_t i=0; i<h->numDynamic; ++i) {
303303
if(h->Dynamic._32[i].d_tag==DT_RPATH) {
304304
printf_dump(LOG_NEVER, " RPATH : %s\n", h->DynStrTab+h->Dynamic._32[i].d_un.d_val + h->delta);
305305
}
@@ -349,4 +349,3 @@ void DumpRelRTable32(elfheader_t *h, int cnt, Elf32_Relr *relr, const char* name
349349
printf_dump(LOG_NEVER, "ELF Dump %s Table=====\n", name);
350350
}
351351
}
352-

src/elfs/elfparser32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ elfheader_t* ParseElfHeader32(FILE* f, const char* name, int exec)
189189
// grab DT_REL & DT_RELA stuffs
190190
// also grab the DT_STRTAB string table
191191
{
192-
for (int i=0; i<h->numDynamic; ++i) {
192+
for (size_t i=0; i<h->numDynamic; ++i) {
193193
Elf32_Dyn d = h->Dynamic._32[i];
194194
Elf32_Word val = d.d_un.d_val;
195195
Elf32_Addr ptr = d.d_un.d_ptr;

src/emu/x64int3.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static void concatString(char* buff, int len, void* s, const char* trail)
108108
{
109109
char tmp[len];
110110
if(!s) snprintf(tmp, len-1, "%p%s", s, trail);
111-
else snprintf(tmp, len-1, "%p\"%s\"%s", s, s, trail);
111+
else snprintf(tmp, len-1, "%p\"%s\"%s", s, (char*)s, trail);
112112
strncat(buff, tmp, len);
113113
}
114114

@@ -416,6 +416,7 @@ void x64Int3(x64emu_t* emu, uintptr_t* addr)
416416
uint8_t type = *(uint8_t*)(R_RAX);
417417
snprintf(buff2, 64, "[type=%d]", type);
418418
}
419+
break;
419420
case 100:
420421
snprintf(buff2, 64, "[function: %p]", (void*)R_RIP);
421422
break;

0 commit comments

Comments
 (0)