From 9254c05fe87dee7f2cb10c88489787a84711e242 Mon Sep 17 00:00:00 2001 From: TANAKA Takuji Date: Sun, 13 Jun 2021 13:09:43 +0900 Subject: [PATCH] upmendex: avoid segmentation fault for unwritable fopen (#119) --- source/texk/upmendex/fwrite.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/texk/upmendex/fwrite.c b/source/texk/upmendex/fwrite.c index 5308c6910..7224fc7a8 100644 --- a/source/texk/upmendex/fwrite.c +++ b/source/texk/upmendex/fwrite.c @@ -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); @@ -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 */