bootstrappable: mescc bug: sizeof expr.

This commit is contained in:
Jan Nieuwenhuizen 2017-11-16 07:49:01 +01:00
parent 3e09b10573
commit 5df456f020
2 changed files with 11 additions and 8 deletions

View File

@ -1971,8 +1971,8 @@ static void tidy_section_headers(TCCState *s1, int *sec_order)
Section **snew, *s;
ElfW(Sym) *sym;
snew = tcc_malloc(s1->nb_sections * sizeof(snew[0]));
backmap = tcc_malloc(s1->nb_sections * sizeof(backmap[0]));
snew = tcc_malloc(s1->nb_sections * sizeof(struct Section*));
backmap = tcc_malloc(s1->nb_sections * sizeof(int));
for (i = 0, nnew = 0, l = s1->nb_sections; i < s1->nb_sections; i++) {
s = s1->sections[sec_order[i]];
if (!i || s->sh_name) {

15
tccpp.c
View File

@ -1751,7 +1751,7 @@ ST_FUNC void preprocess(int is_bof)
inp();
q = buf;
while (ch != c && ch != '\n' && ch != CH_EOF) {
if ((q - buf) < sizeof(buf) - 1)
if ((q - buf) < 1024 - 1)
*q++ = ch;
if (ch == '\\') {
if (handle_stray_noerror() == 0)
@ -1778,7 +1778,7 @@ ST_FUNC void preprocess(int is_bof)
next();
buf[0] = '\0';
while (tok != TOK_LINEFEED) {
pstrcat(buf, sizeof(buf), get_tok_str(tok, &tokc));
pstrcat(buf, 1024, get_tok_str(tok, &tokc));
next();
}
len = strlen(buf);
@ -1820,11 +1820,11 @@ ST_FUNC void preprocess(int is_bof)
/* search in all the include paths */
int j = i - 2, k = j - s1->nb_include_paths;
path = k < 0 ? s1->include_paths[j] : s1->sysinclude_paths[k];
pstrcpy(buf1, sizeof(buf1), path);
pstrcat(buf1, sizeof(buf1), "/");
pstrcpy(buf1, sizeof (file->filename), path);
pstrcat(buf1, sizeof (file->filename), "/");
}
pstrcat(buf1, sizeof(buf1), buf);
pstrcat(buf1, sizeof (file->filename), buf);
e = search_cached_include(s1, buf1, 0);
if (e && (define_find(e->ifndef_macro) || e->once == pp_once)) {
/* no need to parse the include because the 'ifndef macro'
@ -1835,8 +1835,11 @@ ST_FUNC void preprocess(int is_bof)
goto include_done;
}
if (tcc_open(s1, buf1) < 0)
trace ("preprocess 80 buf1="); eputs (buf1); eputs ("\n");
if (tcc_open(s1, buf1) < 0) {
trace ("preprocess not found="); eputs (buf1); eputs ("\n");
continue;
}
file->include_next_index = i + 1;
#ifdef INC_DEBUG