-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect usage of 'Val instead of 'Enum_Val #431
Comments
On 13-Jun-24 2:24 AM, Liam Powell wrote:
Here is another case of the same error, this one can return an incorrect
value:
https://github.com/AdaCore/Ada_Drivers_Library/blob/b651d01dcfd7e27836f938c1d494e1ed3212ed43/arch/ARM/STM32/drivers/stm32-gpio.adb#L439 <https://github.com/AdaCore/Ada_Drivers_Library/blob/b651d01dcfd7e27836f938c1d494e1ed3212ed43/arch/ARM/STM32/drivers/stm32-gpio.adb#L439>
Thank you for opening this issue.
I have not yet looked at the first example, but I believe that the code
in this second example case is correct.
Specifically, in the following:
return EXTI.External_Line_Number'Val (GPIO_Pin'Pos (This.Pin));
is correct because:
* type External_Line_Number does not have a representation clause,
therefore the representation values are zero-based (ie, 0 through 22), and
* the result of 'Pos is always zero-based, so GPIO_Pin'Pos returns 0 ..
15, and
* 0 .. 15 are valid representations for External_Line_Number values when
converted via 'Val, and
* those numeric values result in the External_Line_Number values that
match the corresponding GPIO pins.
Let me know if you disagree. It is always possible that I have missed
something.
In any case I will also look at the first example in the issue.
Thanks again,
Pat Rogers
|
I have since removed that one but GitHub obviously can not update the
email, it was only problematic in a fork rather than this repo. The first
one is still an issue with Range_Check.
…On Tue, Aug 13, 2024 at 2:22 AM Pat Rogers ***@***.***> wrote:
On 13-Jun-24 2:24 AM, Liam Powell wrote:
> Here is another case of the same error, this one can return an incorrect
> value:
>
>
https://github.com/AdaCore/Ada_Drivers_Library/blob/b651d01dcfd7e27836f938c1d494e1ed3212ed43/arch/ARM/STM32/drivers/stm32-gpio.adb#L439
<
https://github.com/AdaCore/Ada_Drivers_Library/blob/b651d01dcfd7e27836f938c1d494e1ed3212ed43/arch/ARM/STM32/drivers/stm32-gpio.adb#L439
>
Thank you for opening this issue.
I have not yet looked at the first example, but I believe that the code
in this second example case is correct.
Specifically, in the following:
return EXTI.External_Line_Number'Val (GPIO_Pin'Pos (This.Pin));
is correct because:
* type External_Line_Number does not have a representation clause,
therefore the representation values are zero-based (ie, 0 through 22), and
* the result of 'Pos is always zero-based, so GPIO_Pin'Pos returns 0 ..
15, and
* 0 .. 15 are valid representations for External_Line_Number values when
converted via 'Val, and
* those numeric values result in the External_Line_Number values that
match the corresponding GPIO pins.
Let me know if you disagree. It is always possible that I have missed
something.
In any case I will also look at the first example in the issue.
Thanks again,
Pat Rogers
—
Reply to this email directly, view it on GitHub
<#431 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANZQULYDJACYHH243DTMXDZRD4NJAVCNFSM6AAAAABJHYTHKOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOBUGY2DONRWGM>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
On 12-Aug-24 1:25 PM, Liam Powell wrote:
I have since removed that one but GitHub obviously can not update the
email, it was only problematic in a fork rather than this repo. The first
one is still an issue with Range_Check.
OK, I'll take a look.
Pat
|
On 13-Jun-24 2:14 AM, Liam Powell wrote:
The below line will raise a Constraint_Error if Range_Check is enabled
as the enumeration is not continuous, using 'Enum_Val instead would fix
this. This error could exist in the thousands of other uses of 'Val
which I have not checked and it could have potentially worse
consequences than this one which will likely be harmless when
Range_Check is disabled.
https://github.com/AdaCore/Ada_Drivers_Library/blob/b651d01dcfd7e27836f938c1d494e1ed3212ed43/arch/ARM/STM32/drivers/stm32-adc.adb#L410 <https://github.com/AdaCore/Ada_Drivers_Library/blob/b651d01dcfd7e27836f938c1d494e1ed3212ed43/arch/ARM/STM32/drivers/stm32-adc.adb#L410>
I agree that using 'Val in this line is incorrect.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The below line will raise a Constraint_Error if Range_Check is enabled as the enumeration is not continuous, using 'Enum_Val instead would fix this. This error could exist in the other uses of 'Val which I have not checked and it could have potentially worse consequences than this one which will likely be harmless when Range_Check is disabled.
Ada_Drivers_Library/arch/ARM/STM32/drivers/stm32-adc.adb
Line 410 in b651d01
The text was updated successfully, but these errors were encountered: