From 0047595373e8b3e81768195dad4dcc4695bd310a Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Tue, 6 Jun 2017 18:27:54 +0200 Subject: [PATCH] Fix defects detected by coverity scan --- src/algorithms/libs/rtklib/rtklib_ephemeris.cc | 2 +- src/algorithms/libs/rtklib/rtklib_pntpos.cc | 3 ++- src/algorithms/libs/rtklib/rtklib_ppp.cc | 13 +++++++++++-- src/algorithms/libs/rtklib/rtklib_rtkcmn.cc | 13 ++++++++----- src/algorithms/libs/rtklib/rtklib_solution.cc | 2 +- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/algorithms/libs/rtklib/rtklib_ephemeris.cc b/src/algorithms/libs/rtklib/rtklib_ephemeris.cc index 07954f822..7fb213366 100644 --- a/src/algorithms/libs/rtklib/rtklib_ephemeris.cc +++ b/src/algorithms/libs/rtklib/rtklib_ephemeris.cc @@ -92,7 +92,7 @@ double var_uraeph(int ura) 2.4, 3.4, 4.85, 6.85, 9.65, 13.65, 24.0, 48.0, 96.0, 192.0, 384.0, 768.0, 1536.0, 3072.0, 6144.0 }; - return ura < 0 || 15 < ura ? std::pow(6144.0, 2.0) : std::pow(ura_value[ura], 2.0); + return ura < 0 || 14 < ura ? std::pow(6144.0, 2.0) : std::pow(ura_value[ura], 2.0); } diff --git a/src/algorithms/libs/rtklib/rtklib_pntpos.cc b/src/algorithms/libs/rtklib/rtklib_pntpos.cc index 1f95ba32f..6bf14c19e 100644 --- a/src/algorithms/libs/rtklib/rtklib_pntpos.cc +++ b/src/algorithms/libs/rtklib/rtklib_pntpos.cc @@ -364,7 +364,8 @@ int valsol(const double *azel, const int *vsat, int n, const prcopt_t *opt, const double *v, int nv, int nx, char *msg) { - double azels[MAXOBS*2], dop[4], vv; + double azels[MAXOBS*2] = {0}; + double dop[4], vv; int i, ns; trace(3, "valsol : n=%d nv=%d\n", n, nv); diff --git a/src/algorithms/libs/rtklib/rtklib_ppp.cc b/src/algorithms/libs/rtklib/rtklib_ppp.cc index 5fe24ed68..2b606f07e 100644 --- a/src/algorithms/libs/rtklib/rtklib_ppp.cc +++ b/src/algorithms/libs/rtklib/rtklib_ppp.cc @@ -461,7 +461,11 @@ int fix_amb_ILS(rtk_t *rtk, int *sat1, int *sat2, int *NW, int n) sat2[m] = sat2[i]; NW[m++] = NW[i]; } - if (m<3) return 0; + if (m<3) + { + free(B1); free(N1); free(D); free(E); free(Q); free(NC); + return 0; + } /* covariance of narrow-lane ambiguities */ matmul("TN", m, rtk->nx, rtk->nx, 1.0, D, rtk->P, 0.0, E); @@ -471,9 +475,14 @@ int fix_amb_ILS(rtk_t *rtk, int *sat1, int *sat2, int *NW, int n) if ((info = lambda(m, 2, B1, Q, N1, s))) { trace(2, "lambda error: info=%d\n", info); + free(B1); free(N1); free(D); free(E); free(Q); free(NC); + return 0; + } + if (s[0] <= 0.0) + { + free(B1); free(N1); free(D); free(E); free(Q); free(NC); return 0; } - if (s[0] <= 0.0) return 0; rtk->sol.ratio = (float)(MIN_PPP(s[1]/s[0], 999.9)); diff --git a/src/algorithms/libs/rtklib/rtklib_rtkcmn.cc b/src/algorithms/libs/rtklib/rtklib_rtkcmn.cc index ea6d31f5d..d9eed2887 100644 --- a/src/algorithms/libs/rtklib/rtklib_rtkcmn.cc +++ b/src/algorithms/libs/rtklib/rtklib_rtkcmn.cc @@ -3234,12 +3234,12 @@ void createdir(const char *path) char buff[1024], *p; //tracet(3, "createdir: path=%s\n", path); - strcpy(buff, path); + if(strlen(path) < 1025) strcpy(buff, path); + else trace(1, "path is too long"); if (!(p = strrchr(buff, FILEPATHSEP))) return; *p = '\0'; - if(mkdir(buff, 0777) == 0) {} - else trace(1, "Error creating folder"); + if(mkdir(buff, 0777) != 0) trace(1, "Error creating folder"); } @@ -3257,7 +3257,9 @@ int repstr(char *str, const char *pat, const char *rep) r += sprintf(r, "%s", rep); } if (p <= str) return 0; - strcpy(r, p); + + if(strlen(p) < 1025 ) strcpy(r, p); + else trace(1, "pat array is too long"); strcpy(str, buff); return 1; } @@ -3945,7 +3947,8 @@ int rtk_uncompress(const char *file, char *uncfile) trace(3, "rtk_uncompress: file=%s\n", file); - strcpy(tmpfile, file); + if(strlen(file) < 1025) strcpy(tmpfile, file); + else trace(1, "file array is too long"); if (!(p = strrchr(tmpfile, '.'))) return 0; /* uncompress by gzip */ diff --git a/src/algorithms/libs/rtklib/rtklib_solution.cc b/src/algorithms/libs/rtklib/rtklib_solution.cc index 82f804305..d4bf306fc 100644 --- a/src/algorithms/libs/rtklib/rtklib_solution.cc +++ b/src/algorithms/libs/rtklib/rtklib_solution.cc @@ -271,7 +271,7 @@ int decode_nmeagga(char **val, int n, sol_t *sol) /* decode nmea ---------------------------------------------------------------*/ int decode_nmea(char *buff, sol_t *sol) { - char *p,*q,*val[MAXFIELD]; + char *p, *q, *val[MAXFIELD] = {0}; int n = 0; trace(4,"decode_nmea: buff=%s\n",buff);