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

Issue #445. Testing the behavior of the strncasecmp_custom function. #454

Merged
merged 3 commits into from
Oct 2, 2024

Conversation

lecapitainenemo
Copy link
Contributor

@lecapitainenemo lecapitainenemo commented Sep 29, 2024

Related to issue #445 fix custom strncasecmp implementation.

It was described that the strncasecmp_custom function was going to fail and emit that strings like "not" and "NOTICE" were equal. However, the current implementation passed tests of this style (I added them).

This was a not a notable change so I did not add anything to ChangeLog.

Thanks.

@goatshriek goatshriek self-assigned this Sep 29, 2024
Copy link

codecov bot commented Sep 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.53%. Comparing base (72f40f9) to head (1fb7f34).
Report is 1 commits behind head on latest.

Additional details and impacted files
@@            Coverage Diff             @@
##           latest     #454      +/-   ##
==========================================
+ Coverage   90.48%   90.53%   +0.04%     
==========================================
  Files          47       47              
  Lines        4373     4374       +1     
  Branches      585      586       +1     
==========================================
+ Hits         3957     3960       +3     
+ Misses        281      280       -1     
+ Partials      135      134       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lecapitainenemo
Copy link
Contributor Author

I was wondering how to proceed, if I committed a mistake or if there is any other recommended task.
Thank you

@goatshriek
Copy link
Owner

goatshriek commented Sep 30, 2024

The bug can be subtle, but is present. By passing in a buffer size far greater than the string you provided, you've forced the comparison to go farther in and find the NULL character difference. However the from_buffer function needs to work when it doesn't have a NULL terminator. After all the purpose of this function is to NOT need a NULL terminator to begin with!

You can trigger the failure by reducing the buffer size to match the string length, add this test, or [my recommendation] do both.

TEST( GetSeverityEnum, InvalidButPrefix ) {
  enum stumpless_severity result = stumpless_get_severity_enum( "war" );
  EXPECT_EQ( result, -1 );
  EXPECT_ERROR_ID_EQ( STUMPLESS_INVALID_SEVERITY );
}

…p. After that, the strncasecmp_custom function was modified to obtain the desired behavior.
@lecapitainenemo
Copy link
Contributor Author

Hey,
I added the failing tests. I removed the "EXPECT_ERROR_ID_EQ( STUMPLESS_INVALID_SEVERITY );" part from them, though. With the modification to strncasecmp_custom function, all the tests (new and old) pass. Please let me know if there is anything wrong. I appreciate your time and patience.

@goatshriek
Copy link
Owner

Ah, I didn't realize that error codes were not being raised. I've opened #455 to address that.

Everything looks good! One final ask: can you also add a new test for the opposite direction: that strings that start with a valid severity but are longer are not accepted. For example "warnings are neat" should not be parsed to a valid severity. This will make sure that the comparison works properly in both directions.

…verity strings (Longer strings that contained valid severities in them) were tested.
@lecapitainenemo
Copy link
Contributor Author

The respective tests were added and all old and new passed.
Thank you

@goatshriek goatshriek merged commit 1bd3333 into goatshriek:latest Oct 2, 2024
56 checks passed
@goatshriek goatshriek added the hacktoberfest-accepted accepted work that is valid for hacktoberfest label Oct 2, 2024
@goatshriek
Copy link
Owner

Thanks very much for putting this contribution together and sticking with it through the requested changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted accepted work that is valid for hacktoberfest
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants