[PATCH] Fix uninitialized variable with wrong type

Kornel Benko kornel at lyx.org
Thu Sep 10 15:27:49 UTC 2020


Am Thu, 10 Sep 2020 15:30:18 +0300
schrieb Yuriy Skalko <yuriy.skalko at gmail.com>:

> > Am Wed, 9 Sep 2020 22:14:40 +0200
> > schrieb Kornel Benko <kor... at lyx.org>:
> >   
> >> > Since pclose (Unix) returns signed int and GetExitCodeProcess (Windows)
> >> > returns unsigned DWORD, and then result is compared with -1 in common
> >> > branch, now I don't see clean way to get rid of the warning in this mix
> >> > of conditional compilation branches. Let's leave as it is now.
> >> > 
> >> > There is similar mix of signed/unsigned in ForkedCalls.cpp (setRetValue
> >> > call) but without compiler warnings.
> >> > 
> >> > 
> >> > Yuriy
> >> >     
> >> 
> >> What about this?
> >> 
> >>       Kornel  
> > 
> > Forget it. Maybe this is better.
> >   
> 
> Yes, it solves this issue, but adding variable for this is not clean
> enough as for me :)
> Here is another not-so-clean solution with reinterpret_cast:
> 
> 
> diff --git a/src/support/filetools.cpp b/src/support/filetools.cpp
> index d6b27856cb..52a9ff950a 100644
> --- a/src/support/filetools.cpp
> +++ b/src/support/filetools.cpp
> @@ -1107,8 +1107,8 @@ cmd_ret const runCommand(string const & cmd)
> 
>  #if defined (_WIN32)
>  	WaitForSingleObject(process.hProcess, INFINITE);
> -	DWORD pret;
> -	if (!GetExitCodeProcess(process.hProcess, &pret))
> +	int pret = 0;
> +	if (!GetExitCodeProcess(process.hProcess,
> reinterpret_cast<LPDWORD>(&pret)))
>  		pret = -1;
>  	if (!infile.empty())
>  		CloseHandle(startup.hStdInput);
> 
> 
> 

Yes, but why do you think that 'LPDWORD' and 'int *' are (will be) always equivalent?
I am not expert though...

	Kornel

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: Digitale Signatur von OpenPGP
URL: <http://lists.lyx.org/pipermail/lyx-devel/attachments/20200910/7cabc825/attachment.asc>


More information about the lyx-devel mailing list