Avoid using SEEK_END when possible

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6917 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
anders_k 2017-10-05 18:11:03 +00:00
parent 1ae118af99
commit 5f1651ab91
4 changed files with 44 additions and 53 deletions

View file

@ -721,9 +721,8 @@ int CEXEBuild::LoadLicenseFile(const TCHAR *file, TCHAR** pdata, const TCHAR *cm
}
FILE *f=strm.GetHandle();
UINT cbBOMOffset=ftell(f); // We might be positioned after a BOM
fseek(f,0,SEEK_END);
UINT cbFileData=ftell(f)-cbBOMOffset; // Size of file in bytes!
UINT32 cbFileSize=get_file_size32(f);
UINT cbFileData=(invalid_file_size32 == cbFileSize) ? 0 : cbFileSize - cbBOMOffset;
if (!cbFileData)
{
warning_fl(DW_LICENSE_EMPTY, _T("%") NPRIs _T(": empty license file \"%") NPRIs _T("\"\n"),cmdname,file);
@ -1972,28 +1971,15 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
int k=line.gettoken_enum(1, _T("all\0IDD_LICENSE\0IDD_DIR\0IDD_SELCOM\0IDD_INST\0IDD_INSTFILES\0IDD_UNINST\0IDD_VERIFY\0IDD_LICENSE_FSRB\0IDD_LICENSE_FSCB\0"));
if (k<0) PRINTHELP();
FILE *fui = FOPEN(line.gettoken_str(2), ("rb"));
if (!fui) {
ERROR_MSG(_T("Error: Can't open \"%") NPRIs _T("\"!\n"), line.gettoken_str(2));
return PS_ERROR;
}
MANAGE_WITH(fui, fclose);
fseek(fui, 0, SEEK_END);
unsigned int len = ftell(fui);
fseek(fui, 0, SEEK_SET);
LPBYTE ui = (LPBYTE) malloc(len);
if (!ui) {
ERROR_MSG(_T("Internal compiler error #12345: malloc(%d) failed\n"), len);
extern void quit(); quit();
}
MANAGE_WITH(ui, free);
if (fread(ui, 1, len, fui) != len) {
unsigned long uifilesize;
BYTE *uifiledata = alloc_and_read_file(line.gettoken_str(2), uifilesize);
if (!uifiledata) {
ERROR_MSG(_T("Error: Can't read \"%") NPRIs _T("\"!\n"), line.gettoken_str(2));
return PS_ERROR;
}
MANAGE_WITH(uifiledata, free);
CResourceEditor *uire = new CResourceEditor(ui, len);
CResourceEditor *uire = new CResourceEditor(uifiledata, uifilesize);
init_res_editor();
// Search for required items