Skip to content

More wrappers#79

Open
tiedaoxiaotubie wants to merge 8 commits intoeurecom-s3:masterfrom
tiedaoxiaotubie:more_wrappers
Open

More wrappers#79
tiedaoxiaotubie wants to merge 8 commits intoeurecom-s3:masterfrom
tiedaoxiaotubie:more_wrappers

Conversation

@tiedaoxiaotubie
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread runtime/LibcWrappers.cpp Outdated
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
Copy Markdown
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.

Comment thread runtime/LibcWrappers.cpp Outdated
if (isConcrete(a, strlen(a)) && isConcrete(b, strlen(b)))
return result;

auto aShadowIt = ReadOnlyShadow(a, strlen(a)).begin_non_null();
Copy link
Copy Markdown
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?

Comment thread runtime/LibcWrappers.cpp Outdated
++aShadowIt;
++bShadowIt;
allEqual =
_sym_build_bool_and(allEqual, _sym_build_equal(*aShadowIt, *bShadowIt));
Copy link
Copy Markdown
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.

Comment thread runtime/LibcWrappers.cpp Outdated
* return (int)strtol(str, (char **)NULL, 10);
* }
* */
auto result = strtol(s, (char **)NULL, 10);
Copy link
Copy Markdown
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?

Comment thread runtime/LibcWrappers.cpp Outdated
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
Copy Markdown
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?

Comment thread runtime/LibcWrappers.cpp Outdated
return result;
}

long int SYM(atol)(const char *s) {
Copy link
Copy Markdown
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?

Comment thread runtime/LibcWrappers.cpp Outdated
_sym_set_return_expression(nullptr);

size_t srcLen = strnlen(src, n);
size_t copied = std::min(n, srcLen);
Copy link
Copy Markdown
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