FLTK logo

STR #2823

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 Home  |  Articles & FAQs  |  Bugs & Features  |  Documentation  |  Download  |  Screenshots  ]
 

Return to Bugs & Features | Roadmap 1.3 | SVN ⇄ GIT ]

STR #2823

Application:FLTK Library
Status:1 - Closed w/Resolution
Priority:2 - Low, e.g. a documentation error or undocumented side-effect
Scope:3 - Applies to all machines and operating systems
Subsystem:Core Library
Summary:Fl_Preferences unecessary setting of dirty attribute
Version:1.3-current
Created By:popej
Assigned To:matt
Fix Version:1.4-current (SVN: v12305)
Update Notification:

Receive EMails Don't Receive EMails

Trouble Report Files:

No files


Trouble Report Comments:


Name/Time/Date Text  
 
#1 popej
14:14 Apr 12, 2012
Class Fl_Preferences uses to overwrite preferences file even when data is not changed. Simple reading preferences can result in writing to file.

I have traced problem to 2 functions:

// add more data to an existing entry
void Fl_Preferences::Node::add( const char *line ) {
  if ( lastEntrySet<0 || lastEntrySet>=nEntry_ ) return;
  char *&dst = entry_[ lastEntrySet ].value;
  size_t a = strlen( dst );
  size_t b = strlen( line );
  dst = (char*)realloc( dst, a+b+1 );
  memcpy( dst+a, line, b+1 );
  dirty_ = 1;  // <= error
}

Function add() is used only when reading data from a file, there is no reason to mark node as dirty.

// add a child to this node and set its path (try to find it first...)
Fl_Preferences::Node *Fl_Preferences::Node::addChild( const char *path ) {
  sprintf( nameBuffer, "%s/%s", path_, path );
  char *name = strdup( nameBuffer );
  Node *nd = find( name );
  free( name );
  dirty_ = 1;  // <= too early
  updateIndex();
  return nd;
}

Function addChild() can be used when reading entry from a group. Even if it creates new empty node, there is no need to mark parent node as dirty until there is something written to new node.
 
 
#2 matt
14:04 Jul 07, 2017
Fixed in Subversion repository.

Part 1 was truly an oversight. Part 2 is a bit harder for some use cases. I moved this into the code that actually creates a new node if needed. Also, I cleared all dirty flags after loading from file, because everything should really be in sync at this particular point. This fixes an unnecessary write operation when the Fl_Preferences node is destroyed.
 
     

Return to Bugs & Features ]

 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.