mirror of
https://github.com/cosinekitty/astronomy.git
synced 2026-05-18 22:01:42 -04:00
Run cppcheck. Fixed errors in C code found by cppcheck.
This commit is contained in:
4
.github/workflows/astronomy-engine-tests.yml
vendored
4
.github/workflows/astronomy-engine-tests.yml
vendored
@@ -23,10 +23,10 @@ jobs:
|
||||
run: python -m pip install --upgrade pip && pip install pylint mypy
|
||||
- name: Install documentation tools Linux
|
||||
if: startsWith(matrix.os, 'ubuntu')
|
||||
run: sudo apt install -y doxygen xsltproc
|
||||
run: sudo apt install -y doxygen xsltproc cppcheck
|
||||
- name: Install documentation tools macOS
|
||||
if: startsWith(matrix.os, 'macOS')
|
||||
run: HOMEBREW_NO_AUTO_UPDATE=1 brew install doxygen
|
||||
run: HOMEBREW_NO_AUTO_UPDATE=1 brew install doxygen cppcheck
|
||||
- name: Init Node.js 16
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
|
||||
@@ -25,6 +25,7 @@ The following tools are required for developers:
|
||||
- doxygen
|
||||
- xsltproc
|
||||
- coreutils
|
||||
- cppcheck
|
||||
- Java Developer Kit (JDK), for Kotlin.
|
||||
- Hint for quick start: install [Android Developer Studio](https://developer.android.com/studio)
|
||||
or the Community version of [IntelliJ IDEA](https://www.jetbrains.com/idea/).
|
||||
|
||||
@@ -6833,7 +6833,7 @@ static int DE405_Check(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
nscanned = sscanf(line, "%10[A-Za-z] %lf %lf %lf %lf %lf %lf", name, &pos[0], &pos[1], &pos[2], &vel[0], &vel[1], &vel[2]);
|
||||
nscanned = sscanf(line, "%7[A-Za-z] %lf %lf %lf %lf %lf %lf", name, &pos[0], &pos[1], &pos[2], &vel[0], &vel[1], &vel[2]);
|
||||
if (nscanned != 7)
|
||||
FAIL("C DE405_Check(%s line %d): expected 7 tokens, found %d\n", filename, lnum, nscanned);
|
||||
body = Astronomy_BodyCode(name);
|
||||
@@ -7126,7 +7126,7 @@ static int MoonNodes(void)
|
||||
if (strlen(line) < 40)
|
||||
FAIL("C MoonNodes(%s line %d): line is too short\n", filename, lnum);
|
||||
|
||||
nscanned = sscanf(line, "%c %20s %lf %lf", &kind, date, &ra, &dec);
|
||||
nscanned = sscanf(line, "%c %17s %lf %lf", &kind, date, &ra, &dec);
|
||||
if (nscanned != 4)
|
||||
FAIL("C MoonNodes(%s line %d): syntax error\n", filename, lnum);
|
||||
|
||||
|
||||
@@ -82,6 +82,7 @@ cd generate || Fail "Cannot change back to generate directory."
|
||||
|
||||
echo ""
|
||||
echo "Building C source code for 'generate' program."
|
||||
cppcheck --error-exitcode=9 generate.c || exit 1
|
||||
./build || Fail "Could not build 'generate' program from source."
|
||||
|
||||
mkdir -pv output temp apsides || Fail "Error creating directories."
|
||||
|
||||
@@ -541,6 +541,7 @@ static astro_ecliptic_t EclError(astro_status_t status)
|
||||
{
|
||||
astro_ecliptic_t ecl;
|
||||
ecl.status = status;
|
||||
ecl.elon = ecl.elat = NAN;
|
||||
ecl.vec = VecError(status, TimeError());
|
||||
return ecl;
|
||||
}
|
||||
@@ -660,11 +661,12 @@ static astro_transit_t TransitErr(astro_status_t status)
|
||||
return transit;
|
||||
}
|
||||
|
||||
static astro_axis_t AxisErr(astro_status_t status)
|
||||
static astro_axis_t AxisErr(astro_status_t status, astro_time_t time)
|
||||
{
|
||||
astro_axis_t axis;
|
||||
axis.status = status;
|
||||
axis.ra = axis.dec = NAN;
|
||||
axis.ra = axis.dec = axis.spin = NAN;
|
||||
axis.north = VecError(status, time);
|
||||
return axis;
|
||||
}
|
||||
|
||||
@@ -4422,6 +4424,7 @@ astro_state_vector_t Astronomy_HelioState(astro_body_t body, astro_time_t time)
|
||||
state.y = vec.y;
|
||||
state.z = vec.z;
|
||||
state.vx = state.vy = state.vz = 0.0;
|
||||
state.t = time;
|
||||
state.status = vec.status;
|
||||
return state;
|
||||
}
|
||||
@@ -11060,7 +11063,7 @@ static astro_axis_t EarthRotationAxis(astro_time_t *time)
|
||||
/* Derive angular values: right ascension and declination. */
|
||||
equ = Astronomy_EquatorFromVector(axis.north);
|
||||
if (equ.status != ASTRO_SUCCESS)
|
||||
return AxisErr(equ.status);
|
||||
return AxisErr(equ.status, *time);
|
||||
axis.ra = equ.ra;
|
||||
axis.dec = equ.dec;
|
||||
|
||||
@@ -11283,7 +11286,7 @@ astro_axis_t Astronomy_RotationAxis(astro_body_t body, astro_time_t *time)
|
||||
break;
|
||||
|
||||
default:
|
||||
return AxisErr(ASTRO_INVALID_BODY);
|
||||
return AxisErr(ASTRO_INVALID_BODY, *time);
|
||||
}
|
||||
|
||||
axis.ra = ra / 15.0; /* convert degrees to sidereal hours */
|
||||
|
||||
@@ -8,6 +8,8 @@ Fail()
|
||||
[[ "$1" == "" || "$1" == "-v" ]] || Fail "Invalid command line options."
|
||||
[[ -z "${CPP}" ]] && CPP=g++
|
||||
|
||||
cppcheck --error-exitcode=9 ../source/c/astronomy.c ctest.c || exit 1
|
||||
|
||||
# Verify that the source can be built as modern C++.
|
||||
${CPP} -x c++ -std=c++17 -c -Wall -Werror -O3 ../source/c/astronomy.c || Fail "Cannot compile as C++"
|
||||
rm -f astronomy.o
|
||||
|
||||
@@ -547,6 +547,7 @@ static astro_ecliptic_t EclError(astro_status_t status)
|
||||
{
|
||||
astro_ecliptic_t ecl;
|
||||
ecl.status = status;
|
||||
ecl.elon = ecl.elat = NAN;
|
||||
ecl.vec = VecError(status, TimeError());
|
||||
return ecl;
|
||||
}
|
||||
@@ -666,11 +667,12 @@ static astro_transit_t TransitErr(astro_status_t status)
|
||||
return transit;
|
||||
}
|
||||
|
||||
static astro_axis_t AxisErr(astro_status_t status)
|
||||
static astro_axis_t AxisErr(astro_status_t status, astro_time_t time)
|
||||
{
|
||||
astro_axis_t axis;
|
||||
axis.status = status;
|
||||
axis.ra = axis.dec = NAN;
|
||||
axis.ra = axis.dec = axis.spin = NAN;
|
||||
axis.north = VecError(status, time);
|
||||
return axis;
|
||||
}
|
||||
|
||||
@@ -5583,6 +5585,7 @@ astro_state_vector_t Astronomy_HelioState(astro_body_t body, astro_time_t time)
|
||||
state.y = vec.y;
|
||||
state.z = vec.z;
|
||||
state.vx = state.vy = state.vz = 0.0;
|
||||
state.t = time;
|
||||
state.status = vec.status;
|
||||
return state;
|
||||
}
|
||||
@@ -12676,7 +12679,7 @@ static astro_axis_t EarthRotationAxis(astro_time_t *time)
|
||||
/* Derive angular values: right ascension and declination. */
|
||||
equ = Astronomy_EquatorFromVector(axis.north);
|
||||
if (equ.status != ASTRO_SUCCESS)
|
||||
return AxisErr(equ.status);
|
||||
return AxisErr(equ.status, *time);
|
||||
axis.ra = equ.ra;
|
||||
axis.dec = equ.dec;
|
||||
|
||||
@@ -12899,7 +12902,7 @@ astro_axis_t Astronomy_RotationAxis(astro_body_t body, astro_time_t *time)
|
||||
break;
|
||||
|
||||
default:
|
||||
return AxisErr(ASTRO_INVALID_BODY);
|
||||
return AxisErr(ASTRO_INVALID_BODY, *time);
|
||||
}
|
||||
|
||||
axis.ra = ra / 15.0; /* convert degrees to sidereal hours */
|
||||
|
||||
Reference in New Issue
Block a user