History

div fixes

- 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

grischka committed 2 years ago

Commit 6b78e561 parent 3b943be20 files · +227 −508Browse files

Showing the changes to libtcc.c (1 of 20 files). Show all

Unified · Split

libtcc.c+27−17
@@ -201,7 +201,8 @@ ST_FUNC char *tcc_load_text(int fd) · 200 unmodified lines
201201 {
202202 int len = lseek(fd, 0, SEEK_END);
203203 char *buf = load_data(fd, 0, len + 1);
204− buf[len] = 0;
204+ if (buf)
205+ buf[len] = 0;
205206 return buf;
206207 }
207208
@@ -336,7 +337,8 @@ PUB_FUNC void *tcc_malloc_debug(unsigned long size, const char *file, int line) · 128 unmodified lines
336337 {
337338 int ofs;
338339 mem_debug_header_t *header;
339−
340+ if (!size)
341+ return NULL;
340342 header = tcc_malloc(sizeof(mem_debug_header_t) + size);
341343 header->magic1 = MEM_DEBUG_MAGIC1;
342344 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
346348 ofs = strlen(file) - MEM_DEBUG_FILE_LEN;
347349 strncpy(header->file_name, file + (ofs > 0 ? ofs : 0), MEM_DEBUG_FILE_LEN);
348350 header->file_name[MEM_DEBUG_FILE_LEN] = 0;
349−
350351 WAIT_SEM(&mem_sem);
351352 header->next = mem_debug_chain;
352353 header->prev = NULL;
@@ -357,7 +358,6 @@ PUB_FUNC void *tcc_malloc_debug(unsigned long size, const char *file, int line) · 4 unmodified lines
357358 if (mem_cur_size > mem_max_size)
358359 mem_max_size = mem_cur_size;
359360 POST_SEM(&mem_sem);
360−
361361 return MEM_USER_PTR(header);
362362 }
363363
@@ -367,7 +367,6 @@ PUB_FUNC void tcc_free_debug(void *ptr) · 3 unmodified lines
367367 if (!ptr)
368368 return;
369369 header = malloc_check(ptr, "tcc_free");
370−
371370 WAIT_SEM(&mem_sem);
372371 mem_cur_size -= header->size;
373372 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
385384 {
386385 void *ptr;
387386 ptr = tcc_malloc_debug(size,file,line);
388− memset(ptr, 0, size);
387+ if (size)
388+ memset(ptr, 0, size);
389389 return ptr;
390390 }
391391
@@ -393,10 +393,14 @@ PUB_FUNC void *tcc_realloc_debug(void *ptr, unsigned long size, const char *file · 1 unmodified line
393393 {
394394 mem_debug_header_t *header;
395395 int mem_debug_chain_update = 0;
396+
396397 if (!ptr)
397398 return tcc_malloc_debug(size, file, line);
399+ if (!size) {
400+ tcc_free_debug(ptr);
401+ return NULL;
402+ }
398403 header = malloc_check(ptr, "tcc_realloc");
399−
400404 WAIT_SEM(&mem_sem);
401405 mem_cur_size -= header->size;
402406 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
413417 if (mem_cur_size > mem_max_size)
414418 mem_max_size = mem_cur_size;
415419 POST_SEM(&mem_sem);
416−
417420 return MEM_USER_PTR(header);
418421 }
419422
@@ -441,6 +444,7 @@ PUB_FUNC void tcc_memcheck(int d) · 21 unmodified lines
441444 }
442445 fflush(stderr);
443446 mem_cur_size = 0;
447+ mem_max_size = 0;
444448 mem_debug_chain = NULL;
445449 #if MEM_DEBUG-0 == 2
446450 exit(2);
@@ -1425,24 +1429,24 @@ static int tcc_set_linker(TCCState *s, const char *option) · 978 unmodified lines
14251429 s->pe_stack_size = strtoul(p, &end, 10);
14261430 } else if (link_option(option, "subsystem=", &p)) {
14271431 #if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64)
1428− if (!strcmp(p, "native")) {
1432+ if (strstart("native", &p)) {
14291433 s->pe_subsystem = 1;
1430− } else if (!strcmp(p, "console")) {
1434+ } else if (strstart("console", &p)) {
14311435 s->pe_subsystem = 3;
1432− } else if (!strcmp(p, "gui") || !strcmp(p, "windows")) {
1436+ } else if (strstart("gui", &p) || strstart("windows", &p)) {
14331437 s->pe_subsystem = 2;
1434− } else if (!strcmp(p, "posix")) {
1438+ } else if (strstart("posix", &p)) {
14351439 s->pe_subsystem = 7;
1436− } else if (!strcmp(p, "efiapp")) {
1440+ } else if (strstart("efiapp", &p)) {
14371441 s->pe_subsystem = 10;
1438− } else if (!strcmp(p, "efiboot")) {
1442+ } else if (strstart("efiboot", &p)) {
14391443 s->pe_subsystem = 11;
1440− } else if (!strcmp(p, "efiruntime")) {
1444+ } else if (strstart("efiruntime", &p)) {
14411445 s->pe_subsystem = 12;
1442− } else if (!strcmp(p, "efirom")) {
1446+ } else if (strstart("efirom", &p)) {
14431447 s->pe_subsystem = 13;
14441448 #elif defined(TCC_TARGET_ARM)
1445− if (!strcmp(p, "wince")) {
1449+ if (strstart("wince", &p)) {
14461450 s->pe_subsystem = 9;
14471451 #endif
14481452 } else
@@ -2211,3 +2215,9 @@ PUB_FUNC void tcc_print_stats(TCCState *s1, unsigned total_time) · 762 unmodified lines
22112215 fprintf(stderr, " %d max (bytes)\n", mem_max_size);
22122216 #endif
22132217 }
2218+
2219+#if ONE_SOURCE
2220+# undef malloc
2221+# undef realloc
2222+# undef free
2223+#endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t