Skip to content

Commit

Permalink
upmendex: avoid segmentation fault for unwritable fopen (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
t-tk committed Jun 13, 2021
1 parent e5de1f1 commit 9254c05
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions source/texk/upmendex/fwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,12 @@ void indwrite(char *filename, struct index *ind, int pagenum)
char lbuff[BUFFERLEN],obuff[BUFFERLEN];
UChar datama[256],initial[INITIALLENGTH],initial_prev[INITIALLENGTH];
int chset,chset_prev;
FILE *fp;
FILE *fp=NULL;
UErrorCode perr;

if (filename && kpse_out_name_ok(filename)) fp=fopen(filename,"wb");
else {
if (filename && kpse_out_name_ok(filename))
fp=fopen(filename,"wb");
if (fp == NULL) {
fp=stdout;
#ifdef WIN32
setmode(fileno(fp), _O_BINARY);
Expand Down Expand Up @@ -402,7 +403,7 @@ void indwrite(char *filename, struct index *ind, int pagenum)
}
fputs(postamble,fp);

if (filename) fclose(fp);
if (fp!=stdout) fclose(fp);
}

/* write page block */
Expand Down

0 comments on commit 9254c05

Please sign in to comment.