-
Notifications
You must be signed in to change notification settings - Fork 2.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
Add support for const error description strings #3176
Conversation
Problem ------- mbedtls_strerror is a utility function which converts an mbedTLS error code into a human readable string. It requires the caller to allocate a buffer every time an error code needs to be converted to a string. It is an overkill and a waste of RAM for resource constrained microcontrollers - where the most common use case is to use these strings for logging. Solution -------- The proposed commit adds two functions: * const char * mbedtls_high_level_strerr( int error_code ); * const char * mbedtls_low_level_strerr( int error_code ); The above two functions convert the high level and low level parts of an mbedTLS error code to human readable strings. They return a const pointer to an unmodifiable string which is not supposed to be modified by the caller and only to be used for logging purposes. The caller no longer needs to allocate a buffer. Backward Compatibility ---------------------- The proposed change is completely backward compatible as it does not change the existing mbedtls_strerror function and ensures that it continues to behave the same way. Signed-off-by: Gaurav Aggarwal <[email protected]>
- Use switch case instead of loop to generate faster code - Add #if defined to address compiler error Signed-off-by: Gaurav Aggarwal <[email protected]>
I do not have access to the internal jenkins server. Can someone help me with what the error in the failed PR checks is? |
Everything that should have passed has passed. The Mbed OS testing is currently broken, but that doesn't hold up PRs. |
Thank you. Would you please help me in getting the required approvals then? |
It's on our review dashboard now. |
Thank you. |
The presence of these markers in the original code was helpful to me in figuring out that this portion of the code is auto-generated. Therefore, I think those are useful and should be present. Signed-off-by: Gaurav Aggarwal <[email protected]>
Ping - Request for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with the design, except that I wonder if mbedtls_high_level_strerr
and mbedtls_low_level_strerr
should operate on the high/low part of the error code, rather than require it to solely consist of a high/low error code.
I'm requesting some minor documentation improvements. Comments on mbedtls_high_level_strerr
also apply to mbedtls_low_level_strerr
.
1. The functions mbedtls_high_level_strerr and mbedtls_low_level_strerr accept any error code and extract the high-level and low-level parts respectively. 2. Documentation updates. Signed-off-by: Gaurav Aggarwal <[email protected]>
Thank you for the review. Yes, I think it is a good suggestion - I have updated |
Thanks for the update! The CI failures are due to a temporary problem on the |
@gilles-peskine-arm One additional remark.
Should there be no objections, I guess @aggarg could do this. Would you? |
Merge pull request ARMmbed#3176 from aggarg/development
Sure, will do. I am habitual of writing functions with single exit point which is why this style. |
Signed-off-by: Gilles Peskine <[email protected]>
This was suggested on this PR: Mbed-TLS#3176 Signed-off-by: Gaurav Aggarwal <[email protected]>
Problem
mbedtls_strerror
is a utility function which converts an mbedTLS error code into a human readable string. It requires the caller to allocate a buffer every time an error code needs to be converted to a string. It is an overkill and a waste of RAM for resource constrained microcontrollers - where the most common use case is to use these strings for logging.Solution
The proposed commit adds two functions:
The above two functions convert the high level and low level parts of an mbedTLS error code to human readable strings. They return a const pointer to an unmodifiable string which is not supposed to be modified by the caller and only to be used for logging purposes. The caller no longer needs to allocate a buffer.
Status
READY
Requires Backporting
NO
The proposed change is completely backward compatible as it does not change the existing mbedtls_strerror function and ensures that it continues to behave the same way.
Files
Modified Files:
Auto Generated File:
The
library/error.c
is generated by runningscripts/generate_errors.pl
(which seems to be the way it is generated).Testing
Signed-off-by: Gaurav Aggarwal [email protected]