From: DeaDDooMER Date: Tue, 19 Sep 2023 11:43:11 +0000 (+0300) Subject: dfwad: fix uninitilized pointer X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=a05470c9a8028d8355045211f9f4dfb0ab332f9a;p=d2df-editor.git dfwad: fix uninitilized pointer --- diff --git a/src/shared/WADEDITOR_dfwad.pas b/src/shared/WADEDITOR_dfwad.pas index 97097bb..2bbc03a 100644 --- a/src/shared/WADEDITOR_dfwad.pas +++ b/src/shared/WADEDITOR_dfwad.pas @@ -626,6 +626,7 @@ implementation begin nrec := LEtoN(s.ReadWord()); section := ''; + sec := nil; for i := 0 to nrec - 1 do begin s.ReadBuffer(name1251[0], 16); @@ -644,6 +645,8 @@ implementation begin if sec = nil then sec := InsertSectionRAW(''); + if res = nil then + raise Exception.Create('Failed to create root section'); res := InsertFileInfoS(sec, name, offset, csize, -1, nil); if res = nil then raise Exception.Create('Failed to register resource [' + section + '][' + name + ']'); @@ -671,24 +674,15 @@ implementation FreeWAD(); Result := False; try + s := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); try - s := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); - try - ReadFromStream(s); - FStream := s; - FLastError := DFWAD_NOERROR; - Result := True; - except - s.Free(); - raise; - end; + ReadFromStream(s); + FStream := s; + FLastError := DFWAD_NOERROR; + Result := True; except - on e: Exception do - begin - if gWADEditorLogLevel >= DFWAD_LOG_INFO then - e_WriteLog('DFWAD: Failed to read DFWAD from file ' + FileName + ', reason: ' + e.Message, MSG_WARNING); - Clear(); - end; + s.Free(); + raise; end; except on e: EFOpenError do @@ -700,6 +694,12 @@ implementation else FLastError := DFWAD_ERROR_WADNOTFOUND; end; + on e: Exception do + begin + if gWADEditorLogLevel >= DFWAD_LOG_INFO then + e_WriteLog('DFWAD: Failed to read DFWAD from file ' + FileName + ', reason: ' + e.Message, MSG_WARNING); + Clear(); + end; end; end;