- Makefile: don't produce unknown targets - libtcc.c: tcc_set_linker(): improve parser - tcc.h: tcc_internal_error(): don't record __FILE__ (for privacy reasons) - tccgen.c: - reject pointer + float operation - use 'int level' for builtin_frame/return_address - save_regs(): remove VT_ARRAY (confuses riscv64-gen) - tccpe.c: store just basename of loaded dlls (rather than full path) - tccpp.c: remove unused TAL defines - *-link.c: add missing ST_FUNC - i386-gen.c: fix thiscall - riscv64-asm.c/arm-asm.c: stay simple C89 - avoid .designators, decl after statement - avoid multiple instances of same static const objects - use skip() instead of next() & expect() - use cstr_printf() instead of snprintf() & cstr_cat() - tcc_error(), expect(): never return
Showing the changes to libtcc.c (1 of 20 files). Show all
Unified · Split
| @@ -201,7 +201,8 @@ ST_FUNC char *tcc_load_text(int fd) · 200 unmodified lines | ||
| 201 | 201 | { |
| 202 | 202 | int len = lseek(fd, 0, SEEK_END); |
| 203 | 203 | char *buf = load_data(fd, 0, len + 1); |
| 204 | − buf[len] = 0; | |
| 204 | + if (buf) | |
| 205 | + buf[len] = 0; | |
| 205 | 206 | return buf; |
| 206 | 207 | } |
| 207 | 208 | |
| @@ -336,7 +337,8 @@ PUB_FUNC void *tcc_malloc_debug(unsigned long size, const char *file, int line) · 128 unmodified lines | ||
| 336 | 337 | { |
| 337 | 338 | int ofs; |
| 338 | 339 | mem_debug_header_t *header; |
| 339 | − | |
| 340 | + if (!size) | |
| 341 | + return NULL; | |
| 340 | 342 | header = tcc_malloc(sizeof(mem_debug_header_t) + size); |
| 341 | 343 | header->magic1 = MEM_DEBUG_MAGIC1; |
| 342 | 344 | header->magic2 = MEM_DEBUG_MAGIC2; |
| @@ -346,7 +348,6 @@ PUB_FUNC void *tcc_malloc_debug(unsigned long size, const char *file, int line) · 3 unmodified lines | ||
| 346 | 348 | ofs = strlen(file) - MEM_DEBUG_FILE_LEN; |
| 347 | 349 | strncpy(header->file_name, file + (ofs > 0 ? ofs : 0), MEM_DEBUG_FILE_LEN); |
| 348 | 350 | header->file_name[MEM_DEBUG_FILE_LEN] = 0; |
| 349 | − | |
| 350 | 351 | WAIT_SEM(&mem_sem); |
| 351 | 352 | header->next = mem_debug_chain; |
| 352 | 353 | header->prev = NULL; |
| @@ -357,7 +358,6 @@ PUB_FUNC void *tcc_malloc_debug(unsigned long size, const char *file, int line) · 4 unmodified lines | ||
| 357 | 358 | if (mem_cur_size > mem_max_size) |
| 358 | 359 | mem_max_size = mem_cur_size; |
| 359 | 360 | POST_SEM(&mem_sem); |
| 360 | − | |
| 361 | 361 | return MEM_USER_PTR(header); |
| 362 | 362 | } |
| 363 | 363 | |
| @@ -367,7 +367,6 @@ PUB_FUNC void tcc_free_debug(void *ptr) · 3 unmodified lines | ||
| 367 | 367 | if (!ptr) |
| 368 | 368 | return; |
| 369 | 369 | header = malloc_check(ptr, "tcc_free"); |
| 370 | − | |
| 371 | 370 | WAIT_SEM(&mem_sem); |
| 372 | 371 | mem_cur_size -= header->size; |
| 373 | 372 | header->size = (unsigned)-1; |
| @@ -385,7 +384,8 @@ PUB_FUNC void *tcc_mallocz_debug(unsigned long size, const char *file, int line) · 11 unmodified lines | ||
| 385 | 384 | { |
| 386 | 385 | void *ptr; |
| 387 | 386 | ptr = tcc_malloc_debug(size,file,line); |
| 388 | − memset(ptr, 0, size); | |
| 387 | + if (size) | |
| 388 | + memset(ptr, 0, size); | |
| 389 | 389 | return ptr; |
| 390 | 390 | } |
| 391 | 391 | |
| @@ -393,10 +393,14 @@ PUB_FUNC void *tcc_realloc_debug(void *ptr, unsigned long size, const char *file · 1 unmodified line | ||
| 393 | 393 | { |
| 394 | 394 | mem_debug_header_t *header; |
| 395 | 395 | int mem_debug_chain_update = 0; |
| 396 | + | |
| 396 | 397 | if (!ptr) |
| 397 | 398 | return tcc_malloc_debug(size, file, line); |
| 399 | + if (!size) { | |
| 400 | + tcc_free_debug(ptr); | |
| 401 | + return NULL; | |
| 402 | + } | |
| 398 | 403 | header = malloc_check(ptr, "tcc_realloc"); |
| 399 | − | |
| 400 | 404 | WAIT_SEM(&mem_sem); |
| 401 | 405 | mem_cur_size -= header->size; |
| 402 | 406 | mem_debug_chain_update = (header == mem_debug_chain); |
| @@ -413,7 +417,6 @@ PUB_FUNC void *tcc_realloc_debug(void *ptr, unsigned long size, const char *file · 10 unmodified lines | ||
| 413 | 417 | if (mem_cur_size > mem_max_size) |
| 414 | 418 | mem_max_size = mem_cur_size; |
| 415 | 419 | POST_SEM(&mem_sem); |
| 416 | − | |
| 417 | 420 | return MEM_USER_PTR(header); |
| 418 | 421 | } |
| 419 | 422 | |
| @@ -441,6 +444,7 @@ PUB_FUNC void tcc_memcheck(int d) · 21 unmodified lines | ||
| 441 | 444 | } |
| 442 | 445 | fflush(stderr); |
| 443 | 446 | mem_cur_size = 0; |
| 447 | + mem_max_size = 0; | |
| 444 | 448 | mem_debug_chain = NULL; |
| 445 | 449 | #if MEM_DEBUG-0 == 2 |
| 446 | 450 | exit(2); |
| @@ -1425,24 +1429,24 @@ static int tcc_set_linker(TCCState *s, const char *option) · 978 unmodified lines | ||
| 1425 | 1429 | s->pe_stack_size = strtoul(p, &end, 10); |
| 1426 | 1430 | } else if (link_option(option, "subsystem=", &p)) { |
| 1427 | 1431 | #if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64) |
| 1428 | − if (!strcmp(p, "native")) { | |
| 1432 | + if (strstart("native", &p)) { | |
| 1429 | 1433 | s->pe_subsystem = 1; |
| 1430 | − } else if (!strcmp(p, "console")) { | |
| 1434 | + } else if (strstart("console", &p)) { | |
| 1431 | 1435 | s->pe_subsystem = 3; |
| 1432 | − } else if (!strcmp(p, "gui") || !strcmp(p, "windows")) { | |
| 1436 | + } else if (strstart("gui", &p) || strstart("windows", &p)) { | |
| 1433 | 1437 | s->pe_subsystem = 2; |
| 1434 | − } else if (!strcmp(p, "posix")) { | |
| 1438 | + } else if (strstart("posix", &p)) { | |
| 1435 | 1439 | s->pe_subsystem = 7; |
| 1436 | − } else if (!strcmp(p, "efiapp")) { | |
| 1440 | + } else if (strstart("efiapp", &p)) { | |
| 1437 | 1441 | s->pe_subsystem = 10; |
| 1438 | − } else if (!strcmp(p, "efiboot")) { | |
| 1442 | + } else if (strstart("efiboot", &p)) { | |
| 1439 | 1443 | s->pe_subsystem = 11; |
| 1440 | − } else if (!strcmp(p, "efiruntime")) { | |
| 1444 | + } else if (strstart("efiruntime", &p)) { | |
| 1441 | 1445 | s->pe_subsystem = 12; |
| 1442 | − } else if (!strcmp(p, "efirom")) { | |
| 1446 | + } else if (strstart("efirom", &p)) { | |
| 1443 | 1447 | s->pe_subsystem = 13; |
| 1444 | 1448 | #elif defined(TCC_TARGET_ARM) |
| 1445 | − if (!strcmp(p, "wince")) { | |
| 1449 | + if (strstart("wince", &p)) { | |
| 1446 | 1450 | s->pe_subsystem = 9; |
| 1447 | 1451 | #endif |
| 1448 | 1452 | } else |
| @@ -2211,3 +2215,9 @@ PUB_FUNC void tcc_print_stats(TCCState *s1, unsigned total_time) · 762 unmodified lines | ||
| 2211 | 2215 | fprintf(stderr, " %d max (bytes)\n", mem_max_size); |
| 2212 | 2216 | #endif |
| 2213 | 2217 | } |
| 2218 | + | |
| 2219 | +#if ONE_SOURCE | |
| 2220 | +# undef malloc | |
| 2221 | +# undef realloc | |
| 2222 | +# undef free | |
| 2223 | +#endif | |