Fixed a few memory faults found by Valgrind (yes, I finally got my Linux

machine up and running again)



git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4723 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Matthias Melcher 2005-12-30 10:13:17 +00:00
parent 10fae2dd8a
commit d3db965083
8 changed files with 39 additions and 23 deletions

View File

@ -305,14 +305,17 @@ void CodeEditor::style_update(int pos, int nInserted, int nDeleted,
end = editor->mBuffer->line_end(pos + nInserted); end = editor->mBuffer->line_end(pos + nInserted);
text = editor->mBuffer->text_range(start, end); text = editor->mBuffer->text_range(start, end);
style = editor->mStyleBuffer->text_range(start, end); style = editor->mStyleBuffer->text_range(start, end);
last = style[end - start - 1]; if (start==end)
last = 0;
else
last = style[end - start - 1];
style_parse(text, style, end - start); style_parse(text, style, end - start);
editor->mStyleBuffer->replace(start, end, style); editor->mStyleBuffer->replace(start, end, style);
editor->redisplay_range(start, end); editor->redisplay_range(start, end);
if (last != style[end - start - 1]) { if (start==end || last != style[end - start - 1]) {
// The last character on the line changed styles, so reparse the // The last character on the line changed styles, so reparse the
// remainder of the buffer... // remainder of the buffer...
free(text); free(text);

View File

@ -1332,6 +1332,7 @@ void min_w_cb(Fl_Value_Input* i, void* v) {
void min_h_cb(Fl_Value_Input* i, void* v) { void min_h_cb(Fl_Value_Input* i, void* v) {
if (v == LOAD) { if (v == LOAD) {
if (!current_widget->is_window()) return;
i->value(((Fl_Window_Type*)current_widget)->sr_min_h); i->value(((Fl_Window_Type*)current_widget)->sr_min_h);
} else { } else {
int mod = 0; int mod = 0;
@ -1348,6 +1349,7 @@ void min_h_cb(Fl_Value_Input* i, void* v) {
void max_w_cb(Fl_Value_Input* i, void* v) { void max_w_cb(Fl_Value_Input* i, void* v) {
if (v == LOAD) { if (v == LOAD) {
if (!current_widget->is_window()) return;
i->value(((Fl_Window_Type*)current_widget)->sr_max_w); i->value(((Fl_Window_Type*)current_widget)->sr_max_w);
} else { } else {
int mod = 0; int mod = 0;
@ -1364,6 +1366,7 @@ void max_w_cb(Fl_Value_Input* i, void* v) {
void max_h_cb(Fl_Value_Input* i, void* v) { void max_h_cb(Fl_Value_Input* i, void* v) {
if (v == LOAD) { if (v == LOAD) {
if (!current_widget->is_window()) return;
i->value(((Fl_Window_Type*)current_widget)->sr_max_h); i->value(((Fl_Window_Type*)current_widget)->sr_max_h);
} else { } else {
int mod = 0; int mod = 0;

View File

@ -359,7 +359,7 @@ const char * Fl_File_Chooser::label() {
void Fl_File_Chooser::ok_label(const char *l) { void Fl_File_Chooser::ok_label(const char *l) {
okButton->label(l); okButton->label(l);
int w, h; int w=0, h=0;
okButton->measure_label(w, h); okButton->measure_label(w, h);
okButton->resize(cancelButton->x() - 50 - w, cancelButton->y(), okButton->resize(cancelButton->x() - 50 - w, cancelButton->y(),
w + 40, 25); w + 40, 25);

View File

@ -283,7 +283,7 @@ showChoiceCB();} {}
Function {ok_label(const char *l)} {return_type void Function {ok_label(const char *l)} {return_type void
} { } {
code {okButton->label(l); code {okButton->label(l);
int w, h; int w=0, h=0;
okButton->measure_label(w, h); okButton->measure_label(w, h);
okButton->resize(cancelButton->x() - 50 - w, cancelButton->y(), okButton->resize(cancelButton->x() - 50 - w, cancelButton->y(),
w + 40, 25); w + 40, 25);

View File

@ -38,6 +38,7 @@ Fl_Valuator::Fl_Valuator(int X, int Y, int W, int H, const char* L)
align(FL_ALIGN_BOTTOM); align(FL_ALIGN_BOTTOM);
when(FL_WHEN_CHANGED); when(FL_WHEN_CHANGED);
value_ = 0; value_ = 0;
previous_value_ = 1;
min = 0; min = 0;
max = 1; max = 1;
A = 0.0; A = 0.0;

View File

@ -263,15 +263,16 @@ int fl_draw_pixmap(const char*const* di, int x, int y, Fl_Color bg) {
for (int Y = 0; Y < d.h; Y++) { for (int Y = 0; Y < d.h; Y++) {
const uchar* p = data[Y]; const uchar* p = data[Y];
if (chars_per_pixel <= 1) { if (chars_per_pixel <= 1) {
int dw = d.w;
for (int X = 0; X < W; X++) { for (int X = 0; X < W; X++) {
uchar b = (*p++ != transparent_index); uchar b = (dw-->0 && *p++ != transparent_index);
if (*p++ != transparent_index) b |= 2; if (dw-->0 && *p++ != transparent_index) b |= 2;
if (*p++ != transparent_index) b |= 4; if (dw-->0 && *p++ != transparent_index) b |= 4;
if (*p++ != transparent_index) b |= 8; if (dw-->0 && *p++ != transparent_index) b |= 8;
if (*p++ != transparent_index) b |= 16; if (dw-->0 && *p++ != transparent_index) b |= 16;
if (*p++ != transparent_index) b |= 32; if (dw-->0 && *p++ != transparent_index) b |= 32;
if (*p++ != transparent_index) b |= 64; if (dw-->0 && *p++ != transparent_index) b |= 64;
if (*p++ != transparent_index) b |= 128; if (dw-->0 && *p++ != transparent_index) b |= 128;
*bitmap++ = b; *bitmap++ = b;
} }
} else { } else {

View File

@ -182,7 +182,8 @@ void push_menu(const char* nnn)
if (menus[men].icommand[i][0] != '@') but[bn]->tooltip(menus[men].icommand[i]); if (menus[men].icommand[i][0] != '@') but[bn]->tooltip(menus[men].icommand[i]);
else but[bn]->tooltip(0); else but[bn]->tooltip(0);
} }
strcpy(stack[stsize],nnn); if (stack[stsize]!=nnn)
strcpy(stack[stsize],nnn);
stsize++; stsize++;
} }
@ -255,8 +256,8 @@ void dobut(Fl_Widget *, long arg)
CreateProcess(NULL, command, NULL, NULL, FALSE, CreateProcess(NULL, command, NULL, NULL, FALSE,
NORMAL_PRIORITY_CLASS, NULL, NULL, &suInfo, &prInfo); NORMAL_PRIORITY_CLASS, NULL, NULL, &suInfo, &prInfo);
delete command; delete[] command;
delete copy_of_icommand; delete[] copy_of_icommand;
#else // NON WIN32 systems. #else // NON WIN32 systems.
@ -266,7 +267,7 @@ void dobut(Fl_Widget *, long arg)
sprintf(command, "./%s &", menus[men].icommand[bn]); sprintf(command, "./%s &", menus[men].icommand[bn]);
system(command); system(command);
delete command; delete[] command;
#endif // WIN32 #endif // WIN32
} }
} }
@ -336,7 +337,8 @@ int main(int argc, char **argv) {
if (i < argc) fname = argv[i]; if (i < argc) fname = argv[i];
if (!load_the_menu(fname)) Fl::fatal("Can't open %s",fname); if (!load_the_menu(fname)) Fl::fatal("Can't open %s",fname);
strcpy(buf,fname); if (buf!=fname)
strcpy(buf,fname);
const char *c = fl_filename_name(buf); const char *c = fl_filename_name(buf);
if (c > buf) {buf[c-buf] = 0; chdir(buf);} if (c > buf) {buf[c-buf] = 0; chdir(buf);}
push_menu("@main"); push_menu("@main");

View File

@ -379,20 +379,26 @@ style_update(int pos, // I - Position of update
end = textbuf->line_end(pos + nInserted); end = textbuf->line_end(pos + nInserted);
text = textbuf->text_range(start, end); text = textbuf->text_range(start, end);
style = stylebuf->text_range(start, end); style = stylebuf->text_range(start, end);
last = style[end - start - 1]; if (start==end)
last = 0;
else
last = style[end - start - 1];
// printf("start = %d, end = %d, text = \"%s\", style = \"%s\"...\n", // printf("start = %d, end = %d, text = \"%s\", style = \"%s\", last='%c'...\n",
// start, end, text, style); // start, end, text, style, last);
style_parse(text, style, end - start); style_parse(text, style, end - start);
// printf("new style = \"%s\"...\n", style); // printf("new style = \"%s\", new last='%c'...\n",
// style, style[end - start - 1]);
stylebuf->replace(start, end, style); stylebuf->replace(start, end, style);
((Fl_Text_Editor *)cbArg)->redisplay_range(start, end); ((Fl_Text_Editor *)cbArg)->redisplay_range(start, end);
if (last != style[end - start - 1]) { if (start==end || last != style[end - start - 1]) {
// The last character on the line changed styles, so reparse the // printf("Recalculate the rest of the buffer style\n");
// Either the user deleted some text, or the last character
// on the line changed styles, so reparse the
// remainder of the buffer... // remainder of the buffer...
free(text); free(text);
free(style); free(style);