Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/intelhex.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace intelhex

value_type& operator[](address_type); //Array access operator
value_type get(address_type); // Return the value at address
void set(address_type, value_type); // Set the value at address
void set(address_type, value_type, bool ignore_fill=false); // Set the value at address

void load(const std::string&); // Load from a file
void read(std::istream &); // Read data from an input stream
Expand Down
34 changes: 18 additions & 16 deletions src/intelhex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ namespace intelhex
}

// Set the value at address or create a new element using value
void hex_data::set(address_type address, value_type value)
void hex_data::set(address_type address, value_type value, bool ignore_fill)
{
if( value == fill() ) // Handle fill values
if( !ignore_fill && value == fill() ) // Handle fill values
{
erase(address); // If the address is already set, erase it
return;
Expand Down Expand Up @@ -93,19 +93,21 @@ namespace intelhex
// Merge adjacent blocks
void hex_data::compact()
{
iterator previous = blocks.begin();
iterator i = previous;

for(++i; i != blocks.end(); ++i)
{
if( (previous->first + previous->second.size()) == i->first )
{
previous->second.insert(previous->second.end(), i->second.begin(), i->second.end());
blocks.erase(i);
i = previous;
}
previous = i;
}
if (blocks.size() > 0) {
iterator previous = blocks.begin();
iterator i = previous;

for(++i; i != blocks.end(); ++i)
{
if( (previous->first + previous->second.size()) == i->first )
{
previous->second.insert(previous->second.end(), i->second.begin(), i->second.end());
blocks.erase(i);
i = previous;
}
previous = i;
}
}
}

// Delete all allocated memory
Expand Down Expand Up @@ -290,7 +292,7 @@ namespace intelhex
while( (i!=blocks.rend()) && (i->first > addr))
++i;

if( (addr - i->first) > i->second.size() )
if( (addr - i->first) >= i->second.size() )
return false;
else
return true;
Expand Down