c - Why doesn't valgrind complain when copying uninitialized data? -


according manual doesn't:

it important understand program can copy around junk (uninitialised) data as likes. memcheck observes , keeps track of data, not complain. complaint issued when program attempts make use of uninitialised data in way might affect program's externally-visible behaviour.

the question if there's important reason behave way? there (commonly) used construct that's copies uninitialized data trigger false positives? or there way make valgrind complain this?

my concern in c use of uninitialized variables have undefined behavior (iirc), example following functions emit nasal daemons:

int fubar(void) {      int a;       return a; } 

now recalled incorrectly, it's in situations it's undefined, example if you're doing arithmetics uninitialized variables:

int fubar(void) {     int a;      -= a;     return a; } 

so same question arises here. there important reason valgrind allow arithmetics uninitialized data? etc. note if floating point data alter externally observable behaviour trapping on fp-errors might enabled.

yes, happens quite often. example:

struct {     char a;     int b; } s1, s2;  s1.a = '.'; s1.b = 31337;  memcpy (&s2, &s1, sizeof(s1)); 

here, copying uninitialized bytes (the padding bytes between a , b).

i think, valgrind doesn't complain here.

generally spoken (in response arithmetic example):

valgrind tries complain when uninitialized data can cause of non-deterministic behaviour of program. or other way round: not complain, if can rule out case. so, example, when branch or syscall parameter depends on uninitialized data valgrind complains. can try out putting exit(a) after a -= a;, results in

syscall param exit_group(status) contains uninitialised byte(s) 

even when result 0 in case. (you might have declare a volatile prevent removing code)


Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -