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

More wrappers #79

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

tiedaoxiaotubie
Copy link
Contributor

add 7 common glibc function wrappers, including strcmp, strncmp, strlen, atoi, atol, strcpy and strncpy

Every wrapper was provided with a test_xxx.c to verity its correctness.

Copy link
Collaborator

@sebastianpoeplau sebastianpoeplau left a comment

Choose a reason for hiding this comment

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

This is very nice, thank you!

I'll be happy to work on resolving the few comments I had, rebase, and merge.

auto aShadowIt = ReadOnlyShadow(a, strlen(a)).begin_non_null();
auto bShadowIt = ReadOnlyShadow(b, strlen(b)).begin_non_null();
auto *allEqual = _sym_build_equal(*aShadowIt, *bShadowIt);
for (size_t i = 1; i < strlen(a); i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should probably stop at the minimum of the two string lengths - otherwise we'll crash while trying to assemble the expression.

if (isConcrete(a, strlen(a)) && isConcrete(b, strlen(b)))
return result;

auto aShadowIt = ReadOnlyShadow(a, strlen(a)).begin_non_null();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we include the null byte?

++aShadowIt;
++bShadowIt;
allEqual =
_sym_build_bool_and(allEqual, _sym_build_equal(*aShadowIt, *bShadowIt));
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't capture the exact semantics (especially for the case where the strings aren't equal), but it's much better than what we currently have 😉 Maybe we can just add a comment saying what would have to be done for an accurate symbolic representation.

* return (int)strtol(str, (char **)NULL, 10);
* }
* */
auto result = strtol(s, (char **)NULL, 10);
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's nothing wrong with that function summary, but why don't we call atoi directly?

size_t length = strlen(s);
size_t num_len = 0;
for (size_t i = 0; i < length; i++) {
if ('0' <= (char)s[i] && (char)s[i] <= '9') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this mean we don't handle negative numbers?

return result;
}

long int SYM(atol)(const char *s) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is really similar to the wrapper for atoi. Should we merge the two?

_sym_set_return_expression(nullptr);

size_t srcLen = strnlen(src, n);
size_t copied = std::min(n, srcLen);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is really minor, but isn't srcLen always less than or equal to n as per the definition of strnlen?

@sebastianpoeplau sebastianpoeplau self-assigned this Feb 22, 2023
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.

3 participants