Skip to content

Conversation

@Sehun0819
Copy link

@Sehun0819 Sehun0819 commented Sep 7, 2021

  • memcpy
char dst[5];
char src[5] = "abcd";
memcpy(dst, src, 5);

Sparrow raises following alarm on above code

= Alarms =
1. memcpy.c:8 {main} UnProven
  memcpy (StartOf(dst), StartOf(src), 5) @main-17:  offset: [6, 6], size: [5, 5] UnProven, allocsite: main-10
  memcpy (StartOf(dst), StartOf(src), 5) @main-17:  offset: [6, 6], size: [5, 5] UnProven, allocsite: main-8

And I found out current code calculates 'offset = len + 1` and it must be a typo.

  • strlen
char* str = "abcd";
char* substr = str + 1;
int len1 = strlen(str);
int len2 = strlen(substr);

Currently both len1 and len2 are evaluated to 4, as model_strlen doesn't count offset.

@Sehun0819 Sehun0819 changed the title simple memcpy bug simple memcpy/strlen bug Sep 19, 2021
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