History

safety: replace occurrences of strcpy by pstrcpy

grischka committed 13 years ago

Commit 2f6b8461 parent 370547a4 files · +11 −21Browse files

Unified · Split

4 files
  1. libtcc.c +1 −1
  2. tccelf.c +6 −16
  3. tccgen.c +1 −1
  4. tccpe.c +3 −3
libtcc.c+1−1
@@ -1636,7 +1636,7 @@ PUB_FUNC char *tcc_default_target(TCCState *s, const char *default_file) · 1635 unmodified lines
1636 && *ext)1636 && *ext)
1637 strcpy(ext, ".o");1637 strcpy(ext, ".o");
1638 else1638 else
1639 pstrcpy(buf, sizeof(buf), "a.out");1639 strcpy(buf, "a.out");
1640 1640
1641 return tcc_strdup(buf);1641 return tcc_strdup(buf);
1642}1642}
tccelf.c+6−16
@@ -2992,20 +2992,6 @@ static int ld_next(TCCState *s1, char *name, int name_size) · 2991 unmodified lines
2992 return c;2992 return c;
2993}2993}
2994 2994
2995/*
2996 * Extract the file name from the library name
2997 *
2998 * /!\ No test on filename capacity, be careful
2999 */
3000static void libname_to_filename(TCCState *s1, const char libname[], char filename[])
3001{
3002 if (!s1->static_link) {
3003 sprintf(filename, "lib%s.so", libname);
3004 } else {
3005 sprintf(filename, "lib%s.a", libname);
3006 }
3007}
3008
3009static int ld_add_file(TCCState *s1, const char filename[])2995static int ld_add_file(TCCState *s1, const char filename[])
3010{2996{
3011 int ret;2997 int ret;
@@ -3052,8 +3038,12 @@ static int ld_add_file_list(TCCState *s1, const char *cmd, int as_needed) · 40 unmodified lines
3052 ret = -1;3038 ret = -1;
3053 goto lib_parse_error;3039 goto lib_parse_error;
3054 }3040 }
3055 strcpy(libname, &filename[1]);3041 pstrcpy(libname, sizeof libname, &filename[1]);
3056 libname_to_filename(s1, libname, filename);3042 if (s1->static_link) {
3043 snprintf(filename, sizeof filename, "lib%s.a", libname);
3044 } else {
3045 snprintf(filename, sizeof filename, "lib%s.so", libname);
3046 }
3057 } else if (t != LD_TOK_NAME) {3047 } else if (t != LD_TOK_NAME) {
3058 tcc_error_noabort("filename expected");3048 tcc_error_noabort("filename expected");
3059 ret = -1;3049 ret = -1;
tccgen.c+1−1
@@ -5580,7 +5580,7 @@ ST_FUNC void gen_inline_functions(void) · 5579 unmodified lines
5580 str = fn->token_str;5580 str = fn->token_str;
5581 fn->sym = NULL;5581 fn->sym = NULL;
5582 if (file)5582 if (file)
5583 strcpy(file->filename, fn->filename);5583 pstrcpy(file->filename, sizeof file->filename, fn->filename);
5584 sym->r = VT_SYM | VT_CONST;5584 sym->r = VT_SYM | VT_CONST;
5585 sym->type.t &= ~VT_INLINE;5585 sym->type.t &= ~VT_INLINE;
5586 5586
tccpe.c+3−3
@@ -663,7 +663,7 @@ static int pe_write(struct pe_info *pe) · 662 unmodified lines
663 }663 }
664 }664 }
665 665
666 strcpy((char*)psh->Name, sh_name);666 pstrcpy((char*)psh->Name, sizeof psh->Name, sh_name);
667 667
668 psh->Characteristics = pe_sec_flags[si->cls];668 psh->Characteristics = pe_sec_flags[si->cls];
669 psh->VirtualAddress = addr;669 psh->VirtualAddress = addr;
@@ -933,7 +933,7 @@ static void pe_build_exports(struct pe_info *pe) · 263 unmodified lines
933 933
934#if 1934#if 1
935 /* automatically write exports to <output-filename>.def */935 /* automatically write exports to <output-filename>.def */
936 strcpy(buf, pe->filename);936 pstrcpy(buf, sizeof buf, pe->filename);
937 strcpy(tcc_fileextension(buf), ".def");937 strcpy(tcc_fileextension(buf), ".def");
938 op = fopen(buf, "w");938 op = fopen(buf, "w");
939 if (NULL == op) {939 if (NULL == op) {
@@ -1598,7 +1598,7 @@ static int pe_load_def(TCCState *s1, FILE *fp) · 658 unmodified lines
1598 case 0:1598 case 0:
1599 if (0 != strnicmp(p, "LIBRARY", 7))1599 if (0 != strnicmp(p, "LIBRARY", 7))
1600 goto quit;1600 goto quit;
1601 strcpy(dllname, trimfront(p+7));1601 pstrcpy(dllname, sizeof dllname, trimfront(p+7));
1602 ++state;1602 ++state;
1603 continue;1603 continue;
1604 1604

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