diff --git a/src/algorithms/libs/rtklib/rtklib_solution.cc b/src/algorithms/libs/rtklib/rtklib_solution.cc index 9502a4f74..f2fc6c702 100644 --- a/src/algorithms/libs/rtklib/rtklib_solution.cc +++ b/src/algorithms/libs/rtklib/rtklib_solution.cc @@ -1468,6 +1468,8 @@ int outpos(unsigned char *buff, const char *s, const sol_t *sol, double Q[9]; const char *sep = opt2sep(opt); char *p = reinterpret_cast(buff); + char *start; + start = p; trace(3, "outpos :\n"); @@ -1482,15 +1484,15 @@ int outpos(unsigned char *buff, const char *s, const sol_t *sol, { deg2dms(pos[0] * R2D, dms1); deg2dms(pos[1] * R2D, dms2); - p += std::snprintf(p, MAXSOLMSG, "%s%s%4.0f%s%02.0f%s%08.5f%s%4.0f%s%02.0f%s%08.5f", s, sep, + p += std::snprintf(p, MAXSOLMSG - (p - start), "%s%s%4.0f%s%02.0f%s%08.5f%s%4.0f%s%02.0f%s%08.5f", s, sep, dms1[0], sep, dms1[1], sep, dms1[2], sep, dms2[0], sep, dms2[1], sep, dms2[2]); } else { - p += std::snprintf(p, MAXSOLMSG, "%s%s%14.9f%s%14.9f", s, sep, pos[0] * R2D, sep, pos[1] * R2D); + p += std::snprintf(p, MAXSOLMSG - (p - start), "%s%s%14.9f%s%14.9f", s, sep, pos[0] * R2D, sep, pos[1] * R2D); } - p += std::snprintf(p, MAXSOLMSG, "%s%10.4f%s%3d%s%3d%s%8.4f%s%8.4f%s%8.4f%s%8.4f%s%8.4f%s%8.4f%s%6.2f%s%6.1f\n", + p += std::snprintf(p, MAXSOLMSG - (p - start), "%s%10.4f%s%3d%s%3d%s%8.4f%s%8.4f%s%8.4f%s%8.4f%s%8.4f%s%8.4f%s%6.2f%s%6.1f\n", sep, pos[2], sep, sol->stat, sep, sol->ns, sep, SQRT_SOL(Q[4]), sep, SQRT_SOL(Q[0]), sep, SQRT_SOL(Q[8]), sep, sqvar(Q[1]), sep, sqvar(Q[2]), sep, sqvar(Q[5]), sep, sol->age, sep, sol->ratio); @@ -1546,17 +1548,18 @@ int outnmea_rmc(unsigned char *buff, const sol_t *sol) char *q; char sum; char *emag = const_cast("E"); + const int MSG_TAIL = 6; trace(3, "outnmea_rmc:\n"); if (sol->stat <= SOLQ_NONE) { - p += std::snprintf(p, MAXSOLBUF, "$GPRMC,,,,,,,,,,,,"); + p += std::snprintf(p, MAXSOLBUF - MSG_TAIL, "$GPRMC,,,,,,,,,,,,"); for (q = reinterpret_cast(buff) + 1, sum = 0; *q; q++) { sum ^= *q; } - p += std::snprintf(p, MAXSOLBUF, "*%02X%c%c", sum, 0x0D, 0x0A); + p += std::snprintf(p, MSG_TAIL, "*%02X%c%c", sum, 0x0D, 0x0A); return p - reinterpret_cast(buff); } time = gpst2utc(sol->time); @@ -1584,7 +1587,7 @@ int outnmea_rmc(unsigned char *buff, const sol_t *sol) } deg2dms(fabs(pos[0]) * R2D, dms1); deg2dms(fabs(pos[1]) * R2D, dms2); - p += std::snprintf(p, MAXSOLBUF, "$GPRMC,%02.0f%02.0f%05.2f,A,%02.0f%010.7f,%s,%03.0f%010.7f,%s,%4.2f,%4.2f,%02.0f%02.0f%02d,%.1f,%s,%s", + p += std::snprintf(p, MAXSOLBUF - MSG_TAIL, "$GPRMC,%02.0f%02.0f%05.2f,A,%02.0f%010.7f,%s,%03.0f%010.7f,%s,%4.2f,%4.2f,%02.0f%02.0f%02d,%.1f,%s,%s", ep[3], ep[4], ep[5], dms1[0], dms1[1] + dms1[2] / 60.0, pos[0] >= 0 ? "N" : "S", dms2[0], dms2[1] + dms2[2] / 60.0, pos[1] >= 0 ? "E" : "W", vel / KNOT2M, dir, ep[2], ep[1], static_cast(ep[0]) % 100, amag, emag, @@ -1593,7 +1596,7 @@ int outnmea_rmc(unsigned char *buff, const sol_t *sol) { sum ^= *q; /* check-sum */ } - p += std::snprintf(p, MAXSOLBUF, "*%02X%c%c", sum, 0x0D, 0x0A); + p += std::snprintf(p, MSG_TAIL, "*%02X%c%c", sum, 0x0D, 0x0A); return p - reinterpret_cast(buff); } @@ -1612,17 +1615,18 @@ int outnmea_gga(unsigned char *buff, const sol_t *sol) char *p = reinterpret_cast(buff); char *q; char sum; + const int MSG_TAIL = 6; trace(3, "outnmea_gga:\n"); if (sol->stat <= SOLQ_NONE) { - p += std::snprintf(p, MAXSOLBUF, "$GPGGA,,,,,,,,,,,,,,"); + p += std::snprintf(p, MAXSOLBUF - MSG_TAIL, "$GPGGA,,,,,,,,,,,,,,"); for (q = reinterpret_cast(buff) + 1, sum = 0; *q; q++) { sum ^= *q; } - p += std::snprintf(p, MAXSOLBUF, "*%02X%c%c", sum, 0x0D, 0x0A); + p += std::snprintf(p, MSG_TAIL, "*%02X%c%c", sum, 0x0D, 0x0A); return p - reinterpret_cast(buff); } for (solq = 0; solq < 8; solq++) @@ -1647,7 +1651,7 @@ int outnmea_gga(unsigned char *buff, const sol_t *sol) h = 0; // geoidh(pos); deg2dms(fabs(pos[0]) * R2D, dms1); deg2dms(fabs(pos[1]) * R2D, dms2); - p += std::snprintf(p, MAXSOLBUF, "$GPGGA,%02.0f%02.0f%05.2f,%02.0f%010.7f,%s,%03.0f%010.7f,%s,%d,%02d,%.1f,%.3f,M,%.3f,M,%.1f,", + p += std::snprintf(p, MAXSOLBUF - MSG_TAIL, "$GPGGA,%02.0f%02.0f%05.2f,%02.0f%010.7f,%s,%03.0f%010.7f,%s,%d,%02d,%.1f,%.3f,M,%.3f,M,%.1f,", ep[3], ep[4], ep[5], dms1[0], dms1[1] + dms1[2] / 60.0, pos[0] >= 0 ? "N" : "S", dms2[0], dms2[1] + dms2[2] / 60.0, pos[1] >= 0 ? "E" : "W", solq, sol->ns, dop, pos[2] - h, h, sol->age); @@ -1655,7 +1659,7 @@ int outnmea_gga(unsigned char *buff, const sol_t *sol) { sum ^= *q; /* check-sum */ } - p += std::snprintf(p, MAXSOLBUF, "*%02X%c%c", sum, 0x0D, 0x0A); + p += std::snprintf(p, MSG_TAIL, "*%02X%c%c", sum, 0x0D, 0x0A); return p - reinterpret_cast(buff); } @@ -1675,17 +1679,20 @@ int outnmea_gsa(unsigned char *buff, const sol_t *sol, char *q; char *s; char sum; + const int MSG_TAIL = 6; + const int COMMA_LENGTH = 2; + const int MAX_LENGTH_INT = 10; trace(3, "outnmea_gsa:\n"); if (sol->stat <= SOLQ_NONE) { - p += std::snprintf(p, MAXSOLBUF, "$GPGSA,A,1,,,,,,,,,,,,,,,"); + p += std::snprintf(p, MAXSOLBUF - MSG_TAIL, "$GPGSA,A,1,,,,,,,,,,,,,,,"); for (q = reinterpret_cast(buff) + 1, sum = 0; *q; q++) { sum ^= *q; } - p += std::snprintf(p, MAXSOLBUF, "*%02X%c%c", sum, 0x0D, 0x0A); + p += std::snprintf(p, MSG_TAIL, "*%02X%c%c", sum, 0x0D, 0x0A); return p - reinterpret_cast(buff); } @@ -1719,20 +1726,20 @@ int outnmea_gsa(unsigned char *buff, const sol_t *sol, { if (i < nsat) { - p += std::snprintf(p, MAXSOLBUF, ",%02d", prn[i]); + p += std::snprintf(p, MAX_LENGTH_INT + 2, ",%02d", prn[i]); } else { - p += std::snprintf(p, MAXSOLBUF, ","); + p += std::snprintf(p, COMMA_LENGTH, ","); } } dops(nsat, azel, 0.0, dop); - p += std::snprintf(p, MAXSOLBUF, ",%3.1f,%3.1f,%3.1f,1", dop[1], dop[2], dop[3]); + p += std::snprintf(p, MAXSOLBUF - (p - s), ",%3.1f,%3.1f,%3.1f,1", dop[1], dop[2], dop[3]); for (q = s + 1, sum = 0; *q; q++) { sum ^= *q; /* check-sum */ } - p += std::snprintf(p, MAXSOLBUF, "*%02X%c%c", sum, 0x0D, 0x0A); + p += std::snprintf(p, MSG_TAIL, "*%02X%c%c", sum, 0x0D, 0x0A); } /* GLGSA: glonass */ for (sat = 1, nsat = 0; sat <= MAXSAT && nsat < 12; sat++) @@ -1754,25 +1761,26 @@ int outnmea_gsa(unsigned char *buff, const sol_t *sol, if (nsat > 0) { s = p; - p += std::snprintf(p, MAXSOLBUF, "$GLGSA,A,%d", sol->stat <= 0 ? 1 : 3); + const int GLGSA_LENGTH = 11; + p += std::snprintf(p, GLGSA_LENGTH, "$GLGSA,A,%d", sol->stat <= 0 ? 1 : 3); for (i = 0; i < 12; i++) { if (i < nsat) { - p += std::snprintf(p, MAXSOLBUF, ",%02d", prn[i] + 64); + p += std::snprintf(p, MAX_LENGTH_INT + 2, ",%02d", prn[i] + 64); } else { - p += std::snprintf(p, MAXSOLBUF, ","); + p += std::snprintf(p, COMMA_LENGTH, ","); } } dops(nsat, azel, 0.0, dop); - p += std::snprintf(p, MAXSOLBUF, ",%3.1f,%3.1f,%3.1f,2", dop[1], dop[2], dop[3]); + p += std::snprintf(p, MAXSOLBUF - (p - s), ",%3.1f,%3.1f,%3.1f,2", dop[1], dop[2], dop[3]); for (q = s + 1, sum = 0; *q; q++) { sum ^= *q; /* check-sum */ } - p += std::snprintf(p, MAXSOLBUF, "*%02X%c%c", sum, 0x0D, 0x0A); + p += std::snprintf(p, MSG_TAIL, "*%02X%c%c", sum, 0x0D, 0x0A); } /* GAGSA: galileo */ for (sat = 1, nsat = 0; sat <= MAXSAT && nsat < 12; sat++) @@ -1799,20 +1807,20 @@ int outnmea_gsa(unsigned char *buff, const sol_t *sol, { if (i < nsat) { - p += std::snprintf(p, MAXSOLBUF, ",%02d", prn[i]); + p += std::snprintf(p, MAX_LENGTH_INT + 2, ",%02d", prn[i]); } else { - p += std::snprintf(p, MAXSOLBUF, ","); + p += std::snprintf(p, COMMA_LENGTH, ","); } } dops(nsat, azel, 0.0, dop); - p += std::snprintf(p, MAXSOLBUF, ",%3.1f,%3.1f,%3.1f,3", dop[1], dop[2], dop[3]); + p += std::snprintf(p, MAXSOLBUF - (p - s), ",%3.1f,%3.1f,%3.1f,3", dop[1], dop[2], dop[3]); for (q = s + 1, sum = 0; *q; q++) { sum ^= *q; /* check-sum */ } - p += std::snprintf(p, MAXSOLBUF, "*%02X%c%c", sum, 0x0D, 0x0A); + p += std::snprintf(p, MSG_TAIL, "*%02X%c%c", sum, 0x0D, 0x0A); } return p - reinterpret_cast(buff); } @@ -1838,6 +1846,7 @@ int outnmea_gsv(unsigned char *buff, const sol_t *sol, char *q; char *s; char sum; + const int MSG_TAIL = 6; trace(3, "outnmea_gsv:\n"); @@ -1848,7 +1857,7 @@ int outnmea_gsv(unsigned char *buff, const sol_t *sol, { sum ^= *q; } - p += std::snprintf(p, MAXSOLBUF, "*%02X%c%c", sum, 0x0D, 0x0A); + p += std::snprintf(p, MSG_TAIL, "*%02X%c%c", sum, 0x0D, 0x0A); return p - reinterpret_cast(buff); } /* GPGSV: gps/sbas */ @@ -1886,19 +1895,19 @@ int outnmea_gsv(unsigned char *buff, const sol_t *sol, } el = ssat[sats[k] - 1].azel[1] * R2D; snr = ssat[sats[k] - 1].snr[0] * 0.25; - p += std::snprintf(p, MAXSOLBUF, ",%02d,%02.0f,%03.0f,%02.0f", prn, el, az, snr); + p += std::snprintf(p, MAXSOLBUF - (s - p), ",%02d,%02.0f,%03.0f,%02.0f", prn, el, az, snr); } else { - p += std::snprintf(p, MAXSOLBUF, ",,,,"); + p += std::snprintf(p, MAXSOLBUF - (s - p), ",,,,"); } } - p += std::snprintf(p, MAXSOLBUF, ",1"); /* L1C/A */ + p += std::snprintf(p, MAXSOLBUF - (s - p), ",1"); /* L1C/A */ for (q = s + 1, sum = 0; *q; q++) { sum ^= *q; /* check-sum */ } - p += std::snprintf(p, MAXSOLBUF, "*%02X%c%c", sum, 0x0D, 0x0A); + p += std::snprintf(p, MSG_TAIL, "*%02X%c%c", sum, 0x0D, 0x0A); } /* GLGSV: glonass */ for (sat = 1, n = 0; sat < MAXSAT && n < 12; sat++) @@ -1932,19 +1941,19 @@ int outnmea_gsv(unsigned char *buff, const sol_t *sol, } el = ssat[sats[k] - 1].azel[1] * R2D; snr = ssat[sats[k] - 1].snr[0] * 0.25; - p += std::snprintf(p, MAXSOLBUF, ",%02d,%02.0f,%03.0f,%02.0f", prn, el, az, snr); + p += std::snprintf(p, MAXSOLBUF - (s - p), ",%02d,%02.0f,%03.0f,%02.0f", prn, el, az, snr); } else { - p += std::snprintf(p, MAXSOLBUF, ",,,,"); + p += std::snprintf(p, MAXSOLBUF - (s - p), ",,,,"); } } - p += std::snprintf(p, MAXSOLBUF, ",1"); /* L1C/A */ + p += std::snprintf(p, MAXSOLBUF - (s - p), ",1"); /* L1C/A */ for (q = s + 1, sum = 0; *q; q++) { sum ^= *q; /* check-sum */ } - p += std::snprintf(p, MAXSOLBUF, "*%02X%c%c", sum, 0x0D, 0x0A); + p += std::snprintf(p, MSG_TAIL, "*%02X%c%c", sum, 0x0D, 0x0A); } /* GAGSV: galileo */ for (sat = 1, n = 0; sat < MAXSAT && n < 12; sat++) @@ -1977,19 +1986,19 @@ int outnmea_gsv(unsigned char *buff, const sol_t *sol, } el = ssat[sats[k] - 1].azel[1] * R2D; snr = ssat[sats[k] - 1].snr[0] * 0.25; - p += std::snprintf(p, MAXSOLBUF, ",%02d,%02.0f,%03.0f,%02.0f", prn, el, az, snr); + p += std::snprintf(p, MAXSOLBUF - (s - p), ",%02d,%02.0f,%03.0f,%02.0f", prn, el, az, snr); } else { - p += std::snprintf(p, MAXSOLBUF, ",,,,"); + p += std::snprintf(p, MAXSOLBUF - (s - p), ",,,,"); } } - p += std::snprintf(p, MAXSOLBUF, ",7"); /* L1BC */ + p += std::snprintf(p, MAXSOLBUF - (s - p), ",7"); /* L1BC */ for (q = s + 1, sum = 0; *q; q++) { sum ^= *q; /* check-sum */ } - p += std::snprintf(p, MAXSOLBUF, "*%02X%c%c", sum, 0x0D, 0x0A); + p += std::snprintf(p, MSG_TAIL, "*%02X%c%c", sum, 0x0D, 0x0A); } return p - reinterpret_cast(buff); } @@ -2019,6 +2028,8 @@ int outprcopts(unsigned char *buff, const prcopt_t *opt) const char *s9[] = {"off", "on", "auto calib", "external calib", ""}; int i; char *p = reinterpret_cast(buff); + char *s; + s = p; trace(3, "outprcopts:\n"); @@ -2026,51 +2037,51 @@ int outprcopts(unsigned char *buff, const prcopt_t *opt) if (PMODE_DGPS <= opt->mode && opt->mode <= PMODE_FIXED) { - p += std::snprintf(p, MAXSOLMSG, "%s freqs : %s\n", COMMENTH, s2[opt->nf - 1]); + p += std::snprintf(p, MAXSOLMSG - (p - s), "%s freqs : %s\n", COMMENTH, s2[opt->nf - 1]); } if (opt->mode > PMODE_SINGLE) { - p += std::snprintf(p, MAXSOLMSG, "%s solution : %s\n", COMMENTH, s3[opt->soltype]); + p += std::snprintf(p, MAXSOLMSG - (p - s), "%s solution : %s\n", COMMENTH, s3[opt->soltype]); } - p += std::snprintf(p, MAXSOLMSG, "%s elev mask : %.1f deg\n", COMMENTH, opt->elmin * R2D); + p += std::snprintf(p, MAXSOLMSG - (p - s), "%s elev mask : %.1f deg\n", COMMENTH, opt->elmin * R2D); if (opt->mode > PMODE_SINGLE) { - p += std::snprintf(p, MAXSOLMSG, "%s dynamics : %s\n", COMMENTH, opt->dynamics ? "on" : "off"); - p += std::snprintf(p, MAXSOLMSG, "%s tidecorr : %s\n", COMMENTH, opt->tidecorr ? "on" : "off"); + p += std::snprintf(p, MAXSOLMSG - (p - s), "%s dynamics : %s\n", COMMENTH, opt->dynamics ? "on" : "off"); + p += std::snprintf(p, MAXSOLMSG - (p - s), "%s tidecorr : %s\n", COMMENTH, opt->tidecorr ? "on" : "off"); } if (opt->mode <= PMODE_FIXED) { - p += std::snprintf(p, MAXSOLMSG, "%s ionos opt : %s\n", COMMENTH, s4[opt->ionoopt]); + p += std::snprintf(p, MAXSOLMSG - (p - s), "%s ionos opt : %s\n", COMMENTH, s4[opt->ionoopt]); } - p += std::snprintf(p, MAXSOLMSG, "%s tropo opt : %s\n", COMMENTH, s5[opt->tropopt]); - p += std::snprintf(p, MAXSOLMSG, "%s ephemeris : %s\n", COMMENTH, s6[opt->sateph]); + p += std::snprintf(p, MAXSOLMSG - (p - s), "%s tropo opt : %s\n", COMMENTH, s5[opt->tropopt]); + p += std::snprintf(p, MAXSOLMSG - (p - s), "%s ephemeris : %s\n", COMMENTH, s6[opt->sateph]); if (opt->navsys != SYS_GPS) { - p += std::snprintf(p, MAXSOLMSG, "%s navi sys :", COMMENTH); + p += std::snprintf(p, MAXSOLMSG - (p - s), "%s navi sys :", COMMENTH); for (i = 0; sys[i]; i++) { if (opt->navsys & sys[i]) { - p += std::snprintf(p, MAXSOLMSG, " %s", s7[i]); + p += std::snprintf(p, MAXSOLMSG - (p - s), " %s", s7[i]); } } - p += std::snprintf(p, MAXSOLMSG, "\n"); + p += std::snprintf(p, MAXSOLMSG - (p - s), "\n"); } if (PMODE_KINEMA <= opt->mode && opt->mode <= PMODE_FIXED) { - p += std::snprintf(p, MAXSOLMSG, "%s amb res : %s\n", COMMENTH, s8[opt->modear]); + p += std::snprintf(p, MAXSOLMSG - (p - s), "%s amb res : %s\n", COMMENTH, s8[opt->modear]); if (opt->navsys & SYS_GLO) { - p += std::snprintf(p, MAXSOLMSG, "%s amb glo : %s\n", COMMENTH, s9[opt->glomodear]); + p += std::snprintf(p, MAXSOLMSG - (p - s), "%s amb glo : %s\n", COMMENTH, s9[opt->glomodear]); } if (opt->thresar[0] > 0.0) { - p += std::snprintf(p, MAXSOLMSG, "%s val thres : %.1f\n", COMMENTH, opt->thresar[0]); + p += std::snprintf(p, MAXSOLMSG - (p - s), "%s val thres : %.1f\n", COMMENTH, opt->thresar[0]); } } if (opt->mode == PMODE_MOVEB && opt->baseline[0] > 0.0) { - p += std::snprintf(p, MAXSOLMSG, "%s baseline : %.4f %.4f m\n", COMMENTH, + p += std::snprintf(p, MAXSOLMSG - (p - s), "%s baseline : %.4f %.4f m\n", COMMENTH, opt->baseline[0], opt->baseline[1]); } for (i = 0; i < 2; i++) @@ -2079,7 +2090,7 @@ int outprcopts(unsigned char *buff, const prcopt_t *opt) { continue; } - p += std::snprintf(p, MAXSOLMSG, "%s antenna%d : %-21s (%7.4f %7.4f %7.4f)\n", COMMENTH, + p += std::snprintf(p, MAXSOLMSG - (p - s), "%s antenna%d : %-21s (%7.4f %7.4f %7.4f)\n", COMMENTH, i + 1, opt->anttype[i], opt->antdel[i][0], opt->antdel[i][1], opt->antdel[i][2]); } @@ -2101,6 +2112,8 @@ int outsolheads(unsigned char *buff, const solopt_t *opt) const char *sep = opt2sep(opt); char *p = reinterpret_cast(buff); int timeu = opt->timeu < 0 ? 0 : (opt->timeu > 20 ? 20 : opt->timeu); + char *s; + s = p; trace(3, "outsolheads:\n"); @@ -2114,32 +2127,32 @@ int outsolheads(unsigned char *buff, const solopt_t *opt) p += std::snprintf(p, MAXSOLMSG, "%s (", COMMENTH); if (opt->posf == SOLF_XYZ) { - p += std::snprintf(p, MAXSOLMSG, "x/y/z-ecef=WGS84"); + p += std::snprintf(p, MAXSOLMSG - (p - s), "x/y/z-ecef=WGS84"); } else if (opt->posf == SOLF_ENU) { - p += std::snprintf(p, MAXSOLMSG, "e/n/u-baseline=WGS84"); + p += std::snprintf(p, MAXSOLMSG - (p - s), "e/n/u-baseline=WGS84"); } else { - p += std::snprintf(p, MAXSOLMSG, "lat/lon/height=%s/%s", s1[opt->datum], s2[opt->height]); + p += std::snprintf(p, MAXSOLMSG - (p - s), "lat/lon/height=%s/%s", s1[opt->datum], s2[opt->height]); } - p += std::snprintf(p, MAXSOLMSG, ",Q=1:fix,2:float,3:sbas,4:dgps,5:single,6:ppp,ns=# of satellites)\n"); + p += std::snprintf(p, MAXSOLMSG - (p - s), ",Q=1:fix,2:float,3:sbas,4:dgps,5:single,6:ppp,ns=# of satellites)\n"); } - p += std::snprintf(p, MAXSOLMSG, "%s %-*s%s", COMMENTH, (opt->timef ? 16 : 8) + timeu + 1, s3[opt->times], sep); + p += std::snprintf(p, MAXSOLMSG - (p - s), "%s %-*s%s", COMMENTH, (opt->timef ? 16 : 8) + timeu + 1, s3[opt->times], sep); if (opt->posf == SOLF_LLH) { /* lat/lon/hgt */ if (opt->degf) { - p += std::snprintf(p, MAXSOLMSG, "%16s%s%16s%s%10s%s%3s%s%3s%s%8s%s%8s%s%8s%s%8s%s%8s%s%8s%s%6s%s%6s\n", + p += std::snprintf(p, MAXSOLMSG - (p - s), "%16s%s%16s%s%10s%s%3s%s%3s%s%8s%s%8s%s%8s%s%8s%s%8s%s%8s%s%6s%s%6s\n", "latitude(d'\")", sep, "longitude(d'\")", sep, "height(m)", sep, "Q", sep, "ns", sep, "sdn(m)", sep, "sde(m)", sep, "sdu(m)", sep, "sdne(m)", sep, "sdeu(m)", sep, "sdue(m)", sep, "age(s)", sep, "ratio"); } else { - p += std::snprintf(p, MAXSOLMSG, "%14s%s%14s%s%10s%s%3s%s%3s%s%8s%s%8s%s%8s%s%8s%s%8s%s%8s%s%6s%s%6s\n", + p += std::snprintf(p, MAXSOLMSG - (p - s), "%14s%s%14s%s%10s%s%3s%s%3s%s%8s%s%8s%s%8s%s%8s%s%8s%s%8s%s%6s%s%6s\n", "latitude(deg)", sep, "longitude(deg)", sep, "height(m)", sep, "Q", sep, "ns", sep, "sdn(m)", sep, "sde(m)", sep, "sdu(m)", sep, "sdne(m)", sep, "sdeu(m)", sep, "sdun(m)", sep, "age(s)", sep, "ratio"); @@ -2147,14 +2160,14 @@ int outsolheads(unsigned char *buff, const solopt_t *opt) } else if (opt->posf == SOLF_XYZ) { /* x/y/z-ecef */ - p += std::snprintf(p, MAXSOLMSG, "%14s%s%14s%s%14s%s%3s%s%3s%s%8s%s%8s%s%8s%s%8s%s%8s%s%8s%s%6s%s%6s\n", + p += std::snprintf(p, MAXSOLMSG - (p - s), "%14s%s%14s%s%14s%s%3s%s%3s%s%8s%s%8s%s%8s%s%8s%s%8s%s%8s%s%6s%s%6s\n", "x-ecef(m)", sep, "y-ecef(m)", sep, "z-ecef(m)", sep, "Q", sep, "ns", sep, "sdx(m)", sep, "sdy(m)", sep, "sdz(m)", sep, "sdxy(m)", sep, "sdyz(m)", sep, "sdzx(m)", sep, "age(s)", sep, "ratio"); } else if (opt->posf == SOLF_ENU) { /* e/n/u-baseline */ - p += std::snprintf(p, MAXSOLMSG, "%14s%s%14s%s%14s%s%3s%s%3s%s%8s%s%8s%s%8s%s%8s%s%8s%s%8s%s%6s%s%6s\n", + p += std::snprintf(p, MAXSOLMSG - (p - s), "%14s%s%14s%s%14s%s%3s%s%3s%s%8s%s%8s%s%8s%s%8s%s%8s%s%8s%s%6s%s%6s\n", "e-baseline(m)", sep, "n-baseline(m)", sep, "u-baseline(m)", sep, "Q", sep, "ns", sep, "sde(m)", sep, "sdn(m)", sep, "sdu(m)", sep, "sden(m)", sep, "sdnu(m)", sep, "sdue(m)", sep, "age(s)", sep, "ratio"); diff --git a/src/algorithms/libs/rtklib/rtklib_stream.cc b/src/algorithms/libs/rtklib/rtklib_stream.cc index 3bf654db6..80ed04020 100644 --- a/src/algorithms/libs/rtklib/rtklib_stream.cc +++ b/src/algorithms/libs/rtklib/rtklib_stream.cc @@ -1484,13 +1484,15 @@ int reqntrip_s(ntrip_t *ntrip, char *msg) { char buff[256 + NTRIP_MAXSTR]; char *p = buff; + char *s; + s = p; tracet(3, "reqntrip_s: state=%d\n", ntrip->state); p += std::snprintf(p, 256 + NTRIP_MAXSTR, "SOURCE %s %s\r\n", ntrip->passwd, ntrip->mntpnt); - p += std::snprintf(p, NTRIP_MAXSTR, "Source-Agent: NTRIP %s\r\n", NTRIP_AGENT); - p += std::snprintf(p, NTRIP_MAXSTR, "STR: %s\r\n", ntrip->str); - p += std::snprintf(p, NTRIP_MAXSTR, "\r\n"); + p += std::snprintf(p, NTRIP_MAXSTR - (p - s), "Source-Agent: NTRIP %s\r\n", NTRIP_AGENT); + p += std::snprintf(p, NTRIP_MAXSTR - (p - s), "STR: %s\r\n", ntrip->str); + p += std::snprintf(p, sizeof("\r\n") + 1, "\r\n"); if (writetcpcli(ntrip->tcp, reinterpret_cast(buff), p - buff, msg) != p - buff) { @@ -1510,25 +1512,27 @@ int reqntrip_c(ntrip_t *ntrip, char *msg) char buff[1024]; char user[512]; char *p = buff; + char *s; + s = p; tracet(3, "reqntrip_c: state=%d\n", ntrip->state); p += std::snprintf(p, NTRIP_MAXSTR, "GET %s/%s HTTP/1.0\r\n", ntrip->url, ntrip->mntpnt); - p += std::snprintf(p, NTRIP_MAXSTR, "User-Agent: NTRIP %s\r\n", NTRIP_AGENT); + p += std::snprintf(p, NTRIP_MAXSTR - (p - s), "User-Agent: NTRIP %s\r\n", NTRIP_AGENT); if (!*ntrip->user) { - p += std::snprintf(p, NTRIP_MAXSTR, "Accept: */*\r\n"); - p += std::snprintf(p, NTRIP_MAXSTR, "Connection: close\r\n"); + p += std::snprintf(p, NTRIP_MAXSTR - (p - s), "Accept: */*\r\n"); + p += std::snprintf(p, NTRIP_MAXSTR - (p - s), "Connection: close\r\n"); } else { std::snprintf(user, sizeof(user), "%s:%s", ntrip->user, ntrip->passwd); - p += std::snprintf(p, NTRIP_MAXSTR, "Authorization: Basic "); + p += std::snprintf(p, NTRIP_MAXSTR - (p - s), "Authorization: Basic "); p += encbase64(p, reinterpret_cast(user), strlen(user)); - p += std::snprintf(p, NTRIP_MAXSTR, "\r\n"); + p += std::snprintf(p, sizeof("\r\n") + 1, "\r\n"); } - p += std::snprintf(p, NTRIP_MAXSTR, "\r\n"); + p += std::snprintf(p, sizeof("\r\n") + 1, "\r\n"); if (writetcpcli(ntrip->tcp, reinterpret_cast(buff), p - buff, msg) != p - buff) { diff --git a/src/core/libs/supl/asn-rrlp/constr_SEQUENCE.c b/src/core/libs/supl/asn-rrlp/constr_SEQUENCE.c index e6d435617..dbf96b18c 100644 --- a/src/core/libs/supl/asn-rrlp/constr_SEQUENCE.c +++ b/src/core/libs/supl/asn-rrlp/constr_SEQUENCE.c @@ -1151,8 +1151,10 @@ SEQUENCE_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, if(!epres) _ASN_DECODE_STARVED; /* Get the extensions map */ - if(per_get_many_bits(pd, epres, 0, bmlength)) + if(per_get_many_bits(pd, epres, 0, bmlength)) { + FREEMEM(epres); _ASN_DECODE_STARVED; + } memset(&epmd, 0, sizeof(epmd)); epmd.buffer = epres; diff --git a/src/core/libs/supl/asn-supl/constr_SEQUENCE.c b/src/core/libs/supl/asn-supl/constr_SEQUENCE.c index e6d435617..a20057539 100644 --- a/src/core/libs/supl/asn-supl/constr_SEQUENCE.c +++ b/src/core/libs/supl/asn-supl/constr_SEQUENCE.c @@ -1151,9 +1151,10 @@ SEQUENCE_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, if(!epres) _ASN_DECODE_STARVED; /* Get the extensions map */ - if(per_get_many_bits(pd, epres, 0, bmlength)) + if(per_get_many_bits(pd, epres, 0, bmlength)) { + FREEMEM(epres); _ASN_DECODE_STARVED; - + } memset(&epmd, 0, sizeof(epmd)); epmd.buffer = epres; epmd.nbits = bmlength;