Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] rounding exception #36

Merged
Merged
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
3 changes: 3 additions & 0 deletions doc/dictionaries/names.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
aefinish
aenbr
Alin
Alling
Altera
Anselmi
AOMF
Expand Down Expand Up @@ -84,6 +85,7 @@ netpmb
Niederstrasser
Nivas
NSIS
oceanofthelost
opensource
Ozcelik
patryks
Expand All @@ -105,6 +107,7 @@ rpmbuild
Sadowski
Schmitt
SDSMAC
Sean
segfault
Seitz
Sergeev
Expand Down
12 changes: 12 additions & 0 deletions srecord/arglex/tool/get_number.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,32 @@ 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;

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;

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;
Expand Down
34 changes: 34 additions & 0 deletions test/02/t0262a.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/sh
#
# srecord - Manipulate EPROM load files
# 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
# 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 <http://www.gnu.org/licenses/>.
#

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'
oceanofthelost marked this conversation as resolved.
Show resolved Hide resolved
srec_cat: -Round_Up value must not be 0
fubar
if test $? -ne 0; then no_result; fi

diff -u test.ok test.out
if test $? -ne 0; then fail; fi
34 changes: 34 additions & 0 deletions test/02/t0263a.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/sh
#
# srecord - Manipulate EPROM load files
# 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
# 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 <http://www.gnu.org/licenses/>.
#

TEST_SUBJECT="-Round_Down"
. 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'
srec_cat: -Round_Up value must not be 0
fubar
if test $? -ne 0; then no_result; fi

diff -u test.ok test.out
if test $? -ne 0; then fail; fi
34 changes: 34 additions & 0 deletions test/02/t0264a.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/sh
#
# srecord - Manipulate EPROM load files
# 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
# 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 <http://www.gnu.org/licenses/>.
#

TEST_SUBJECT="-Round_Nearest"
. test_prelude.sh

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

diff -u test.ok test.out
if test $? -ne 0; then fail; fi