diff --git a/Source/exehead/exec.c b/Source/exehead/exec.c index 4956985e..352df5fa 100644 --- a/Source/exehead/exec.c +++ b/Source/exehead/exec.c @@ -1406,7 +1406,6 @@ static int NSISCALL ExecuteEntry(entry *entry_) #endif { TCHAR *textout=var1; - DWORD dw; int rpos=0; TCHAR *hptr=var0; int maxlen=GetIntFromParm(2); @@ -1427,17 +1426,17 @@ static int NSISCALL ExecuteEntry(entry *entry_) And what if the multibyte character needs two WCHARs? */ char tmpc; - if (!ReadFile(h,&tmpc,1,&dw,NULL) || dw != 1) break; + if (!myReadFile(h,&tmpc,1)) break; if (0==MultiByteToWideChar(CP_ACP, 0, &tmpc, 1, &c, 1)) c = _T('?'); } else #endif { - if (!ReadFile(h,&c,1,&dw,NULL) || dw != 1) break; + if (!myReadFile(h,&c,1)) break; } if (parm3) { - myitoa(textout,(unsigned int)(_TUCHAR)c); + myitoa(textout,(unsigned char)c); return 0; } if (lc == _T('\r') || lc == _T('\n')) diff --git a/Source/exehead/fileform.c b/Source/exehead/fileform.c index cc72dcb4..2d3dcb48 100644 --- a/Source/exehead/fileform.c +++ b/Source/exehead/fileform.c @@ -540,7 +540,7 @@ int NSISCALL _dodecomp(int offset, HANDLE hFileOut, unsigned char *outbuf, int o retval=__ensuredata(sizeof(int)); if (retval<0) return retval; - if (!ReadFile(dbd_hFile,(LPVOID)&input_len,sizeof(int),&r,NULL) || r!=sizeof(int)) return -3; + if (!myReadFile(dbd_hFile,(LPVOID)&input_len,sizeof(int))) return -3; dbd_pos+=sizeof(int); retval=__ensuredata(input_len); @@ -552,7 +552,7 @@ int NSISCALL _dodecomp(int offset, HANDLE hFileOut, unsigned char *outbuf, int o { DWORD t; DWORD l=min(input_len,IBUFSIZE); - if (!ReadFile(dbd_hFile,(LPVOID)_inbuffer,l,&r,NULL) || l != r) return -3; + if (!myReadFile(dbd_hFile,(LPVOID)_inbuffer,r=l)) return -3; if (!WriteFile(hFileOut,_inbuffer,r,&t,NULL) || t != l) return -2; retval+=r; input_len-=r; @@ -571,8 +571,7 @@ int NSISCALL _dodecomp(int offset, HANDLE hFileOut, unsigned char *outbuf, int o BOOL NSISCALL ReadSelfFile(LPVOID lpBuffer, DWORD nNumberOfBytesToRead) { - DWORD rd; - return ReadFile(g_db_hFile,lpBuffer,nNumberOfBytesToRead,&rd,NULL) && (rd == nNumberOfBytesToRead); + return myReadFile(g_db_hFile,lpBuffer,nNumberOfBytesToRead); } DWORD NSISCALL SetSelfFilePointer(LONG lDistanceToMove) diff --git a/Source/exehead/util.c b/Source/exehead/util.c index c2c77e84..81cb2ef7 100644 --- a/Source/exehead/util.c +++ b/Source/exehead/util.c @@ -449,6 +449,13 @@ TCHAR * NSISCALL my_GetTempFileName(TCHAR *buf, const TCHAR *dir) return 0; } +BOOL NSISCALL myReadFile(HANDLE h, LPVOID buf, DWORD cb) +{ + DWORD cbio; + BOOL r = ReadFile(h, buf, cb, &cbio, NULL); + return r && cb == cbio; +} + #ifdef NSIS_SUPPORT_MOVEONREBOOT /** Modifies the wininit.ini file to rename / delete a file. * @@ -503,7 +510,7 @@ void RenameViaWininit(const TCHAR* prevName, const TCHAR* newName) if (pszWinInit != NULL) { - if (ReadFile(hfile, pszWinInit, dwFileSize, &dwBytes, NULL) && dwFileSize == dwBytes) + if (myReadFile(hfile, pszWinInit, dwFileSize)) { // Look for the rename section in the current file. LPSTR pszRenameSecInFile = mystrstriA(pszWinInit, szRenameSec); diff --git a/Source/exehead/util.h b/Source/exehead/util.h index a81e02a4..f0c46b31 100644 --- a/Source/exehead/util.h +++ b/Source/exehead/util.h @@ -41,6 +41,7 @@ TCHAR * NSISCALL mystrcat(TCHAR *out, const TCHAR *concat); TCHAR * NSISCALL mystrstr(TCHAR *a, TCHAR *b); WIN32_FIND_DATA * NSISCALL file_exists(TCHAR *buf); TCHAR * NSISCALL my_GetTempFileName(TCHAR *buf, const TCHAR *dir); +BOOL NSISCALL myReadFile(HANDLE h, LPVOID buf, DWORD cb); //BOOL NSISCALL my_SetWindowText(HWND hWnd, const TCHAR *val); #define my_SetWindowText SetWindowText