Skip to content
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

[aes,dv] Add a cast for the byte type return of getc() function to string variable assignment #25511

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dariuszst
Copy link

From SV LRM:

6.16.3 Getc()
function byte getc(int i);
— str.getc(i) returns the ASCII code of the ith character in str.
— If i < 0 or i >= str.len(), then str.getc(i) returns 0.

Thus the type cast should be used to assign it to string variable.

@dariuszst dariuszst requested a review from a team as a code owner December 4, 2024 13:56
@dariuszst dariuszst requested review from rswarbrick and removed request for a team December 4, 2024 13:56
@rswarbrick
Copy link
Contributor

I'm not sure this is needed. Isn't this just addressed by the last sentence here?

image

@danielmlynek
Copy link

Reading the SV LRM strictly getc return a byte and byte is not assignment compatible with string.
You are trying to assign byte to whole string - so error is expected.
If you would try to assign it string element like below:
s [0] = name.getc(name.len - 1);
then this would be perfectly legal.
Some tools allow to suppress such error - but it is better to just fix the code.

@rswarbrick
Copy link
Contributor

Oh, that makes sense. How silly of me! It's like mixing up char * and char in C (char *my_str = 'a';)

@rswarbrick
Copy link
Contributor

Thanks for the change. Annoyingly, it's failing CI because of the commit message being badly formatted. Would you mind tweaking?

…ring variable assignment

Assign the result of getc function of a byte type to the string variable requires type casting.
Signed-off-by: Dariusz Stachanczyk <[email protected]>
@dariuszst dariuszst force-pushed the aes_getc_cast_to_string branch from e4d7551 to eaf1df1 Compare December 10, 2024 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants