apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cliff Woolley <cliffwool...@yahoo.com>
Subject RE: [PATCH] apr_generate_random_bytes - WIN32
Date Tue, 30 Oct 2001 06:14:18 GMT
On Tue, 30 Oct 2001, Mladen Turk wrote:

> >  1    if (!CryptAcquireContext(&hProv,NULL,NULL,PROV_RSA_FULL,0)) {
> >  2        /* Try to create the new key container */
> >  3        if ((GetLastError() != NTE_BAD_KEYSET) ||
> >  4            (!CryptAcquireContext(&hProv,NULL,NULL,PROV_RSA_FULL,
> >  5                                  CRYPT_NEWKEYSET))) {
> >  6        	return apr_get_os_error();
> >  7        }
> >  8    }
>
> 1    if (!CryptAcquireContext(&hProv,NULL,NULL,PROV_RSA_FULL,0)) {
> 2        /* Try to create the new key container */
> 3        if (GetLastError() == NTE_BAD_KEYSET) {
> 4            if (!CryptAcquireContext(&hProv,NULL,NULL,PROV_RSA_FULL,
> 5                                  CRYPT_NEWKEYSET))
> 6        	return apr_get_os_error();
> 7        }
> 8        else
> 9        	return apr_get_os_error();
> 10    }
>

It's the same exact thing.  I just exploited the handy dandy
short-circuit boolean evaluation of C, which guarantees in my example that
if the one is !=, then the second CryptAcquireContext call will be
skipped.

Anyhow, yours might arguably be easier to read... so +1 to either variant
from the Win32 peanut gallery (I'm taking your word for it that this is
the right fix since I know next to nothing about the Win32 API... I'm just
saying +1 because I now believe the logic is correct).

--Cliff

--------------------------------------------------------------
   Cliff Woolley
   cliffwoolley@yahoo.com
   Charlottesville, VA



Mime
View raw message