Skip to content

Commit 3a7c13a

Browse files
committed
Fix endless loop in generator bug
Marksu Heidelberg <[email protected]> contributed a patch to fix a bug that he also found with the -generator which resulted in an endless loop. If the start address of a partial record is >= 0xFFFFFFF1, there is a 32 overflow when adding 255 (the maximum record data length). But the result with this address is still correct (see documentation "If the maximum is given as zero then the range extends to the end of the address space."), the endless loop appears when using address 0xFFFFFFF2 or higher. But can be previously reproduced with this command: srec_cat -generate 0xFFFFFF02 0xFFFFFF03 -constant 0xAB
1 parent 78067cb commit 3a7c13a

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

srecord/input/generator.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ srecord::input_generator::read(srecord::record &result)
5353
// Calculate the address range for this chunk of data. Use the
5454
// biggest record size available.
5555
//
56-
unsigned long addr = range.get_lowest();
57-
interval partial(addr, addr + srecord::record::max_data_length);
56+
interval::data_t addr = range.get_lowest();
57+
interval::data_t end = addr + srecord::record::max_data_length;
58+
if (end < addr)
59+
end = 0xFFFFFFFF;
60+
interval partial(addr, end);
5861
partial *= range;
5962

6063
//

test/02/t0254a.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/sh
2+
#
3+
# srecord - Manipulate EPROM load files
4+
# Copyright (C) 2014 Markus Heidelberg
5+
#
6+
# This program is free software; you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation; either version 3 of the License, or (at
9+
# your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
# General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
#
19+
20+
TEST_SUBJECT="generate near end of address space"
21+
. test_prelude
22+
23+
cat > test.ok << 'fubar'
24+
S00600004844521B
25+
S306FFFFFF02AB4F
26+
S5030001FB
27+
fubar
28+
if test $? -ne 0; then no_result; fi
29+
30+
srec_cat -generate 0xFFFFFF02 0xFFFFFF03 -constant 0xAB -o test.out -header HDR
31+
if test $? -ne 0; then fail; fi
32+
33+
diff test.ok test.out
34+
if test $? -ne 0; then fail; fi
35+
36+
#
37+
# The things tested here, worked.
38+
# No other guarantees are made.
39+
#
40+
pass
41+
42+
# vim: set ts=8 sw=4 et :

0 commit comments

Comments
 (0)