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

Fix type mismatches and remove unnecessary typecasting #57

Closed
skliper opened this issue Sep 30, 2019 · 11 comments
Closed

Fix type mismatches and remove unnecessary typecasting #57

skliper opened this issue Sep 30, 2019 · 11 comments
Labels
Milestone

Comments

@skliper
Copy link
Contributor

skliper commented Sep 30, 2019

This ticket is to fix up areas of the code that have type mismatches or other unnecessary typecasting.

  • In some areas, the standard "int" type is used when it should be the OSAL int32/uint32 type.
  • In other areas, values are cast to certain types when it is not necessary to do so because the compiler will automatically do the right thing.

In the latter case, the type cast should be removed, because in certain situations it can actually interfere with the compiler doing the right thing and make it do the //wrong// thing instead. An example of this is casting to "int" with operands that are actually unsigned types and/or different widths. In the case that the forced "int" is a negative value, a sign extension might be performed and this might produce an unexpected result. In general, a cast should only be used when there is a good reason why the compiler's default conversion rules are not sufficient.

@skliper skliper added this to the 6.5.0 milestone Sep 30, 2019
@skliper
Copy link
Contributor Author

skliper commented Sep 30, 2019

Imported from trac issue 26. Created by jphickey on 2015-01-21T13:46:44, last modified: 2019-03-05T14:57:55

@skliper skliper self-assigned this Sep 30, 2019
@skliper skliper added the bug label Sep 30, 2019
@skliper
Copy link
Contributor Author

skliper commented Sep 30, 2019

Trac comment by jphickey on 2015-01-21 14:02:43:

For a specific example of how extra typecasting can actually //break// things, consider the following code:

{{{
unsigned long result1, result2;
unsigned int input = 0xDEADBEEFU;

result1 = input;
result2 = (int) input;

printf("Input = %u, Results = %ld %ld\n", input, result1, result2);
}}}

Compiling and executing this produces the following result:
{{{
Input = 3735928559, Results = 3735928559 -559038737
}}}

The first result (without any extra cast) is more likely the desired result.

@skliper
Copy link
Contributor Author

skliper commented Sep 30, 2019

Trac comment by jphickey on 2015-01-26 15:04:17:

Branch "trac-26-type_fixes" pushed -- commit [changeset:45f45f4]

This grabs several low hanging fruits regarding signed/unsigned mismatches and unnecessary casts.

@skliper
Copy link
Contributor Author

skliper commented Sep 30, 2019

Trac comment by jphickey on 2015-04-06 11:31:33:

This is ready for review/merge

@skliper
Copy link
Contributor Author

skliper commented Sep 30, 2019

Trac comment by sstrege on 2015-04-06 13:57:15:

Concur with changes/merge

@skliper
Copy link
Contributor Author

skliper commented Sep 30, 2019

Trac comment by acudmore on 2015-04-07 09:41:45:

Concur.

@skliper
Copy link
Contributor Author

skliper commented Sep 30, 2019

Trac comment by jwilmot on 2015-04-07 12:53:30:

Concur. Why would we have signed task ids? Should we have a TaskID_t?

@skliper
Copy link
Contributor Author

skliper commented Sep 30, 2019

Trac comment by glimes on 2015-04-07 13:01:01:

Tested changeset [changeset:45f45f491] as part of the ic-2015-03-10 merge.

@skliper
Copy link
Contributor Author

skliper commented Sep 30, 2019

Trac comment by glimes on 2015-04-13 15:24:53:

Part of integration candidate 2015-03-10,
committed to cFS CFE Development branch on 2015-04-10
as part of merge [changeset:7d6f6d0].

@skliper
Copy link
Contributor Author

skliper commented Sep 30, 2019

Trac comment by glimes on 2016-02-25 10:17:32:

these will be fixed in CFE 6.5

@skliper
Copy link
Contributor Author

skliper commented Sep 30, 2019

Trac comment by jhageman on 2019-03-05 14:57:55:

Milestone renamed

@skliper skliper closed this as completed Sep 30, 2019
This was referenced Sep 30, 2019
@skliper skliper removed their assignment Sep 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant