-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Check if read succedded before reading again/allocating memory #3606
Comments
Should i fix the 273 instances ? |
@kunaltyagi Could you expand upon what exactly you mean by "graceful error detection" as failure to read the stream can lead to unexpected behavior. |
This should be factored in the operation. Failure to read should inform the user with proper debug information programmatically (like return a false, or raise exception or something) along with log in debug mode. |
Raise exception and let the upper layers in the stack decide what to do with it. |
Since there exists no exception for failure to read, @SergioRAgostinho should I go ahead and create a new exception in pcl/exceptions.h as it would be useful at multiple places? |
What about this one pcl/common/include/pcl/exceptions.h Lines 176 to 188 in e5b8fe5
Do you feel it's too generic? |
Yeah I thought it would be too generic but after looking at all the case, I guess most cases would fit under IOException |
Is something like this alright? Just want to confirm before actually implementing it to the 273 instances. Would it perhaps be better to write a function that performs this sanity check, instead of writing try and catch statements at all the instances? |
In your example Answering directly your question: the snippet is not what we want. Take some time to read https://en.cppreference.com/w/cpp/io/basic_istream/read carefully. |
What about this? |
There's no value in catching an exception you just threw. This exception handling ( |
Oh, right. So this snippet without the try and catch, and checking for error before allocating |
No @0sidharth , it is syntactically wrong. Please try to compile your snippets. I'd recommend a Unix machine or Windows + MS VS 2019 or https://godbolt.org as good places to start. |
I was talking about this @kunaltyagi , and it is compiling for me so I cannot figure out which syntatic error you are referring to? |
The snippet provided here is correct. I've 2 more comments on this snippet:
|
Marking this as stale due to 30 days of inactivity. It will be closed in 7 days if no further activity occurs. |
Your Environment
Context
Bad parsing is inevitable, specially if operations are performed on read data without validation
Expected Behavior
Graceful error detection
Current Behavior
Files: 273 instances. One sample provided:
Possible Solution
Sanity checks on input stream after reading before allocating memory
The text was updated successfully, but these errors were encountered: