Skip to content

Commit 36bb6d8

Browse files
authored
Merge pull request #38 from nwneetools/null-pointer
fix nullpointer issue for non-ignored includes and `-c` behavioral issues
2 parents 9af8318 + b464dc9 commit 36bb6d8

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

_NscLib/NscCodeGenerator.cpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,13 @@ bool CNscCodeGenerator::GenerateOutput (CNwnStream *pCodeOutput,
256256
// Add our main
257257
//
258258

259-
pSymbol ->ulFlags |= NscSymFlag_Referenced;
260-
m_anFunctions .push_back (m_pCtx ->GetSymbolOffset (pSymbol));
261-
GatherUsed (pSymbol);
262-
259+
if (pSymbol)
260+
{
261+
pSymbol->ulFlags |= NscSymFlag_Referenced;
262+
m_anFunctions.push_back(m_pCtx->GetSymbolOffset(pSymbol));
263+
GatherUsed(pSymbol);
264+
}
265+
263266
//
264267
// Initialize the stack depths
265268
//
@@ -598,9 +601,13 @@ bool CNscCodeGenerator::GenerateOutput (CNwnStream *pCodeOutput,
598601
return false;
599602

600603
//
601-
// Write the output
604+
// Write the output.
605+
// Return early if file is not executable.
602606
//
603607

608+
if (pSymbol == NULL)
609+
return true;
610+
604611
UINT32 ulSize = (UINT32) (m_pauchOut - m_pauchCode);
605612
WriteINT32 (&m_pauchCode [9], ulSize);
606613
pCodeOutput ->Write (m_pauchCode, m_pauchOut - m_pauchCode);

_NscLib/NscCompiler.cpp

+18-1
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,25 @@ NscResult NscCompileScript (CNwnLoader *pLoader, const char *pszName,
419419

420420
try
421421
{
422-
if (!sGen .GenerateOutput (pCodeOutput, pDebugOutput, fIgnoreIncludes))
422+
if (sGen .GenerateOutput (pCodeOutput, pDebugOutput, fIgnoreIncludes))
423+
{
424+
//
425+
// If using the -c flag, prevent creating a compiled file.
426+
//
427+
428+
if (!fIgnoreIncludes && !sCtx .HasMain ())
429+
{
430+
if (fAllocated)
431+
free (pauchData);
432+
return NscResult_Include;
433+
}
434+
}
435+
else
423436
return NscResult_Failure;
437+
438+
439+
//if (!sGen .GenerateOutput (pCodeOutput, pDebugOutput, fIgnoreIncludes))
440+
// return NscResult_Failure;
424441
}
425442
catch (std::exception)
426443
{

0 commit comments

Comments
 (0)