Opened on Jun 19, 2015 at 7:00:17 AM
Closed on Jun 22, 2015 at 2:18:02 AM
Last modified on Jun 22, 2015 at 7:32:13 AM
#3054 closed Bug (Fixed)
_Crypt_GenRandom always returns False and sets @error
| Reported by: | wraithdu | Owned by: | BrewManNH |
|---|---|---|---|
| Milestone: | 3.3.13.21 | Component: | Standard UDFs |
| Version: | 3.3.13.20 | Severity: | None |
| Keywords: | _crypt_genrandom | Cc: |
Description
The function sets $iError = @error + 10 without checking @error. Further, I see no documentation or reason for @error + 10 at all.
Func _Crypt_GenRandom($pBuffer, $iSize) _Crypt_Startup() Local $aRet = DllCall(__Crypt_DllHandle(), "bool", "CryptGenRandom", "handle", __Crypt_Context(), "dword", $iSize, "struct*", $pBuffer) Local $iError = @error + 10, $iExtended = @extended _Crypt_Shutdown() If $iError Or (Not $aRet[0]) Then Return SetError($iError, $iExtended, False) Else Return True EndIf EndFunc ;==>_Crypt_GenRandom
Attachments (0)
Change History (11)
comment:3 by , on Jun 20, 2015 at 3:34:10 AM
I found where it was changed in the repository. Not sure why it got changed the way it did, but easy enough to correct.
comment:4 by , on Jun 20, 2015 at 3:55:25 AM
| Milestone: | → 3.3.13.21 |
|---|---|
| Owner: | set to |
| Resolution: | → Fixed |
| Status: | new → closed |
Fixed by revision [11324] in version: 3.3.13.21
comment:5 by , on Jun 20, 2015 at 12:34:17 PM
In fact the + 10 if the $aRet[0] is non zero to insure the setting of a non zeror @error
comment:6 by , on Jun 20, 2015 at 2:17:50 PM
In every function in Crypt.au3 error return values are offset by distinct constant values; I guess it's to help locate where the error popped from.
comment:7 by , on Jun 22, 2015 at 1:02:32 AM
That doesn't explain why it is set that way, or when it was changed, or where it was documented. If you make a change like this, it needs to be documented.
By the way, if @error is zero, then setting it to 10 means that the next If statement will fire, and it will incorrectly return from the function with an error message. If you wanted to correct for any possible non-zero error, then you should be checking for zero first, and then change its value.
comment:8 by , on Jun 22, 2015 at 2:16:04 AM
| Resolution: | Fixed |
|---|---|
| Status: | closed → reopened |
comment:9 by , on Jun 22, 2015 at 2:18:02 AM
| Resolution: | → Fixed |
|---|---|
| Status: | reopened → closed |
Fixed by revision [11327] in version: 3.3.13.21
comment:10 by , on Jun 22, 2015 at 7:15:41 AM
Thanks ,
You right checking only @error instead of $iError was the smallest correction
comment:11 by , on Jun 22, 2015 at 7:32:13 AM
I never pretended it was the right way to handle errors and never said it wasn't a bug! And I never touched this code.

According to the header in the function, you wrote it, did someone change it after it was committed?