memset and memcpymemcpySyntax:
#include <string.h> void * memcpy ( void * destinationPtr, const void * sourcePtr, size_t num );
If your code uses the memcpy function, see
the information in this table.
| Specification | Example |
|---|---|
Polyspace® runs a Invalid use of standard library
routine check on the function. The check determines if
the memory block that sourcePtr or destinationPtr points
to is greater than or equal in size to the memory assigned to them
through num. | #include <string.h>
typedef struct {
char a;
int b;
} S;
void func(int);
void main() {
S s;
int d;
memcpy(&d, &s, sizeof(S));
}In this code, Polyspace produces a red Invalid use of standard library routine error because:
|
Polyspace does not check if the memory that Following the use of | #include <string.h>
typedef struct {
char a;
int b;
} S;
void func(int);
void main() {
S s, d={'a',1};
int val;
val = d.b; // val=1
memcpy(&d, &s, sizeof(S));
val = d.b;
// val can have any int value
}In this code, when the |
Polyspace raises a red Invalid use of standard library routine check if the source and destination arguments overlap. Overlapping assignments are forbidden by the C Standard. | A red check is produced for this memory assignment: #include <string.h>
int main() {
char arr[4];
memcpy (arr, arr + 3, sizeof(int));
} |
memsetSyntax:
#include <string.h> void * memset ( void * ptr, int value, size_t num );
If your code uses the memset function, see
the information in this table.
| Specification | Example |
|---|---|
Polyspace runs a Invalid use of standard library
routine check on the function. The check determines if
the memory block that ptr points to is greater
than or equal in size to the memory assigned to them through num. | #include <string.h>
typedef struct {
char a;
int b;
} S;
void main() {
int val;
memset(&val,0,sizeof(S));
}In this code, Polyspace produces a red Invalid use of standard library routine error because:
|
If | #include <string.h>
typedef struct {
char a;
int b;
} S;
void main() {
S s;
int val;
memset(&s,0,sizeof(S));
val=s.b; //val=0
}In this code, Polyspace considers that
following the use of |
Following the use of
| #include <string.h>
typedef struct {
char a;
int b;
} S;
void main() {
S s;
int val;
memset(&s,1,sizeof(S));
val=s.b;
// val can have any int value
}In
this code, Polyspace considers that following the use of
Following the
|