History

tccpp.c: Guard against ppfp being NULL

Missed these in e946eb2a4109e0de5f8514457f851897a4824c3e

Vlad Vissoultchev committed 10 years ago

Commit 810a6771 parent 6a49afb2 files · +18 −24Browse files

Unified · Split

2 files
  1. tcc.c +2 −7
  2. tccpp.c +16 −17
tcc.c+2−7
@@ -303,13 +303,8 @@ int main(int argc, char **argv) · 302 unmodified lines
303303 tcc_error("could not write '%s'", s->outfile);
304304 }
305305 s->dffp = s->ppfp;
306− if (s->dflag == 'M') {
307−#ifndef TCC_TARGET_PE
308− s->ppfp = fopen("/dev/null", "w");
309−#else
310− s->ppfp = fopen("nul", "w");
311−#endif
312− }
306+ if (s->dflag == 'M')
307+ s->ppfp = NULL;
313308 }
314309
315310 tcc_set_output_type(s, s->output_type);
tccpp.c+16−17
@@ -1072,20 +1072,18 @@ static int macro_is_equal(const int *a, const int *b) · 1071 unmodified lines
10721072
10731073 static void pp_line(TCCState *s1, BufferedFile *f, int level)
10741074 {
1075− int d = f->line_num - f->line_ref;
1076− if (s1->Pflag == LINE_MACRO_OUTPUT_FORMAT_NONE
1077− || (level == 0 && f->line_ref && d < 8))
1078− {
1079− while (d > 0)
1080− fputs("\n", s1->ppfp), --d;
1081− }
1082− else
1083− if (s1->Pflag == LINE_MACRO_OUTPUT_FORMAT_STD) {
1084− fprintf(s1->ppfp, "#line %d \"%s\"\n", f->line_num, f->filename);
1085− }
1086− else {
1087− fprintf(s1->ppfp, "# %d \"%s\"%s\n", f->line_num, f->filename,
1088− level > 0 ? " 1" : level < 0 ? " 2" : "");
1075+ if (s1->ppfp) {
1076+ int d = f->line_num - f->line_ref;
1077+ if (s1->Pflag == LINE_MACRO_OUTPUT_FORMAT_NONE
1078+ || (level == 0 && f->line_ref && d < 8)) {
1079+ while (d > 0)
1080+ fputs("\n", s1->ppfp), --d;
1081+ } else if (s1->Pflag == LINE_MACRO_OUTPUT_FORMAT_STD) {
1082+ fprintf(s1->ppfp, "#line %d \"%s\"\n", f->line_num, f->filename);
1083+ } else {
1084+ fprintf(s1->ppfp, "# %d \"%s\"%s\n", f->line_num, f->filename,
1085+ level > 0 ? " 1" : level < 0 ? " 2" : "");
1086+ }
10891087 }
10901088 f->line_ref = f->line_num;
10911089 }
@@ -3473,16 +3471,17 @@ ST_FUNC int tcc_preprocess(TCCState *s1) · 2381 unmodified lines
34733471 continue;
34743472 }
34753473 pp_line(s1, file, 0);
3476− while (spcs)
3474+ while (s1->ppfp && spcs > 0)
34773475 fputs(" ", s1->ppfp), --spcs;
3476+ spcs = 0;
34783477 token_seen = 1;
34793478
34803479 } else if (tok == TOK_LINEFEED) {
34813480 ++file->line_ref;
34823481 token_seen = 0;
34833482 }
3484−
3485− fputs(get_tok_str(tok, &tokc), s1->ppfp);
3483+ if (s1->ppfp)
3484+ fputs(get_tok_str(tok, &tokc), s1->ppfp);
34863485 }
34873486
34883487 return 0;

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