From 4f36210536a16dd89870c3e26a598c11dfd06efb Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Fri, 1 Dec 2023 10:20:52 +0100 Subject: [PATCH] Fix warnings --- src/algorithms/libs/rtklib/rtklib_rtkcmn.cc | 19 ++++++++++--------- src/algorithms/libs/rtklib/rtklib_stream.cc | 14 +++++++------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/algorithms/libs/rtklib/rtklib_rtkcmn.cc b/src/algorithms/libs/rtklib/rtklib_rtkcmn.cc index 9d194f7aa..de9bcccb7 100644 --- a/src/algorithms/libs/rtklib/rtklib_rtkcmn.cc +++ b/src/algorithms/libs/rtklib/rtklib_rtkcmn.cc @@ -2983,7 +2983,7 @@ pcv_t *searchpcv(int sat, const char *type, gtime_t time, const pcvs_t *pcvs) { pcv_t *pcv; - char buff[MAXANT] = ""; + char buff[MAXANT + 1] = ""; char *types[2]; char *p; int i; @@ -3730,12 +3730,12 @@ int savenav(const char *file, const nav_t *nav) } auto id = satno2id(nav->eph[i].sat); fprintf(fp, - "%s,%d,%d,%d,%d,%d,%d,%d,%.14E,%.14E,%.14E,%.14E,%.14E,%.14E," + "%s,%d,%d,%d,%d,%lld,%lld,%lld,%.14E,%.14E,%.14E,%.14E,%.14E,%.14E," "%.14E,%.14E,%.14E,%.14E,%.14E,%.14E,%.14E,%.14E,%.14E,%.14E," "%.14E,%.14E,%.14E,%.14E,%.14E,%d,%d\n", id.data(), nav->eph[i].iode, nav->eph[i].iodc, nav->eph[i].sva, - nav->eph[i].svh, static_cast(nav->eph[i].toe.time), - static_cast(nav->eph[i].toc.time), static_cast(nav->eph[i].ttr.time), + nav->eph[i].svh, static_cast(nav->eph[i].toe.time), + static_cast(nav->eph[i].toc.time), static_cast(nav->eph[i].ttr.time), nav->eph[i].A, nav->eph[i].e, nav->eph[i].i0, nav->eph[i].OMG0, nav->eph[i].omg, nav->eph[i].M0, nav->eph[i].deln, nav->eph[i].OMGd, nav->eph[i].idot, nav->eph[i].crc, nav->eph[i].crs, nav->eph[i].cuc, @@ -3751,11 +3751,11 @@ int savenav(const char *file, const nav_t *nav) } auto id = satno2id(nav->geph[i].sat); fprintf(fp, - "%s,%d,%d,%d,%d,%d,%d,%d,%.14E,%.14E,%.14E,%.14E,%.14E,%.14E," + "%s,%d,%d,%d,%d,%d,%lld,%lld,%.14E,%.14E,%.14E,%.14E,%.14E,%.14E," "%.14E,%.14E,%.14E,%.14E,%.14E,%.14E\n", id.data(), nav->geph[i].iode, nav->geph[i].frq, nav->geph[i].svh, - nav->geph[i].sva, nav->geph[i].age, static_cast(nav->geph[i].toe.time), - static_cast(nav->geph[i].tof.time), + nav->geph[i].sva, nav->geph[i].age, static_cast(nav->geph[i].toe.time), + static_cast(nav->geph[i].tof.time), nav->geph[i].pos[0], nav->geph[i].pos[1], nav->geph[i].pos[2], nav->geph[i].vel[0], nav->geph[i].vel[1], nav->geph[i].vel[2], nav->geph[i].acc[0], nav->geph[i].acc[1], nav->geph[i].acc[2], @@ -5016,7 +5016,7 @@ int rtk_uncompress(const char *file, char *uncfile) int stat = 0; char *p; char cmd[2048] = ""; - char tmpfile[1024] = ""; + char tmpfile[1025] = ""; char buff[1024]; char *fname; char *dir = const_cast(""); @@ -5157,7 +5157,7 @@ int expath(const char *path, char *paths[], int nmax) int i; int j; int n = 0; - char tmp[1024] = ""; + char tmp[1025] = ""; struct dirent *d; DIR *dp; const char *file = path; @@ -5230,6 +5230,7 @@ int expath(const char *path, char *paths[], int nmax) } std::strncpy(paths[i], paths[j], 1024); std::strncpy(paths[j], tmp, 1024); + paths[j][1023] = '\0'; } } } diff --git a/src/algorithms/libs/rtklib/rtklib_stream.cc b/src/algorithms/libs/rtklib/rtklib_stream.cc index e9a29cf3f..3cb647ad6 100644 --- a/src/algorithms/libs/rtklib/rtklib_stream.cc +++ b/src/algorithms/libs/rtklib/rtklib_stream.cc @@ -81,7 +81,8 @@ serial_t *openserial(const char *path, int mode, char *msg) char *p; char parity = 'N'; char dev[128]; - char port[128]; + char port[128] = ""; + port[127] = '\0'; char fctr[64] = ""; const speed_t bs[] = { @@ -105,7 +106,7 @@ serial_t *openserial(const char *path, int mode, char *msg) } else if (strlen(path) < 128) { - std::strncpy(port, path, 128); + std::strncpy(port, path, 127); port[127] = '\0'; } @@ -124,7 +125,6 @@ serial_t *openserial(const char *path, int mode, char *msg) return nullptr; } parity = static_cast(toupper(static_cast(parity))); - std::string s_aux = "/dev/"s + std::string(port); s_aux.resize(128, '\0'); int n = s_aux.length(); @@ -705,7 +705,7 @@ void syncfile(file_t *file1, file_t *file2) void decodetcppath(const char *path, char *addr, char *port, char *user, char *passwd, char *mntpnt, char *str) { - char buff[MAXSTRPATH] = ""; + char buff[MAXSTRPATH + 1] = ""; char *p; char *q; @@ -1827,7 +1827,7 @@ int statentrip(ntrip_t *ntrip) void decodeftppath(const char *path, char *addr, char *file, char *user, char *passwd, int *topts) { - char buff[MAXSTRPATH] = ""; + char buff[MAXSTRPATH + 1] = ""; char *p; char *q; @@ -1896,7 +1896,7 @@ void decodeftppath(const char *path, char *addr, char *file, char *user, p = buff; } - std::strncpy(addr, p, 1024); + std::strncpy(addr, p, 1023); addr[1023] = '\0'; } @@ -2254,7 +2254,7 @@ int stropen(stream_t *stream, int type, int mode, const char *path) stream->mode = mode; if (strlen(path) < MAXSTRPATH) { - std::strncpy(stream->path, path, MAXSTRPATH); + std::strncpy(stream->path, path, MAXSTRPATH - 1); stream->path[MAXSTRPATH - 1] = '\0'; } stream->inb = stream->inr = stream->outb = stream->outr = 0;