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 #36, handle read failure #37

Closed
wants to merge 1 commit into from

Conversation

zanzaben
Copy link
Contributor

@zanzaben zanzaben commented Mar 1, 2021

Describe the contribution
Fixes #36
Handles case where read returns an error

Testing performed
Build and run unit test

Expected behavior changes
No impact to behavior

System(s) tested on
Ubuntu 20.04

Contributor Info - All information REQUIRED for consideration of pull request
Alex Campbell GSFC

Copy link
Contributor

@jphickey jphickey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting minor change here too to avoid extra cast.
.

printf("\ncfe_ts_crc error: file read failed!\n");
exit(1);
}
fileCRC = CalculateCRC(buffer, (uint32)readSize, fileCRC);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason that a cast to (uint32) was added here? Shouldn't be needed.
Also see my other comment in the other PR that the return type of read() is ssize_t, not int.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was done because CalculateCRC is expecting a uint32

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it will convert implicitly - and forcing a conversion can have unintended consequences. In reality the CalculateCRC() functions should take a size_t anyway.

Note that C has very specific rules about when and how implicit type conversions are done - and things (almost) always just work. When it doesn't just work you'll get a compiler warning about it, but a cast can hide that warning because it is literally telling the compiler "I meant to do that". Hence why its not advised to put them in unless there is a real reason why you need to tell the compiler that you meant to do that. In this case, I don't see any reason.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note - I'm not suggesting changing CalculateCRC to size_t here - just leave it alone - it doesn't matter. My only concern is the extra cast - should not do this.

@jphickey
Copy link
Contributor

jphickey commented Mar 3, 2021

Note - submitted issue #41 about the EOF bit. Maybe we can fix that too while looking at this code.

@zanzaben
Copy link
Contributor Author

zanzaben commented Mar 4, 2021

Moving this to #42

@zanzaben zanzaben closed this Mar 4, 2021
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.

read failures are not handled
3 participants