|
From: Daniel V. <m4...@ma...> - 2005-12-16 12:58:16
|
I've been using valgrind to check my image compression routine, and reduced the reported problem to the following code, compiled with gcc 4.0.1-4ubuntu9 using "gcc -g -Wall vt.c".
I am not even sure whether valgrind can possibly report the right thing, but here goes:
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
FILE *f;
unsigned char filebuf = 0;
unsigned int refinement_cache; // not initialised
// the following statement works if we turn the plus (+) into an or (|)
refinement_cache = (refinement_cache << 1) + 1; // bit 0 is now valid
f = fopen("vt.tmp", "w");
filebuf = (filebuf << 1) + (refinement_cache & 1); // write bit 0 to file
fwrite(&filebuf, 1, 1, f);
fclose(f); // valgrind complains that we are passing undefined data to a syscall
return 0;
}
|