#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:1 Changed 10 years ago by BrewManNH
comment:2 Changed 10 years ago by wraithdu
Yep. My original version is in ticket #2263.
comment:3 Changed 10 years ago by BrewManNH
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 Changed 10 years ago by BrewManNH
- Milestone set to 3.3.13.21
- Owner set to BrewManNH
- Resolution set to Fixed
- Status changed from new to closed
Fixed by revision [11324] in version: 3.3.13.21
comment:5 Changed 10 years ago by Jpm
In fact the + 10 if the $aRet[0] is non zero to insure the setting of a non zeror @error
comment:6 Changed 10 years ago by jchd18
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 Changed 10 years ago by BrewManNH
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.
Where 10 is being added to the @error value is definitely a bug. If you wanted to return a non-zero value for the $aRet[0] being 0 then you should be adding 10 to the $iError variable AFTER the If statement, not before it. The way it was rewritten guarantees that it will always return an error condition unless @error is -10.
comment:8 Changed 10 years ago by BrewManNH
- Resolution Fixed deleted
- Status changed from closed to reopened
comment:9 Changed 10 years ago by BrewManNH
- Resolution set to Fixed
- Status changed from reopened to closed
Fixed by revision [11327] in version: 3.3.13.21
comment:10 Changed 10 years ago by Jpm
Thanks ,
You right checking only @error instead of $iError was the smallest correction
comment:11 Changed 10 years ago by jchd18
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.
Guidelines for posting comments:
- You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
- In-depth discussions should take place on the forum.
For more information see the full version of the ticket guidelines here.
According to the header in the function, you wrote it, did someone change it after it was committed?