Hello,
I was debugging and seeing memory leaks logs using valgrind in my software and 
I found a suspicious warning regarding fltk. I'm using fltk-1.3.x-r6581 with 
Linux. Of course, It could be a false-positive, but I think It worth a look :)

==6463==
==6463== Invalid read of size 1
==6463==    at 0x807933B: put_font_size(char const*, int)
==6463==    by 0x8079410: find(int, int)
==6463==    by 0x8079471: fl_font(int, int)
==6463==    by 0x807A69F: fl_normal_label(Fl_Label const*, int, int, int, int, 
unsigned)
==6463==    by 0x807A7E3: Fl_Widget::draw_label(int, int, int, int, unsigned) 
const
==6463==    by 0x807A814: Fl_Widget::draw_label(int, int, int, int) const
==6463==    by 0x807A884: Fl_Widget::draw_label() const
==6463==    by 0x806AFA6: Fl_Group::draw_child(Fl_Widget&) const
==6463==    by 0x806B137: Fl_Group::draw_children()
==6463==    by 0x8058556: CUiTouchNumParameter::draw() (TouchParameter.cpp:197)
==6463==    by 0x806AFA6: Fl_Group::draw_child(Fl_Widget&) const
==6463==    by 0x806B137: Fl_Group::draw_children()
==6463==  Address 0xbed0e0e5 is not stack'd, malloc'd or (recently) free'd
==6463==

And the fltk source for this error was in this function :

static char *put_font_size(const char *n, int size)
{
        int i = 0;
        char *buf;
        const char *ptr;
        const char *f;
        char *name;
        int nbf = 1;
        name = strdup(n);
        while (name[i]) {
                if (name[i] == ',') {nbf++; name[i] = '\0';}
                i++;
        }

        buf = (char*) malloc(nbf * 256);
        buf[0] = '\0';
        ptr = name;
        i = 0;
        while (ptr && nbf > 0) {
                f = find_best_font(ptr, size);
                while (*f) {
                        buf[i] = *f;
                        f++; i++;
                }
                nbf--;
                while (*ptr) ptr++; //My comments:shouldn't we update nbf?
                if (nbf) {
                        ptr++; //My question:could give us invalid access?
                        buf[i] = ',';
                        i++;
                }
                while(isspace(*ptr)) ptr++;
        }
        buf[i] = '\0';
        free(name);
        return buf;
}

Thanks,
J. Marcelo Auler
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to