[liblouis-liblouisxml] bug in logging.c

  • From: Neil Soiffer <NeilS@xxxxxxxxxx>
  • To: liblouis-liblouisxml@xxxxxxxxxxxxx
  • Date: Wed, 7 Oct 2015 07:48:55 -0700

I'm working on updating MathPlayer on Windows (under Visual Studio 2015) to
use the latest releases of LibLouis and LibLouisUTDML. I found the
following problem in logging.c:

void EXPORT_CALL
lou_logEnd ()
{
if (logFile != NULL)
fclose (logFile);
logFile = NULL;
}

When logFile is stderr, doing an fclose on stderr causes a problem the next
time one tries to write to the logging file/stderr. I believe the test
should be

if (logFile != NULL && logFile != stderr)


Although I didn't see a problem with it, the function after that
(closeLogFile) should also probably have that test, and for safety's sake,
also have
logFile = NULL;

That then makes it identical to logEng, so it should just call that
function.


Also, for debugging, it would be better for make_makefile.c to have these
lines for CCFLAGS that turn on debugging info for a debug build:
"CCFLAGS = $(CCFLAGS) /nologo $(INCLUDES) /W1 /c /DLBULIB
/DLIBXML_STATIC",
"!ifdef DEBUG",
"CCFLAGS = $(CCFLAGS) /Zi",
"!else",
"CCFLAGS = $(CCFLAGS) /O2",
"!endif",

Similiarly, the linker flags would be better if they were
"LXCCFLAGS = $(LXCCFLAGS) /nologo /W1 /c /DLIBXML_STATIC",
"!ifdef DEBUG",
"LXCCFLAGS = $(LXCCFLAGS) /DEBUG",
"!endif",

Note that /O2 (current value) has no meaning to the Visual Studio linker.


Neil Soiffer
Senior Scientist
Design Science, Inc.
www.dessci.com

Other related posts: