From e5c1ddeb3d19c8fff7625c03cd045bc7ff167283 Mon Sep 17 00:00:00 2001 From: Sean Alling Date: Sun, 15 Jan 2023 14:54:24 -0800 Subject: [PATCH 1/2] [bugfix] Added tests showing rounding failure Three tests added, one for each rounding method, which will fail when providing input causing exception. --- test/02/t0262a.sh | 34 ++++++++++++++++++++++++++++++++++ test/02/t0263a.sh | 35 +++++++++++++++++++++++++++++++++++ test/02/t0264a.sh | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 test/02/t0262a.sh create mode 100644 test/02/t0263a.sh create mode 100644 test/02/t0264a.sh diff --git a/test/02/t0262a.sh b/test/02/t0262a.sh new file mode 100644 index 00000000..477e6b1e --- /dev/null +++ b/test/02/t0262a.sh @@ -0,0 +1,34 @@ +#!/bin/sh +# +# srecord - Manipulate EPROM load files +# Copyright (C) 2014 Markus Heidelberg +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +TEST_SUBJECT="-Round_Up" +. test_prelude.sh + +cat > test.ok << 'fubar' +S00600004844521B +S306FFFFFFFE00FE +S5030001FB +fubar +if test $? -ne 0; then no_result; fi + +srec_cat test.in -offset - 1 -Round_Up 0 -o test.out + +if test $? -ne 1; then fail; fi + +pass diff --git a/test/02/t0263a.sh b/test/02/t0263a.sh new file mode 100644 index 00000000..085fdc78 --- /dev/null +++ b/test/02/t0263a.sh @@ -0,0 +1,35 @@ +#!/bin/sh +# +# srecord - Manipulate EPROM load files +# Copyright (C) 2014 Markus Heidelberg +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +TEST_SUBJECT="-Round_Down" +. test_prelude.sh + +cat > test.ok << 'fubar' +S00600004844521B +S306FFFFFFFE00FE +S5030001FB +fubar +if test $? -ne 0; then no_result; fi + +srec_cat test.in -offset - 1 -Round_Down 0 -o test.out + +if test $? -ne 1; then fail; fi + + +pass diff --git a/test/02/t0264a.sh b/test/02/t0264a.sh new file mode 100644 index 00000000..1c5d9bb1 --- /dev/null +++ b/test/02/t0264a.sh @@ -0,0 +1,35 @@ +#!/bin/sh +# +# srecord - Manipulate EPROM load files +# Copyright (C) 2014 Markus Heidelberg +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +TEST_SUBJECT="-Round_Nearest" +. test_prelude.sh + +cat > test.ok << 'fubar' +S00600004844521B +S306FFFFFFFE00FE +S5030001FB +fubar +if test $? -ne 0; then no_result; fi + +srec_cat test.in -offset - 1 -Round_Nearest 0 -o test.out + +if test $? -ne 1; then fail; fi + + +pass From 87d1fd9dd7167dd0cbbb01f2eaf04ab09f974b91 Mon Sep 17 00:00:00 2001 From: Sean Alling Date: Sun, 15 Jan 2023 14:57:09 -0800 Subject: [PATCH 2/2] [bugfix] Stop execution when invalid input detected If value provided by user for rounding is 0, trigger fatal error signaling 0 is not valid input. --- doc/dictionaries/names.txt | 3 +++ srecord/arglex/tool/get_number.cc | 12 ++++++++++++ test/02/t0262a.sh | 18 +++++++++--------- test/02/t0263a.sh | 19 +++++++++---------- test/02/t0264a.sh | 19 +++++++++---------- 5 files changed, 42 insertions(+), 29 deletions(-) diff --git a/doc/dictionaries/names.txt b/doc/dictionaries/names.txt index 64b66bf5..6fc1049c 100644 --- a/doc/dictionaries/names.txt +++ b/doc/dictionaries/names.txt @@ -1,6 +1,7 @@ aefinish aenbr Alin +Alling Altera Anselmi AOMF @@ -84,6 +85,7 @@ netpmb Niederstrasser Nivas NSIS +oceanofthelost opensource Ozcelik patryks @@ -105,6 +107,7 @@ rpmbuild Sadowski Schmitt SDSMAC +Sean segfault Seitz Sergeev diff --git a/srecord/arglex/tool/get_number.cc b/srecord/arglex/tool/get_number.cc index eee8217a..66f9db34 100644 --- a/srecord/arglex/tool/get_number.cc +++ b/srecord/arglex/tool/get_number.cc @@ -98,6 +98,10 @@ srecord::arglex_tool::get_number(const char *caption) case token_round_down: token_next(); multiple = get_number("-round-down"); + if (multiple == 0) + { + fatal_error("-Round_Down value must not be 0"); + } value /= multiple; value *= multiple; break; @@ -105,6 +109,10 @@ srecord::arglex_tool::get_number(const char *caption) case token_round_up: token_next(); multiple = get_number("-round-up"); + if (multiple == 0) + { + fatal_error("-Round_Up value must not be 0"); + } value = (value + multiple - 1) / multiple; value *= multiple; break; @@ -112,6 +120,10 @@ srecord::arglex_tool::get_number(const char *caption) case token_round_nearest: token_next(); multiple = get_number("-round-nearest"); + if (multiple == 0) + { + fatal_error("-Round_Nearest value must not be 0"); + } value = (value + multiple / 2) / multiple; value *= multiple; break; diff --git a/test/02/t0262a.sh b/test/02/t0262a.sh index 477e6b1e..418d2c8b 100644 --- a/test/02/t0262a.sh +++ b/test/02/t0262a.sh @@ -1,7 +1,7 @@ #!/bin/sh # # srecord - Manipulate EPROM load files -# Copyright (C) 2014 Markus Heidelberg +# Copyright (C) 2023 Sean Alling # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,15 +20,15 @@ TEST_SUBJECT="-Round_Up" . test_prelude.sh +srec_cat -generate 0 8 -constant 0 -offset - 1 -Round_Up 0 \ + 2> test.out + +if test $? -ne 1; then fail; fi + cat > test.ok << 'fubar' -S00600004844521B -S306FFFFFFFE00FE -S5030001FB +srec_cat: -Round_Up value must not be 0 fubar if test $? -ne 0; then no_result; fi -srec_cat test.in -offset - 1 -Round_Up 0 -o test.out - -if test $? -ne 1; then fail; fi - -pass +diff -u test.ok test.out +if test $? -ne 0; then fail; fi diff --git a/test/02/t0263a.sh b/test/02/t0263a.sh index 085fdc78..1d4ee151 100644 --- a/test/02/t0263a.sh +++ b/test/02/t0263a.sh @@ -1,7 +1,7 @@ #!/bin/sh # # srecord - Manipulate EPROM load files -# Copyright (C) 2014 Markus Heidelberg +# Copyright (C) 2023 Sean Alling # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,16 +20,15 @@ TEST_SUBJECT="-Round_Down" . test_prelude.sh -cat > test.ok << 'fubar' -S00600004844521B -S306FFFFFFFE00FE -S5030001FB -fubar -if test $? -ne 0; then no_result; fi - -srec_cat test.in -offset - 1 -Round_Down 0 -o test.out +srec_cat -generate 0 8 -constant 0 -offset - 1 -Round_Up 0 \ + 2> test.out if test $? -ne 1; then fail; fi +cat > test.ok << 'fubar' +srec_cat: -Round_Up value must not be 0 +fubar +if test $? -ne 0; then no_result; fi -pass +diff -u test.ok test.out +if test $? -ne 0; then fail; fi diff --git a/test/02/t0264a.sh b/test/02/t0264a.sh index 1c5d9bb1..07c778cc 100644 --- a/test/02/t0264a.sh +++ b/test/02/t0264a.sh @@ -1,7 +1,7 @@ #!/bin/sh # # srecord - Manipulate EPROM load files -# Copyright (C) 2014 Markus Heidelberg +# Copyright (C) 2023 Sean Alling # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,16 +20,15 @@ TEST_SUBJECT="-Round_Nearest" . test_prelude.sh -cat > test.ok << 'fubar' -S00600004844521B -S306FFFFFFFE00FE -S5030001FB -fubar -if test $? -ne 0; then no_result; fi - -srec_cat test.in -offset - 1 -Round_Nearest 0 -o test.out +srec_cat -generate 0 8 -constant 0 -offset - 1 -Round_Nearest 0 \ + 2> test.out if test $? -ne 1; then fail; fi +cat > test.ok << 'fubar' +srec_cat: -Round_Nearest value must not be 0 +fubar +if test $? -ne 0; then no_result; fi -pass +diff -u test.ok test.out +if test $? -ne 0; then fail; fi