Skip to content

lib/util-xstrcpy.c: strcpy_or_abort: Actually abort() in -DNDEBUG builds #211

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

solardiz
Copy link
Collaborator

It's reasonable that it uses assert when all of its uses are such that the data must fit, so it'd be a usage bug (which we'd want detected in this way) if the data ever doesn't fit. However, it's probably unexpected that this function becomes unsafe in non-debugging builds. It should probably literally call abort when the assert condition is not met yet execution "mysteriously" continues. I hope the compiler will optimize out the redundant check when assert is compiled in.

Also, the condition may be simplified (in both places) to d_size > s_size. I think the compiler cannot perform the same optimization on its own because it has to assume + 1 may overflow (wraparound to 0).

This PR is untested.

Copy link

codecov bot commented Apr 17, 2025

Codecov Report

Attention: Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 90.42%. Comparing base (e34e063) to head (dcaf1f3).

Files with missing lines Patch % Lines
lib/util-xstrcpy.c 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #211      +/-   ##
===========================================
- Coverage    90.44%   90.42%   -0.03%     
===========================================
  Files           36       36              
  Lines         3988     3990       +2     
  Branches       747      748       +1     
===========================================
+ Hits          3607     3608       +1     
- Misses         242      243       +1     
  Partials       139      139              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant