Skip to content

Commit

Permalink
Fl_Preferences: fixed delete/free confusion, updated docu and sample …
Browse files Browse the repository at this point in the history
…on buffer size issue (buffer needs to allow for additional byte for trailing zero)

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@2242 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
  • Loading branch information
Matthias Melcher committed May 17, 2002
1 parent 6a726f5 commit dc5fa84
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
3 changes: 2 additions & 1 deletion documentation/Fl_Preferences.html
Expand Up @@ -139,7 +139,7 @@ <H4><a name="Fl_Preferences.get">int get(const char *entry, int &amp;value, int
int get(const char *entry, float &amp;value, float defaultValue)<BR>
int get(const char *entry, double &amp;value, double defaultValue )<BR>
int get(const char *entry, char *&amp;text, const char *defaultValue)<BR>
int get(const char *entry, char *text, const char *defaultValue, int maxSize)<BR>
int get(const char *entry, char *text, const char *defaultValue, int maxLength)<BR>
int get(const char *entry, void *&amp;data, const void *defaultValue, int defaultSize)<BR>
int get(const char *entry, void *data, const void *defaultValue, int defaultSize,
int maxSize)</a></H4>
Expand All @@ -149,6 +149,7 @@ <H4><a name="Fl_Preferences.get">int get(const char *entry, int &amp;value, int
(non-zero) or the default was used (0). If the '<tt>char
*&amp;text</tt>' or '<tt>void *&amp;data</tt>' form is used,
the resulting data must be freed with '<tt>free(value)</tt>'.
<P>'<tt>maxLength</tt>' is the maximum length of text that will be read. The text buffer must allow for one additional byte for a trailling zero.

<H4><a name="Fl_Preferences.group">const char
*Fl_Preferences::group(int ix)</a></H4>
Expand Down
29 changes: 19 additions & 10 deletions src/Fl_Preferences.cxx
@@ -1,5 +1,5 @@
//
// "$Id: Fl_Preferences.cxx,v 1.1.2.14 2002/05/16 20:53:22 matthiaswm Exp $"
// "$Id: Fl_Preferences.cxx,v 1.1.2.15 2002/05/17 21:17:05 matthiaswm Exp $"
//
// Preferences methods for the Fast Light Tool Kit (FLTK).
//
Expand Down Expand Up @@ -700,8 +700,10 @@ Fl_Preferences::RootNode::~RootNode()
write();
if ( filename_ )
free( filename_ );
delete vendor_;
delete application_;
if ( vendor_ )
free( vendor_ );
if ( application_ )
free( application_ );
delete prefs_->node;
}

Expand Down Expand Up @@ -795,13 +797,19 @@ Fl_Preferences::Node::~Node()
nx = nd->next_;
delete nd;
}
for ( int i = 0; i < nEntry; i++ )
if ( entry )
{
delete entry[i].name;
delete entry[i].value;
for ( int i = 0; i < nEntry; i++ )
{
if ( entry[i].name )
free( entry[i].name );
if ( entry[i].value )
free( entry[i].value );
}
free( entry );
}
delete[] entry;
if ( path_ ) free( path_ );
if ( path_ )
free( path_ );
}

// recursively check if any entry is dirty (was changed after loading a fresh prefs file)
Expand Down Expand Up @@ -881,7 +889,8 @@ void Fl_Preferences::Node::set( const char *name, const char *value )
if ( !value ) return; // annotation
if ( strcmp( value, entry[i].value ) != 0 )
{
delete entry[i].value;
if ( entry[i].value )
free( entry[i].value );
entry[i].value = strdup( value );
dirty_ = 1;
}
Expand Down Expand Up @@ -1067,5 +1076,5 @@ char Fl_Preferences::Node::remove()


//
// End of "$Id: Fl_Preferences.cxx,v 1.1.2.14 2002/05/16 20:53:22 matthiaswm Exp $".
// End of "$Id: Fl_Preferences.cxx,v 1.1.2.15 2002/05/17 21:17:05 matthiaswm Exp $".
//
2 changes: 1 addition & 1 deletion test/preferences.fl
Expand Up @@ -196,7 +196,7 @@ Fl_Preferences app( Fl_Preferences::USER, "fltk.org", "test/preferences" );
app.getUserdataPath( path, sizeof(path) );

Fl_Preferences bed( app, "Bed" );
bed.get( "alarm", buffer, "8:00", 80 );
bed.get( "alarm", buffer, "8:00", 79 );
wAlarm->value( buffer );

bed.get( "ampm", intValue, 0 );
Expand Down

0 comments on commit dc5fa84

Please sign in to comment.