[ovs-dev] [PATCH] windows pseudorandom number generator

Ben Pfaff blp at nicira.com
Tue Dec 17 07:54:06 UTC 2013


On Mon, Dec 16, 2013 at 05:13:59PM +0000, Alin Serdean wrote:
> I can put in the ernno for the error but the problem is CryptGenRandom
> does not set the error number.

OK.

> So it is either just print the value of GetLastError() or I use
> FormatMessage function to get the text from that value. Like the
> following:

I think it would be better to format the error.

> +    if (!CryptGenRandom(crypt_prov, n, buffer)) {
> +        error = GetLastError();
> +        LPVOID msg_buf;

Please put declarations before statements within a block, as CodingStyle
requires.

> +        FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
> +                       FORMAT_MESSAGE_FROM_SYSTEM |
> +                       FORMAT_MESSAGE_IGNORE_INSERTS,
> +                       NULL,
> +                       error,
> +                       0,
> +                       (LPTSTR)&msg_buf,
> +                       0,
> +                       NULL
> +                       );
> +        VLOG_ERR("CryptGenRandom: read error (%s)", msg_buf);
> +        LocalFree(msg_buf);

The caller still needs an errno value, so probably one should pick some
reasonable value (e.g. EINVAL?) here and use that one.

> +    }
> +
> +    CryptReleaseContext(crypt_prov, 0);
> +#endif
>      return error;
>  }
> 
> Would you like me to set up a helper function like
> ovs_retval_to_string (i.e. ovs_getlasterror_to_string) or just leave
> it the way it is for the moment?

I'm happy either way for the moment, but I guess this will come up
again and then a helper would be a good idea.

Thanks,

Ben.



More information about the dev mailing list