diff --git a/src/algorithms/PVT/adapters/rtklib_pvt.cc b/src/algorithms/PVT/adapters/rtklib_pvt.cc index 0de546abb..8c9d581be 100644 --- a/src/algorithms/PVT/adapters/rtklib_pvt.cc +++ b/src/algorithms/PVT/adapters/rtklib_pvt.cc @@ -194,7 +194,8 @@ RtklibPvt::RtklibPvt(ConfigurationInterface* configuration, int num_bands = 0; if ((gps_1C_count > 0) || (gal_1B_count > 0)) num_bands = 1; if (((gps_1C_count > 0) || (gal_1B_count > 0)) && (gps_2S_count > 0) ) num_bands = 2; - if (((gps_1C_count > 0) || (gal_1B_count > 0)) && (gps_2S_count > 0) && ((gal_E5a_count > 0) || (gal_E5a_count > 0))) num_bands = 3; + if (((gps_1C_count > 0) || (gal_1B_count > 0)) && ((gal_E5a_count > 0) || (gal_E5b_count > 0)) ) num_bands = 2; + if (((gps_1C_count > 0) || (gal_1B_count > 0)) && (gps_2S_count > 0) && ((gal_E5a_count > 0) || (gal_E5b_count > 0))) num_bands = 3; int number_of_frequencies = configuration->property(role + ".num_bands", num_bands); /* (1:L1, 2:L1+L2, 3:L1+L2+L5) */ if( (number_of_frequencies < 1) || (number_of_frequencies > 3) ) { @@ -382,7 +383,7 @@ RtklibPvt::RtklibPvt(ConfigurationInterface* configuration, iono_model, /* ionosphere option (IONOOPT_XXX) */ trop_model, /* troposphere option (TROPOPT_XXX) */ dynamics_model, /* dynamics model (0:none, 1:velocity, 2:accel) */ - earth_tide, /* earth tide correction (0:off,1:solid,2:solid+otl+pole) */ + earth_tide, /* earth tide correction (0:off,1:solid,2:solid+otl+pole) */ number_filter_iter, /* number of filter iteration */ 0, /* code smoothing window size (0:none) */ 0, /* interpolate reference obs (for post mission) */ diff --git a/src/algorithms/input_filter/adapters/pulse_blanking_filter.cc b/src/algorithms/input_filter/adapters/pulse_blanking_filter.cc index 4bca7a799..de0fc59f3 100644 --- a/src/algorithms/input_filter/adapters/pulse_blanking_filter.cc +++ b/src/algorithms/input_filter/adapters/pulse_blanking_filter.cc @@ -144,4 +144,3 @@ gr::basic_block_sptr PulseBlankingFilter::get_right_block() LOG(ERROR) << " Unknown input filter input/output item type conversion"; } } - diff --git a/src/algorithms/input_filter/adapters/pulse_blanking_filter.h b/src/algorithms/input_filter/adapters/pulse_blanking_filter.h index ce812556d..4382e4281 100644 --- a/src/algorithms/input_filter/adapters/pulse_blanking_filter.h +++ b/src/algorithms/input_filter/adapters/pulse_blanking_filter.h @@ -76,8 +76,6 @@ private: std::string input_item_type_; size_t input_size_; std::string output_item_type_; - double intermediate_freq_; - double sampling_freq_; std::string role_; unsigned int in_streams_; unsigned int out_streams_; 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_ionex.cc b/src/algorithms/libs/rtklib/rtklib_ionex.cc index 404cd34f9..c70a43fa6 100644 --- a/src/algorithms/libs/rtklib/rtklib_ionex.cc +++ b/src/algorithms/libs/rtklib/rtklib_ionex.cc @@ -394,15 +394,18 @@ void readtec(const char *file, nav_t *nav, int opt) trace(2, "ionex file open error %s\n", efiles[i]); continue; } - /* read ionex header */ - if (readionexh(fp, lats, lons, hgts, &rb, &nexp, dcb, rms) <= 0.0) + else { - trace(2, "ionex file format error %s\n", efiles[i]); - continue; + /* read ionex header */ + if (readionexh(fp, lats, lons, hgts, &rb, &nexp, dcb, rms) <= 0.0) + { + trace(2, "ionex file format error %s\n", efiles[i]); + fclose(fp); + continue; + } + /* read ionex body */ + readionexb(fp, lats, lons, hgts, rb, nexp, nav); } - /* read ionex body */ - readionexb(fp, lats, lons, hgts, rb, nexp, nav); - fclose(fp); } for (i = 0; i < MAXEXFILE; i++) free(efiles[i]); 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..96ccb7237 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)); @@ -481,6 +490,7 @@ int fix_amb_ILS(rtk_t *rtk, int *sat1, int *sat2, int *NW, int n) if (rtk->opt.thresar[0]>0.0 && rtk->sol.ratioopt.thresar[0]) { trace(2, "varidation error: n=%2d ratio=%8.3f\n", m, rtk->sol.ratio); + free(B1); free(N1); free(D); free(E); free(Q); free(NC); return 0; } trace(2, "varidation ok: %s n=%2d ratio=%8.3f\n", time_str(rtk->sol.time, 0), m, @@ -889,7 +899,7 @@ void testeclipse(const obsd_t *obs, int n, const nav_t *nav, double *rs) /* unit vector of sun direction (ecef) */ sunmoonpos(gpst2utc(obs[0].time), erpv, rsun, NULL, NULL); - normv3(rsun, esun); + if(normv3(rsun, esun) == 0) trace(1, "Error computing the norm"); for (i = 0;ipcvs[i] = pcv ? *pcv : pcv0; } - free(pcvs.pcv); + free(pcv); return 1; } @@ -530,7 +529,11 @@ int readfcbf(const char *file, nav_t *nav) if (!(sat = satid2no(str))) continue; ts = epoch2time(ep1); te = epoch2time(ep2); - if (!addfcb(nav, ts, te, sat, bias, std)) return 0; + if (!addfcb(nav, ts, te, sat, bias, std)) + { + fclose(fp); + return 0; + } } fclose(fp); return 1; diff --git a/src/algorithms/libs/rtklib/rtklib_rtkcmn.cc b/src/algorithms/libs/rtklib/rtklib_rtkcmn.cc index 252880b5b..dbfbebdfd 100644 --- a/src/algorithms/libs/rtklib/rtklib_rtkcmn.cc +++ b/src/algorithms/libs/rtklib/rtklib_rtkcmn.cc @@ -567,13 +567,20 @@ void setcodepri(int sys, int freq, const char *pri) trace(3, "setcodepri : sys=%d freq=%d pri=%s\n", sys, freq, pri); if (freq <= 0 || MAXFREQn; i++) { pcv = pcvs->pcv+i; @@ -2331,10 +2339,14 @@ pcv_t *searchpcv(int sat, const char *type, gtime_t time, if (pcv->te.time != 0 && timediff(pcv->te, time)<0.0) continue; return pcv; } - } + } else { - strcpy(buff, type); + if(strlen(type) < MAXANT +1 ) strcpy(buff, type); + else + { + trace(1, "type array is too long"); + } for (p = strtok(buff, " "); p && n<2; p = strtok(NULL, " ")) types[n++] = p; if (n <= 0) return NULL; @@ -3013,7 +3025,8 @@ void traceopen(const char *file) reppath(file, path, time, "", ""); if (!*path || !(fp_trace = fopen(path, "w"))) fp_trace = stderr; - strcpy(file_trace, file); + if (strlen(file) < 1025) strcpy(file_trace, file); + else trace(1, "file array is too long"); tick_trace = tickget(); time_trace = time; initlock(&lock_trace); @@ -3224,11 +3237,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'; - mkdir(buff, 0777); + if(mkdir(buff, 0777) != 0) trace(1, "Error creating folder"); } @@ -3246,7 +3260,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; } @@ -3934,7 +3950,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 */ @@ -3947,10 +3964,10 @@ int rtk_uncompress(const char *file, char *uncfile) if (execcmd(cmd)) { - remove(uncfile); + if(remove(uncfile) != 0) trace(1, "Error removing file"); return -1; } - strcpy(tmpfile, uncfile); + if(strlen(uncfile) < 1025) strcpy(tmpfile, uncfile); stat = 1; } /* extract tar file */ @@ -3966,10 +3983,10 @@ int rtk_uncompress(const char *file, char *uncfile) sprintf(cmd, "tar -C \"%s\" -xf \"%s\"", dir, tmpfile); if (execcmd(cmd)) { - if (stat) remove(tmpfile); + if (stat) if(remove(tmpfile) != 0) trace(1, "Error removing file"); return -1; } - if (stat) remove(tmpfile); + if (stat) if(remove(tmpfile) != 0) trace(1, "Error removing file"); stat = 1; } /* extract hatanaka-compressed file by cnx2rnx */ @@ -3982,11 +3999,11 @@ int rtk_uncompress(const char *file, char *uncfile) if (execcmd(cmd)) { - remove(uncfile); - if (stat) remove(tmpfile); + if(remove(uncfile) != 0) trace(1, "Error removing file"); + if (stat) if(remove(tmpfile) != 0) trace(1, "Error removing file"); return -1; } - if (stat) remove(tmpfile); + if (stat) if(remove(tmpfile) != 0) trace(1, "Error removing file"); stat = 1; } trace(3, "rtk_uncompress: stat=%d\n", stat); @@ -4005,7 +4022,7 @@ int rtk_uncompress(const char *file, char *uncfile) int expath(const char *path, char *paths[], int nmax) { int i, j, n = 0; - char tmp[1024]; + char tmp[1024] = ""; struct dirent *d; DIR *dp; const char *file = path; @@ -4040,7 +4057,11 @@ int expath(const char *path, char *paths[], int nmax) { if (strcmp(paths[i], paths[j])>0) { - strcpy(tmp, paths[i]); + if(strlen(paths[i]) < 1025) strcpy(tmp, paths[i]); + else + { + trace(1, "Path is too long"); + } strcpy(paths[i], paths[j]); strcpy(paths[j], tmp); } diff --git a/src/algorithms/libs/rtklib/rtklib_rtkpos.cc b/src/algorithms/libs/rtklib/rtklib_rtkpos.cc index 437b75e1f..2ced73641 100644 --- a/src/algorithms/libs/rtklib/rtklib_rtkpos.cc +++ b/src/algorithms/libs/rtklib/rtklib_rtkpos.cc @@ -156,7 +156,8 @@ int rtkopenstat(const char *file, int level) trace(1, "rtkopenstat: file open error path=%s\n", path); return 0; } - strcpy(file_stat, file); + if(strlen(file) < 1025) strcpy(file_stat, file); + else trace(1, "File name is too long"); time_stat = time; statlevel = level; return 1; diff --git a/src/algorithms/libs/rtklib/rtklib_rtksvr.cc b/src/algorithms/libs/rtklib/rtklib_rtksvr.cc index c8ba20466..0c2aabedf 100644 --- a/src/algorithms/libs/rtklib/rtklib_rtksvr.cc +++ b/src/algorithms/libs/rtklib/rtklib_rtksvr.cc @@ -752,8 +752,8 @@ int rtksvrstart(rtksvr_t *svr, int cycle, int buffsize, int *strs, init_rtcm(svr->rtcm+i); /* set receiver and rtcm option */ - strcpy(svr->raw [i].opt, rcvopts[i]); - strcpy(svr->rtcm[i].opt, rcvopts[i]); + if(strlen(rcvopts[i]) < 256 ) strcpy(svr->raw [i].opt, rcvopts[i]); + if(strlen(rcvopts[i]) < 256 ) strcpy(svr->rtcm[i].opt, rcvopts[i]); /* connect dgps corrections */ svr->rtcm[i].dgps = svr->nav.dgps; diff --git a/src/algorithms/libs/rtklib/rtklib_sbas.cc b/src/algorithms/libs/rtklib/rtklib_sbas.cc index ad081128f..577199268 100644 --- a/src/algorithms/libs/rtklib/rtklib_sbas.cc +++ b/src/algorithms/libs/rtklib/rtklib_sbas.cc @@ -185,9 +185,9 @@ int decode_sbstype6(const sbsmsg_t *msg, sbssat_t *sbssat) { iodf[i] = getbitu(msg->msg, 14+i*2, 2); } - for (i = 0;insat && insat && i < MAXSAT; i++) { - if (sbssat->sat[i].fcorr.iodf != iodf[i/13]) continue; + if (sbssat->sat[i].fcorr.iodf != iodf[i/22]) continue; udre = getbitu(msg->msg, 22+i*4, 4); sbssat->sat[i].fcorr.udre = udre+1; } @@ -536,7 +536,7 @@ void readmsgs(const char *file, int sel, gtime_t ts, gtime_t te, if (!(sbs_msgs = (sbsmsg_t *)realloc(sbs->msgs, sbs->nmax * sizeof(sbsmsg_t)))) { trace(1, "readsbsmsg malloc error: nmax=%d\n", sbs->nmax); - free(sbs->msgs); sbs->msgs = NULL; sbs->n = sbs->nmax = 0; + free(sbs->msgs); sbs->msgs = NULL; sbs->n = sbs->nmax = 0; fclose(fp); return; } sbs->msgs = sbs_msgs; 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); diff --git a/src/algorithms/libs/rtklib/rtklib_stream.cc b/src/algorithms/libs/rtklib/rtklib_stream.cc index 5decd4bcb..53d2bb8f4 100644 --- a/src/algorithms/libs/rtklib/rtklib_stream.cc +++ b/src/algorithms/libs/rtklib/rtklib_stream.cc @@ -104,10 +104,10 @@ serial_t *openserial(const char *path, int mode, char *msg) strncpy(port, path, p-path); port[p-path] = '\0'; sscanf(p, ":%d:%d:%c:%d:%s", &brate, &bsize, &parity, &stopb, fctr); } - else strcpy(port, path); + else if(strlen(path) < 128) strcpy(port, path); - for (i = 0;i < 11;i++) if (br[i] == brate) break; - if (i >= 12) + for (i = 0;i < 10; i++) if (br[i] == brate) break; + if (i >= 11) { sprintf(msg, "bitrate error (%d)", brate); tracet(1, "openserial: %s path=%s\n", msg, path); @@ -150,8 +150,8 @@ serial_t *openserial(const char *path, int mode, char *msg) /* close serial --------------------------------------------------------------*/ void closeserial(serial_t *serial) { - tracet(3, "closeserial: dev=%d\n", serial->dev); if (!serial) return; + tracet(3, "closeserial: dev=%d\n", serial->dev); close(serial->dev); free(serial); } @@ -161,8 +161,8 @@ void closeserial(serial_t *serial) int readserial(serial_t *serial, unsigned char *buff, int n, char *msg __attribute__((unused))) { int nr; - tracet(4, "readserial: dev=%d n=%d\n", serial->dev, n); if (!serial) return 0; + tracet(4, "readserial: dev=%d n=%d\n", serial->dev, n); if ((nr = read(serial->dev, buff, n)) < 0) return 0; tracet(5, "readserial: exit dev=%d nr=%d\n", serial->dev, nr); return nr; @@ -173,8 +173,8 @@ int readserial(serial_t *serial, unsigned char *buff, int n, char *msg __attribu int writeserial(serial_t *serial, unsigned char *buff, int n, char *msg __attribute__((unused))) { int ns; - tracet(3, "writeserial: dev=%d n=%d\n", serial->dev, n); if (!serial) return 0; + tracet(3, "writeserial: dev=%d n=%d\n", serial->dev, n); if ((ns = write(serial->dev, buff, n)) < 0) return 0; tracet(5, "writeserial: exit dev=%d ns=%d\n", serial->dev, ns); return ns; @@ -269,7 +269,7 @@ int openfile_(file_t *file, gtime_t time, char *msg) if ((fp = fopen(tagpath, "rb"))) { fclose(fp); - remove(tagpath); + if (remove(tagpath) != 0) trace(1, "Error removing file"); } } return 1; @@ -315,7 +315,7 @@ file_t *openfile(const char *path, int mode, char *msg) if (!(file = (file_t *)malloc(sizeof(file_t)))) return NULL; file->fp = file->fp_tag = file->fp_tmp = file->fp_tag_tmp = NULL; - strcpy(file->path, path); + if(strlen(path) < MAXSTRPATH) strcpy(file->path, path); if ((p = strstr(file->path, "::"))) *p = '\0'; file->openpath[0] = '\0'; file->mode = mode; @@ -344,8 +344,8 @@ file_t *openfile(const char *path, int mode, char *msg) /* close file ----------------------------------------------------------------*/ void closefile(file_t *file) { - tracet(3, "closefile: fp=%d\n", file->fp); if (!file) return; + tracet(3, "closefile: fp=%d\n", file->fp); closefile_(file); free(file); } @@ -404,9 +404,8 @@ int readfile(file_t *file, unsigned char *buff, int nmax, char *msg) int nr = 0; size_t fpos; - tracet(4, "readfile: fp=%d nmax=%d\n", file->fp, nmax); - if (!file) return 0; + tracet(4, "readfile: fp=%d nmax=%d\n", file->fp, nmax); if (file->fp == stdin) { @@ -431,7 +430,7 @@ int readfile(file_t *file, unsigned char *buff, int nmax, char *msg) if (fread(&tick, sizeof(tick), 1, file->fp_tag) < 1 || fread(&fpos, sizeof(fpos), 1, file->fp_tag) < 1) { - fseek(file->fp, 0, SEEK_END); + if(fseek(file->fp, 0, SEEK_END) != 0) trace(1, "fseek error"); sprintf(msg, "end"); break; } @@ -445,7 +444,7 @@ int readfile(file_t *file, unsigned char *buff, int nmax, char *msg) if ((int)(fpos-file->fpos) >= nmax) { - fseek(file->fp, fpos, SEEK_SET); + if(fseek(file->fp, fpos, SEEK_SET) != 0) trace(1, "Error fseek"); file->fpos = fpos; return 0; } @@ -453,7 +452,7 @@ int readfile(file_t *file, unsigned char *buff, int nmax, char *msg) if (file->repmode || file->speed>0.0) { - fseek(file->fp_tag, -(long)(sizeof(tick)+sizeof(fpos)), SEEK_CUR); + if(fseek(file->fp_tag, -(long)(sizeof(tick)+sizeof(fpos)), SEEK_CUR) !=0) trace(1, "Error fseek"); } break; } @@ -478,9 +477,8 @@ int writefile(file_t *file, unsigned char *buff, int n, char *msg) double tow1, tow2, intv; size_t fpos, fpos_tmp; - tracet(3, "writefile: fp=%d n=%d\n", file->fp, n); - if (!file) return 0; + tracet(3, "writefile: fp=%d n=%d\n", file->fp, n); wtime = utc2gpst(timeget()); /* write time in gpst */ @@ -560,7 +558,7 @@ void decodetcppath(const char *path, char *addr, char *port, char *user, if (mntpnt) *mntpnt = '\0'; if (str) *str = '\0'; - strcpy(buff, path); + if(strlen(path) < MAXSTRPATH) strcpy(buff, path); if (!(p = strrchr(buff, '@'))) p = buff; @@ -645,7 +643,7 @@ int connect_nb(socket_t sock, struct sockaddr *addr, socklen_t len) int err, flag; flag = fcntl(sock, F_GETFL, 0); - fcntl(sock, F_SETFL, flag|O_NONBLOCK); + if(fcntl(sock, F_SETFL, flag|O_NONBLOCK) == -1) trace(1, "fcntl error"); if (connect(sock, addr, len) == -1) { err = errsock(); @@ -761,7 +759,7 @@ tcpsvr_t *opentcpsvr(const char *path, char *msg) { tcpsvr_t *tcpsvr, tcpsvr0; // = {{0}}; char port[256] = ""; - + tcpsvr0 = { {0, {0}, 0, {0,0,0,{0}},0,0,0,0}, { 0, {0}, 0,{0,0,0,{0}},0,0,0,0} }; tracet(3, "opentcpsvr: path=%s\n", path); if (!(tcpsvr = (tcpsvr_t *)malloc(sizeof(tcpsvr_t)))) return NULL; @@ -863,7 +861,7 @@ int accsock(tcpsvr_t *tcpsvr, char *msg) tcpsvr->cli[i].sock = sock; if (!setsock(tcpsvr->cli[i].sock, msg)) return 0; memcpy(&tcpsvr->cli[i].addr, &addr, sizeof(addr)); - strcpy(tcpsvr->cli[i].saddr, inet_ntoa(addr.sin_addr)); + if(strlen(inet_ntoa(addr.sin_addr)) < 256) strcpy(tcpsvr->cli[i].saddr, inet_ntoa(addr.sin_addr)); sprintf(msg, "%s", tcpsvr->cli[i].saddr); tracet(2, "accsock: connected sock=%d addr=%s\n", tcpsvr->cli[i].sock, tcpsvr->cli[i].saddr); tcpsvr->cli[i].state = 2; @@ -985,6 +983,7 @@ tcpcli_t *opentcpcli(const char *path, char *msg) { tcpcli_t *tcpcli, tcpcli0; // = {{0}}; char port[256] = ""; + tcpcli0 = {{0, {0}, 0, {0,0,0,{0}},0,0,0,0}, 0, 0}; tracet(3, "opentcpcli: path=%s\n", path); @@ -1425,7 +1424,7 @@ void decodeftppath(const char *path, char *addr, char *file, char *user, topts[2] = 0; /* download time offset (s) */ topts[3] = 0; /* retry interval (s) (0: no retry) */ } - strcpy(buff, path); + if(strlen(path) < MAXSTRPATH) strcpy(buff, path); if ((p = strchr(buff, '/'))) { @@ -1550,13 +1549,13 @@ void *ftpthread(void *arg) /* execute download command */ if ((ret = execcmd(cmd))) { - remove(local); + if(remove(local) != 0) trace(1, "Error removing file"); tracet(1, "execcmd error: cmd=%s ret=%d\n", cmd, ret); ftp->error = ret; ftp->state = 3; return 0; } - remove(errfile); + if(remove(errfile) != 0) trace(1, "Error removing file"); /* uncompress downloaded file */ if ((p = strrchr(local, '.')) && @@ -1565,8 +1564,8 @@ void *ftpthread(void *arg) { if (rtk_uncompress(local, tmpfile)) { - remove(local); - strcpy(local, tmpfile); + if(remove(local) != 0) trace(1, "Error removing file"); + if(strlen(tmpfile) < 1024) strcpy(local, tmpfile); } else { @@ -1576,7 +1575,7 @@ void *ftpthread(void *arg) return 0; } } - strcpy(ftp->local, local); + if(strlen(local) < 1024 ) strcpy(ftp->local, local); ftp->state = 2; /* ftp completed */ tracet(3, "ftpthread: complete cmd=%s\n", cmd); @@ -1754,7 +1753,7 @@ int stropen(stream_t *stream, int type, int mode, const char *path) stream->type = type; stream->mode = mode; - strcpy(stream->path, path); + if(strlen(path) < MAXSTRPATH ) strcpy(stream->path, path); stream->inb = stream->inr = stream->outb = stream->outr = 0; stream->tick = tickget(); stream->inbt = stream->outbt = 0; @@ -2060,7 +2059,7 @@ void strsettimeout(stream_t *stream, int toinact, int tirecon) void strsetdir(const char *dir) { tracet(3, "strsetdir: dir=%s\n", dir); - strcpy(localdir, dir); + if (strlen(dir) < 1024) strcpy(localdir, dir); } @@ -2072,7 +2071,7 @@ void strsetdir(const char *dir) void strsetproxy(const char *addr) { tracet(3, "strsetproxy: addr=%s\n", addr); - strcpy(proxyaddr, addr); + if(strlen(addr) < 256) strcpy(proxyaddr, addr); } diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/gen/volk_gnsssdr_kernel_defs.py b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/gen/volk_gnsssdr_kernel_defs.py index 90ba0693c..3eb77d26f 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/gen/volk_gnsssdr_kernel_defs.py +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/gen/volk_gnsssdr_kernel_defs.py @@ -204,7 +204,7 @@ class kernel_class: ######################################################################## __file__ = os.path.abspath(__file__) srcdir = os.path.dirname(os.path.dirname(__file__)) -kernel_files = glob.glob(os.path.join(srcdir, "kernels", "volk_gnsssdr", "*.h")) +kernel_files = sorted(glob.glob(os.path.join(srcdir, "kernels", "volk_gnsssdr", "*.h"))) kernels = list(map(kernel_class, kernel_files)) if __name__ == '__main__': diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/lib/qa_utils.cc b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/lib/qa_utils.cc index c5b3f5262..d947ebd94 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/lib/qa_utils.cc +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/lib/qa_utils.cc @@ -32,14 +32,20 @@ #include #include #include +#include #include #include #include #include -float uniform() { - return 2.0f * ((float) rand() / RAND_MAX - 0.5f); // uniformly (-1, 1) +float uniform() +{ + // Seed with a real random value, if available + std::random_device r; + std::default_random_engine e1(r()); + std::uniform_real_distribution<> uniform_dist(-1, 1); + return static_cast(uniform_dist(e1)); } template @@ -51,6 +57,9 @@ void random_floats (t *buf, unsigned n) void load_random_data(void *data, volk_gnsssdr_type_t type, unsigned int n) { + std::random_device r; + std::default_random_engine e1(r()); + std::uniform_real_distribution uniform_dist(-1, 1); if(type.is_complex) n *= 2; if(type.is_float) { @@ -63,7 +72,7 @@ void load_random_data(void *data, volk_gnsssdr_type_t type, unsigned int n) if(type.is_signed) int_max /= 2.0; for(unsigned int i = 0; i < n; i++) { - float scaled_rand = (((float) (rand() - (RAND_MAX/2))) / static_cast((RAND_MAX/2))) * int_max; + float scaled_rand = static_cast(uniform_dist(e1)) * int_max; //man i really don't know how to do this in a more clever way, you have to cast down at some point switch(type.size) { diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/python/volk_gnsssdr_modtool/volk_gnsssdr_modtool_generate.py b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/python/volk_gnsssdr_modtool/volk_gnsssdr_modtool_generate.py index ee32d5192..340933018 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/python/volk_gnsssdr_modtool/volk_gnsssdr_modtool_generate.py +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/python/volk_gnsssdr_modtool/volk_gnsssdr_modtool_generate.py @@ -58,10 +58,10 @@ class volk_gnsssdr_modtool: else: name = self.get_basename(base); if name == '': - hdr_files = glob.glob(os.path.join(base, "kernels/volk_gnsssdr/*.h")); + hdr_files = sorted(glob.glob(os.path.join(base, "kernels/volk_gnsssdr/*.h"))); begins = re.compile("(?<=volk_gnsssdr_).*") else: - hdr_files = glob.glob(os.path.join(base, "kernels/volk_gnsssdr_" + name + "/*.h")); + hdr_files = sorted(glob.glob(os.path.join(base, "kernels/volk_gnsssdr_" + name + "/*.h"))); begins = re.compile("(?<=volk_gnsssdr_" + name + "_).*") datatypes = []; @@ -166,7 +166,7 @@ class volk_gnsssdr_modtool: open(dest, 'w+').write(outstring); # copy orc proto-kernels if they exist - for orcfile in glob.glob(inpath + '/orc/' + top + name + '*.orc'): + for orcfile in sorted(glob.glob(inpath + '/kernels/volk_gnsssdr/asm/orc/' + top + name + '*.orc')): if os.path.isfile(orcfile): instring = open(orcfile, 'r').read(); outstring = re.sub(oldvolk_gnsssdr, 'volk_gnsssdr_' + self.my_dict['name'], instring); @@ -333,8 +333,3 @@ class volk_gnsssdr_modtool: write_okay = False if write_okay: open(dest, 'a').write(otherline); - - - - - diff --git a/src/algorithms/signal_generator/gnuradio_blocks/signal_generator_c.cc b/src/algorithms/signal_generator/gnuradio_blocks/signal_generator_c.cc index 74a1cf9f2..4ce5e8daf 100644 --- a/src/algorithms/signal_generator/gnuradio_blocks/signal_generator_c.cc +++ b/src/algorithms/signal_generator/gnuradio_blocks/signal_generator_c.cc @@ -15,7 +15,7 @@ * GNSS-SDR 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. +* (at your option) any later version. * * GNSS-SDR is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -33,7 +33,6 @@ #include #include #include -//#include #include #include "gps_sdr_signal_processing.h" #include "galileo_e1_signal_processing.h" @@ -131,6 +130,8 @@ void signal_generator_c::init() } } random_ = new gr::random(); + std::default_random_engine e1(r()); + std::uniform_int_distribution uniform_dist(0, RAND_MAX); } @@ -295,7 +296,7 @@ int signal_generator_c::general_work (int noutput_items __attribute__((unused)), if (ms_counter_[sat] == 0 && data_flag_) { // New random data bit - current_data_bits_[sat] = gr_complex((rand() % 2) == 0 ? 1 : -1, 0); + current_data_bits_[sat] = gr_complex((uniform_dist(e1) % 2) == 0 ? 1 : -1, 0); } for (k = delay_samples; k < samples_per_code_[sat]; k++) @@ -330,7 +331,7 @@ int signal_generator_c::general_work (int noutput_items __attribute__((unused)), if (ms_counter_[sat]%data_bit_duration_ms_[sat] == 0 && data_flag_) { // New random data bit - current_data_bit_int_[sat] = (rand()%2) == 0 ? 1 : -1; + current_data_bit_int_[sat] = (uniform_dist(e1)%2) == 0 ? 1 : -1; } data_modulation_[sat] = current_data_bit_int_[sat] * (Galileo_E5a_I_SECONDARY_CODE.at((ms_counter_[sat]+delay_sec_[sat]) % 20) == '0' ? 1 : -1); pilot_modulation_[sat] = (Galileo_E5a_Q_SECONDARY_CODE[PRN_[sat] - 1].at((ms_counter_[sat] + delay_sec_[sat]) % 100) == '0' ? 1 : -1); @@ -362,7 +363,7 @@ int signal_generator_c::general_work (int noutput_items __attribute__((unused)), if (ms_counter_[sat] == 0 && data_flag_) { // New random data bit - current_data_bits_[sat] = gr_complex((rand() % 2) == 0 ? 1 : -1, 0); + current_data_bits_[sat] = gr_complex((uniform_dist(e1) % 2) == 0 ? 1 : -1, 0); } for (k = delay_samples; k < samples_per_code_[sat]; k++) diff --git a/src/algorithms/signal_generator/gnuradio_blocks/signal_generator_c.h b/src/algorithms/signal_generator/gnuradio_blocks/signal_generator_c.h index e35dd0229..3700f8af9 100644 --- a/src/algorithms/signal_generator/gnuradio_blocks/signal_generator_c.h +++ b/src/algorithms/signal_generator/gnuradio_blocks/signal_generator_c.h @@ -33,6 +33,8 @@ #include #include +#include +#include #include #include #include @@ -122,6 +124,9 @@ private: gr_complex* complex_phase_; unsigned int work_counter_; + std::random_device r; + std::default_random_engine e1; + std::uniform_int_distribution uniform_dist; public: ~signal_generator_c(); // public destructor @@ -135,4 +140,3 @@ public: }; #endif /* GNSS_SDR_SIGNAL_GENERATOR_C_H */ - diff --git a/src/algorithms/signal_source/adapters/uhd_signal_source.cc b/src/algorithms/signal_source/adapters/uhd_signal_source.cc index 4728543d3..1c59b7113 100644 --- a/src/algorithms/signal_source/adapters/uhd_signal_source.cc +++ b/src/algorithms/signal_source/adapters/uhd_signal_source.cc @@ -62,7 +62,12 @@ UhdSignalSource::UhdSignalSource(ConfigurationInterface* configuration, { dev_addr["addr"] = device_address_; } - + //filter the device by serial number if required (useful for USB devices) + std::string device_serial = configuration->property(role + ".device_serial", empty); + if (empty.compare(device_serial) != 0) // if not empty + { + dev_addr["serial"] = device_serial; + } subdevice_ = configuration->property(role + ".subdevice", empty); clock_source_ = configuration->property(role + ".clock_source", std::string("internal")); RF_channels_ = configuration->property(role + ".RF_channels", 1); diff --git a/src/algorithms/telemetry_decoder/gnuradio_blocks/gps_l1_ca_telemetry_decoder_cc.cc b/src/algorithms/telemetry_decoder/gnuradio_blocks/gps_l1_ca_telemetry_decoder_cc.cc index ddb39d229..10d3289a2 100644 --- a/src/algorithms/telemetry_decoder/gnuradio_blocks/gps_l1_ca_telemetry_decoder_cc.cc +++ b/src/algorithms/telemetry_decoder/gnuradio_blocks/gps_l1_ca_telemetry_decoder_cc.cc @@ -103,7 +103,7 @@ gps_l1_ca_telemetry_decoder_cc::gps_l1_ca_telemetry_decoder_cc( d_decimation_output_factor = 1; d_channel = 0; flag_PLL_180_deg_phase_locked = false; - + d_preamble_time_samples = 0; } diff --git a/src/algorithms/telemetry_decoder/gnuradio_blocks/sbas_l1_telemetry_decoder_cc.cc b/src/algorithms/telemetry_decoder/gnuradio_blocks/sbas_l1_telemetry_decoder_cc.cc index d90135bb6..e12dac1f4 100644 --- a/src/algorithms/telemetry_decoder/gnuradio_blocks/sbas_l1_telemetry_decoder_cc.cc +++ b/src/algorithms/telemetry_decoder/gnuradio_blocks/sbas_l1_telemetry_decoder_cc.cc @@ -98,7 +98,7 @@ int sbas_l1_telemetry_decoder_cc::general_work (int noutput_items __attribute__( d_sample_buf.push_back(current_symbol.Prompt_I); //add new symbol to the symbol queue // store the time stamp of the first sample in the processed sample block - double sample_stamp = in[0].Tracking_sample_counter/in[0].fs; + double sample_stamp = static_cast(in[0].Tracking_sample_counter) / static_cast(in[0].fs); // decode only if enough samples in buffer if(d_sample_buf.size() >= d_block_size) @@ -498,4 +498,3 @@ void sbas_l1_telemetry_decoder_cc::crc_verifier::zerropad_front_and_convert_to_b << std::setfill('0') << std::hex << (unsigned int)byte << std::setfill(' ') << std::resetiosflags(std::ios::hex); } - diff --git a/src/core/system_parameters/gps_cnav_navigation_message.cc b/src/core/system_parameters/gps_cnav_navigation_message.cc index 5b3652387..cf49bba50 100644 --- a/src/core/system_parameters/gps_cnav_navigation_message.cc +++ b/src/core/system_parameters/gps_cnav_navigation_message.cc @@ -68,6 +68,7 @@ Gps_CNAV_Navigation_Message::Gps_CNAV_Navigation_Message() satelliteBlock[prn_] = gnss_satellite_.what_block("GPS", prn_); } b_flag_iono_valid = false; + b_flag_utc_valid = false; } diff --git a/src/tests/single_test_main.cc b/src/tests/single_test_main.cc index f9f91573b..9877e61f2 100644 --- a/src/tests/single_test_main.cc +++ b/src/tests/single_test_main.cc @@ -64,7 +64,11 @@ DECLARE_string(log_dir); int main(int argc, char **argv) { google::ParseCommandLineFlags(&argc, &argv, true); - testing::InitGoogleTest(&argc, argv); + try + { + testing::InitGoogleTest(&argc, argv); + } + catch(...) {} // catch the "testing::internal::::ClassUniqueToAlwaysTrue" from gtest google::InitGoogleLogging(argv[0]); int res = 0; try diff --git a/src/tests/system-tests/ttff_gps_l1.cc b/src/tests/system-tests/ttff_gps_l1.cc index 2d2155e4a..37a21d9d2 100644 --- a/src/tests/system-tests/ttff_gps_l1.cc +++ b/src/tests/system-tests/ttff_gps_l1.cc @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -515,9 +516,10 @@ TEST_F(TTFF_GPS_L1_CA_Test, ColdStart) std::cout << "Just finished measurement " << num_measurements << ", which took " << ttff << " seconds." << std::endl; if(n < FLAGS_num_measurements - 1) { - std::srand(std::time(0)); // use current time as seed for random generator - int random_variable = std::rand(); - float random_variable_0_1 = static_cast(random_variable) / static_cast( RAND_MAX ); + std::random_device r; + std::default_random_engine e1(r()); + std::uniform_real_distribution uniform_dist(0, 1); + float random_variable_0_1 = uniform_dist(e1); int random_delay_s = static_cast(random_variable_0_1 * 25.0); std::cout << "Waiting a random amount of time (from 5 to 30 s) to start a new measurement... " << std::endl; std::cout << "This time will wait " << random_delay_s + 5 << " s." << std::endl << std::endl; @@ -599,9 +601,10 @@ TEST_F(TTFF_GPS_L1_CA_Test, HotStart) std::cout << "Just finished measurement " << num_measurements << ", which took " << ttff << " seconds." << std::endl; if(n < FLAGS_num_measurements - 1) { - std::srand(std::time(0)); // use current time as seed for random generator - int random_variable = std::rand(); - float random_variable_0_1 = static_cast(random_variable) / static_cast( RAND_MAX ); + std::random_device r; + std::default_random_engine e1(r()); + std::uniform_real_distribution uniform_dist(0, 1); + float random_variable_0_1 = uniform_dist(e1); int random_delay_s = static_cast(random_variable_0_1 * 25.0); std::cout << "Waiting a random amount of time (from 5 to 30 s) to start new measurement... " << std::endl; std::cout << "This time will wait " << random_delay_s + 5 << " s." << std::endl << std::endl; diff --git a/src/tests/test_main.cc b/src/tests/test_main.cc index dec6bf9f0..b78051a69 100644 --- a/src/tests/test_main.cc +++ b/src/tests/test_main.cc @@ -16,7 +16,7 @@ * GNSS-SDR 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. +* (at your option) any later version. * * GNSS-SDR is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of diff --git a/src/tests/unit-tests/signal-processing-blocks/tracking/cpu_multicorrelator_test.cc b/src/tests/unit-tests/signal-processing-blocks/tracking/cpu_multicorrelator_test.cc index e567953c5..5e65cf0db 100644 --- a/src/tests/unit-tests/signal-processing-blocks/tracking/cpu_multicorrelator_test.cc +++ b/src/tests/unit-tests/signal-processing-blocks/tracking/cpu_multicorrelator_test.cc @@ -31,6 +31,7 @@ #include #include +#include #include #include #include "cpu_multicorrelator.h" @@ -100,9 +101,12 @@ TEST(CPU_multicorrelator_test, MeasureExecutionTime) // generate local reference (1 sample per chip) gps_l1_ca_code_gen_complex(d_ca_code, 1, 0); // generate inut signal + std::random_device r; + std::default_random_engine e1(r()); + std::uniform_real_distribution uniform_dist(0, 1); for (int n=0;n<2*d_vector_length;n++) { - in_cpu[n]=std::complex(static_cast (rand())/static_cast(RAND_MAX),static_cast (rand())/static_cast(RAND_MAX)); + in_cpu[n]=std::complex(uniform_dist(e1), uniform_dist(e1)); } for (int n=0;n #include #include #include @@ -372,8 +373,15 @@ int main(int argc, char** argv) gr::block_sptr source; source = gr::blocks::file_source::make(sizeof(gr_complex), "tmp_capture.dat"); - - boost::shared_ptr msg_rx = FrontEndCal_msg_rx_make(); + boost::shared_ptr msg_rx; + try + { + msg_rx = FrontEndCal_msg_rx_make(); + } + catch(const std::exception & e) + { + std::cout << "Failure connecting the message port system: " << e.what() << std::endl; exit(0); + } //gr_basic_block_sptr head = gr_make_head(sizeof(gr_complex), nsamples); //gr_head_sptr head_sptr = boost::dynamic_pointer_cast(head);