Commit 8888bdba authored by Csaba Kertesz's avatar Csaba Kertesz

Fix some sanitizer findings, update .gitignore and add a source file to compilation

parent 5a51c289
......@@ -74,3 +74,4 @@ doc/index.cache.bz2
# Generated source/header files
kstars/*adaptor.cpp
kstars/*adaptor.h
unitybuild_*.cpp
......@@ -603,7 +603,7 @@ set(kstars_skyobjects_SRCS
skyobjects/constellationsart.cpp
skyobjects/deepskyobject.cpp
# skyobjects/jupitermoons.cpp
# skyobjects/planetmoons.cpp
skyobjects/planetmoons.cpp
skyobjects/ksasteroid.cpp
skyobjects/kscomet.cpp
skyobjects/ksmoon.cpp
......
......@@ -187,6 +187,9 @@ bool dms::setFromString(const QString &str, bool isDeg)
int dms::arcmin(void) const
{
if (std::isnan(D))
return 0;
int am = int(float(60.0 * (fabs(D) - abs(degree()))));
if (D < 0.0 && D > -1.0) //angle less than zero, but greater than -1.0
{
......@@ -197,6 +200,9 @@ int dms::arcmin(void) const
int dms::arcsec(void) const
{
if (std::isnan(D))
return 0;
int as = int(float(60.0 * (60.0 * (fabs(D) - abs(degree())) - abs(arcmin()))));
//If the angle is slightly less than 0.0, give ArcSec a neg. sgn.
if (degree() == 0 && arcmin() == 0 && D < 0.0)
......@@ -208,6 +214,9 @@ int dms::arcsec(void) const
int dms::marcsec(void) const
{
if (std::isnan(D))
return 0;
int as = int(float(1000.0 * (60.0 * (60.0 * (fabs(D) - abs(degree())) - abs(arcmin())) - abs(arcsec()))));
//If the angle is slightly less than 0.0, give ArcSec a neg. sgn.
if (degree() == 0 && arcmin() == 0 && arcsec() == 0 && D < 0.0)
......@@ -249,6 +258,9 @@ int dms::msecond(void) const
const dms dms::reduce(void) const
{
if (std::isnan(D))
return dms(0);
return dms(D - 360.0 * floor(D / 360.0));
}
......@@ -307,6 +319,9 @@ dms dms::fromString(const QString &st, bool deg)
void dms::reduceToRange(enum dms::AngleRanges range)
{
if (std::isnan(D))
return;
switch (range)
{
case MINUSPI_TO_PI:
......
......@@ -123,7 +123,13 @@ class dms
/** @return integer degrees portion of the angle
*/
inline int degree() const { return int(D); }
inline int degree() const
{
if (std::isnan(D))
return 0;
return int(D);
}
/** @return integer arcminutes portion of the angle.
* @note an arcminute is 1/60 degree.
......
......@@ -39,7 +39,7 @@ class ImageExporter : public QObject
/**
* @short Constructor
*/
ImageExporter(QObject *parent);
explicit ImageExporter(QObject *parent = nullptr);
/**
* @short Destructor
......
......@@ -107,9 +107,17 @@ float64 SpatialVector::dec()
//
void SpatialVector::normalize()
{
float64 sum;
sum = x_ * x_ + y_ * y_ + z_ * z_;
float64 sum = x_ * x_ + y_ * y_ + z_ * z_;
sum = sqrt(sum);
if (sum == 0)
{
x_ = 0;
y_ = 0;
z_ = 0;
return;
}
x_ /= sum;
y_ /= sum;
z_ /= sum;
......
......@@ -76,7 +76,7 @@ class SkyMapComposite : public QObject, public SkyComposite
*Constructor
*@p parent pointer to the parent SkyComponent
*/
explicit SkyMapComposite(SkyComposite *parent);
explicit SkyMapComposite(SkyComposite *parent = nullptr);
~SkyMapComposite();
......
......@@ -75,7 +75,11 @@ KSComet::KSComet(const QString &_s, const QString &imfile, long double _JD, doub
JDp = KStarsDateTime(QDate(year, month, day), QTime(h, m, s)).djd();
//compute the semi-major axis, a:
a = q / (1.0 - e);
if (e == 1)
a = 0;
else
a = q / (1.0-e);
//Compute the orbital Period from Kepler's 3rd law:
P = 365.2568984 * pow(a, 1.5); //period in days
......
......@@ -302,7 +302,9 @@ void KSPlanetBase::findPhase()
{
/* Compute the phase of the planet in degrees */
double earthSun = KStarsData::Instance()->skyComposite()->earth()->rsun();
double cosPhase = (rsun() * rsun() + rearth() * rearth() - earthSun * earthSun) / (2 * rsun() * rearth());
double cosPhase = (rsun()*rearth() == 0 ? 0 : (rsun()*rsun() + rearth()*rearth() - earthSun*earthSun)
/ (2 * rsun() * rearth() ));
Phase = acos(cosPhase) * 180.0 / dms::PI;
/* More elegant way of doing it, but requires the Sun.
TODO: Switch to this if and when we make KSSun a singleton */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment