Last active
August 23, 2022 22:30
-
-
Save Binary-Eater/34405fa2cb7fa4791231b1f0f2336587 to your computer and use it in GitHub Desktop.
Snippet for testing Coverity Scan of composite type reads
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum test_union_type { | |
NONE, | |
SHORT, | |
INTEGER | |
}; | |
union test_union { | |
struct {}; | |
short s; | |
int i; | |
}; | |
struct test { | |
enum test_union_type t; | |
union test_union u; | |
}; | |
void union_set_and_write(union test_union *ptr) { | |
union test_union tmp_union; | |
tmp_union.s = 1; | |
// I believe the line below will not be marked as an unintialized read | |
*ptr = tmp_union; | |
} | |
void none_type_struct_set_and_write(struct test *ptr) { | |
struct test tmp_struct; | |
tmp_struct.t = NONE; | |
// I believe the line below will be marked as an unintialized read | |
*ptr = tmp_struct; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment