FLTK 1.4.x, 202110409 snapshot.
Linux Mint 20.1 MATE
Running Valgrind on a program derived from pixmap_browser.cxx. Due to a bug in my code, I am occasionally passing a folder path to Fl_Shared_Image::get() . Valgrind gives me the following error [earlier stack elided]:
==2731837== Conditional jump or move depends on uninitialised value(s)
==2731837== at 0x139B0A: Fl_Shared_Image::reload() (Fl_Shared_Image.cxx:266)
==2731837== by 0x139685: Fl_Shared_Image::Fl_Shared_Image(char const*, Fl_Image*) (Fl_Shared_Image.cxx:145)
==2731837== by 0x13A1A2: Fl_Shared_Image::get(char const*, int, int) (Fl_Shared_Image.cxx:462)
==2731837== by 0x1263F3: load_file(char const*) (pixmap_browser.cxx:213)
==2731837== by 0x1264F0: file_cb(char const*) (pixmap_browser.cxx:258)
The problem is not at the line shown above, but in this following chunk of code [lines 258-263]:
if ((fp = fl_fopen(name_, "rb")) != NULL) {
if (fread(header, 1, sizeof(header), fp)==0) { /* ignore */ }
fclose(fp);
} else {
return;
}
In the case of a folder path, the fread() call to populate header returns 0, and header has not been initialized. The code proceeds to use header in an invalid state.
I suggest something like this instead:
if ((fp = fl_fopen(name_, "rb")) != NULL) {
int count = fread(header, 1, sizeof(header), fp);
fclose(fp);
if (count==0) return;
} else {
return;
}
I've tried the above change and Valgrind no longer complains about uninitialized values.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.
[ Direct Link to Message ] |