mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-01-28 18:04:51 +00:00
Remove all sprintf usages
Replaced by std::snprintf
This commit is contained in:
parent
05ec821998
commit
7e16077526
@ -593,7 +593,7 @@ private:
|
||||
inline void encode_header()
|
||||
{
|
||||
char header[header_length + 1] = "";
|
||||
std::sprintf(header, "GS%4d", static_cast<int>(body_length_));
|
||||
std::snprintf(header, header_length, "GS%4d", static_cast<int>(body_length_));
|
||||
std::memcpy(data_, header, header_length);
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ static string
|
||||
num2str(int num)
|
||||
{
|
||||
char temp[200];
|
||||
sprintf(temp, "%d", num);
|
||||
snprintf(temp, sizeof(temp), "%d", num);
|
||||
return string(temp);
|
||||
}
|
||||
|
||||
@ -814,7 +814,7 @@ createLocalMemfftKernelString(cl_fft_plan *plan)
|
||||
(*kInfo)->in_place_possible = 1;
|
||||
(*kInfo)->next = nullptr;
|
||||
(*kInfo)->kernel_name = (char *)malloc(sizeof(char) * (kernelName.size() + 1));
|
||||
strcpy((*kInfo)->kernel_name, kernelName.c_str());
|
||||
snprintf((*kInfo)->kernel_name, sizeof((*kInfo)->kernel_name), kernelName.c_str());
|
||||
|
||||
unsigned int numWorkItemsPerXForm = n / radixArray[0];
|
||||
unsigned int numWorkItemsPerWG = numWorkItemsPerXForm <= 64 ? 64 : numWorkItemsPerXForm;
|
||||
@ -1035,7 +1035,7 @@ createGlobalFFTKernelString(cl_fft_plan *plan, int n, int BS, cl_fft_kernel_dir
|
||||
(*kInfo)->in_place_possible = 0;
|
||||
(*kInfo)->next = nullptr;
|
||||
(*kInfo)->kernel_name = (char *)malloc(sizeof(char) * (kernelName.size() + 1));
|
||||
strcpy((*kInfo)->kernel_name, kernelName.c_str());
|
||||
snprintf((*kInfo)->kernel_name, sizeof((*kInfo)->kernel_name), kernelName.c_str());
|
||||
|
||||
insertVariables(localString, R1);
|
||||
|
||||
|
@ -595,7 +595,7 @@ int valsol(const double *azel, const int *vsat, int n,
|
||||
vv = dot(v, v, nv);
|
||||
if (nv > nx && vv > CHISQR[nv - nx - 1])
|
||||
{
|
||||
sprintf(msg, "chi-square error nv=%d vv=%.1f cs=%.1f", nv, vv, CHISQR[nv - nx - 1]);
|
||||
std::snprintf(msg, MAXSOLBUF, "chi-square error nv=%d vv=%.1f cs=%.1f", nv, vv, CHISQR[nv - nx - 1]);
|
||||
return 0;
|
||||
}
|
||||
/* large gdop check */
|
||||
@ -612,7 +612,7 @@ int valsol(const double *azel, const int *vsat, int n,
|
||||
dops(ns, azels, opt->elmin, dop);
|
||||
if (dop[0] <= 0.0 || dop[0] > opt->maxgdop)
|
||||
{
|
||||
sprintf(msg, "gdop error nv=%d gdop=%.1f", nv, dop[0]);
|
||||
std::snprintf(msg, MAXSOLBUF, "gdop error nv=%d gdop=%.1f", nv, dop[0]);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
@ -639,6 +639,7 @@ int estpos(const obsd_t *obs, int n, const double *rs, const double *dts,
|
||||
int stat;
|
||||
int nv;
|
||||
int ns;
|
||||
char msg_aux[128];
|
||||
|
||||
trace(3, "estpos : n=%d\n", n);
|
||||
|
||||
@ -658,7 +659,7 @@ int estpos(const obsd_t *obs, int n, const double *rs, const double *dts,
|
||||
|
||||
if (nv < NX)
|
||||
{
|
||||
sprintf(msg, "lack of valid sats ns=%d", nv);
|
||||
std::snprintf(msg_aux, sizeof(msg_aux), "lack of valid sats ns=%d", nv);
|
||||
break;
|
||||
}
|
||||
/* weight by variance */
|
||||
@ -674,7 +675,7 @@ int estpos(const obsd_t *obs, int n, const double *rs, const double *dts,
|
||||
/* least square estimation */
|
||||
if ((info = lsq(H, v, NX, nv, dx, Q)))
|
||||
{
|
||||
sprintf(msg, "lsq error info=%d", info);
|
||||
std::snprintf(msg_aux, sizeof(msg_aux), "lsq error info=%d", info);
|
||||
break;
|
||||
}
|
||||
for (j = 0; j < NX; j++)
|
||||
@ -712,18 +713,19 @@ int estpos(const obsd_t *obs, int n, const double *rs, const double *dts,
|
||||
free(v);
|
||||
free(H);
|
||||
free(var);
|
||||
|
||||
msg = msg_aux;
|
||||
return stat;
|
||||
}
|
||||
}
|
||||
if (i >= MAXITR)
|
||||
{
|
||||
sprintf(msg, "iteration divergent i=%d", i);
|
||||
std::snprintf(msg_aux, sizeof(msg_aux), "iteration divergent i=%d", i);
|
||||
}
|
||||
|
||||
free(v);
|
||||
free(H);
|
||||
free(var);
|
||||
msg = msg_aux;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -644,7 +644,7 @@ int decode_rtcm2(rtcm_t *rtcm)
|
||||
|
||||
if (rtcm->outtype)
|
||||
{
|
||||
sprintf(rtcm->msgtype, "RTCM %2d (%4d) zcnt=%7.1f staid=%3d seqno=%d",
|
||||
std::snprintf(rtcm->msgtype, sizeof(rtcm->msgtype), "RTCM %2d (%4d) zcnt=%7.1f staid=%3d seqno=%d",
|
||||
type, rtcm->len, zcnt, staid, seqno);
|
||||
}
|
||||
if (type == 3 || type == 22 || type == 23 || type == 24)
|
||||
|
@ -317,7 +317,7 @@ int decode_head1001(rtcm_t *rtcm, int *sync)
|
||||
if (rtcm->outtype)
|
||||
{
|
||||
msg = rtcm->msgtype + strlen(rtcm->msgtype);
|
||||
sprintf(msg, " staid=%4d %s nsat=%2d sync=%d", staid,
|
||||
std::snprintf(msg, sizeof(rtcm->msgtype), " staid=%4d %s nsat=%2d sync=%d", staid,
|
||||
time_str(rtcm->time, 2), nsat, *sync);
|
||||
}
|
||||
return nsat;
|
||||
@ -583,7 +583,7 @@ int decode_type1005(rtcm_t *rtcm)
|
||||
re[j] = rr[j] * 0.0001;
|
||||
}
|
||||
ecef2pos(re, pos);
|
||||
sprintf(msg, " staid=%4d pos=%.8f %.8f %.3f", staid, pos[0] * R2D, pos[1] * R2D,
|
||||
std::snprintf(msg, sizeof(rtcm->msgtype), " staid=%4d pos=%.8f %.8f %.3f", staid, pos[0] * R2D, pos[1] * R2D,
|
||||
pos[2]);
|
||||
}
|
||||
/* test station id */
|
||||
@ -644,7 +644,7 @@ int decode_type1006(rtcm_t *rtcm)
|
||||
re[j] = rr[j] * 0.0001;
|
||||
}
|
||||
ecef2pos(re, pos);
|
||||
sprintf(msg, " staid=%4d pos=%.8f %.8f %.3f anth=%.3f", staid, pos[0] * R2D,
|
||||
std::snprintf(msg, sizeof(rtcm->msgtype), " staid=%4d pos=%.8f %.8f %.3f anth=%.3f", staid, pos[0] * R2D,
|
||||
pos[1] * R2D, pos[2], anth);
|
||||
}
|
||||
/* test station id */
|
||||
@ -697,7 +697,7 @@ int decode_type1007(rtcm_t *rtcm)
|
||||
if (rtcm->outtype)
|
||||
{
|
||||
msg = rtcm->msgtype + strlen(rtcm->msgtype);
|
||||
sprintf(msg, " staid=%4d", staid);
|
||||
std::snprintf(msg, sizeof(rtcm->msgtype), " staid=%4d", staid);
|
||||
}
|
||||
/* test station id */
|
||||
if (!test_staid(rtcm, staid))
|
||||
@ -754,7 +754,7 @@ int decode_type1008(rtcm_t *rtcm)
|
||||
if (rtcm->outtype)
|
||||
{
|
||||
msg = rtcm->msgtype + strlen(rtcm->msgtype);
|
||||
sprintf(msg, " staid=%4d", staid);
|
||||
std::snprintf(msg, sizeof(rtcm->msgtype), " staid=%4d", staid);
|
||||
}
|
||||
/* test station id */
|
||||
if (!test_staid(rtcm, staid))
|
||||
@ -813,7 +813,7 @@ int decode_head1009(rtcm_t *rtcm, int *sync)
|
||||
if (rtcm->outtype)
|
||||
{
|
||||
msg = rtcm->msgtype + strlen(rtcm->msgtype);
|
||||
sprintf(msg, " staid=%4d %s nsat=%2d sync=%d", staid,
|
||||
std::snprintf(msg, sizeof(rtcm->msgtype), " staid=%4d %s nsat=%2d sync=%d", staid,
|
||||
time_str(rtcm->time, 2), nsat, *sync);
|
||||
}
|
||||
return nsat;
|
||||
@ -1127,7 +1127,7 @@ int decode_type1019(rtcm_t *rtcm)
|
||||
if (rtcm->outtype)
|
||||
{
|
||||
msg = rtcm->msgtype + strlen(rtcm->msgtype);
|
||||
sprintf(msg, " prn=%2d iode=%3d iodc=%3d week=%d toe=%6.0f toc=%6.0f svh=%02X",
|
||||
std::snprintf(msg, sizeof(rtcm->msgtype), " prn=%2d iode=%3d iodc=%3d week=%d toe=%6.0f toc=%6.0f svh=%02X",
|
||||
prn, eph.iode, eph.iodc, week, eph.toes, toc, eph.svh);
|
||||
}
|
||||
if (!(sat = satno(sys, prn)))
|
||||
@ -1228,7 +1228,7 @@ int decode_type1020(rtcm_t *rtcm)
|
||||
if (rtcm->outtype)
|
||||
{
|
||||
msg = rtcm->msgtype + strlen(rtcm->msgtype);
|
||||
sprintf(msg, " prn=%2d tk=%02.0f:%02.0f:%02.0f frq=%2d bn=%d tb=%d",
|
||||
std::snprintf(msg, sizeof(rtcm->msgtype), " prn=%2d tk=%02.0f:%02.0f:%02.0f frq=%2d bn=%d tb=%d",
|
||||
prn, tk_h, tk_m, tk_s, geph.frq, bn, tb);
|
||||
}
|
||||
geph.sat = sat;
|
||||
@ -1371,7 +1371,7 @@ int decode_type1029(rtcm_t *rtcm)
|
||||
if (rtcm->outtype)
|
||||
{
|
||||
msg = rtcm->msgtype + strlen(rtcm->msgtype);
|
||||
sprintf(msg, " staid=%4d text=%s", staid, rtcm->msg);
|
||||
std::snprintf(msg, sizeof(rtcm->msgtype), " staid=%4d text=%s", staid, rtcm->msg);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -1469,7 +1469,7 @@ int decode_type1033(rtcm_t *rtcm)
|
||||
if (rtcm->outtype)
|
||||
{
|
||||
msg = rtcm->msgtype + strlen(rtcm->msgtype);
|
||||
sprintf(msg, " staid=%4d", staid);
|
||||
std::snprintf(msg, sizeof(rtcm->msgtype), " staid=%4d", staid);
|
||||
}
|
||||
/* test station id */
|
||||
if (!test_staid(rtcm, staid))
|
||||
@ -1619,7 +1619,7 @@ int decode_type1044(rtcm_t *rtcm)
|
||||
if (rtcm->outtype)
|
||||
{
|
||||
msg = rtcm->msgtype + strlen(rtcm->msgtype);
|
||||
sprintf(msg, " prn=%3d iode=%3d iodc=%3d week=%d toe=%6.0f toc=%6.0f svh=%02X",
|
||||
std::snprintf(msg, sizeof(rtcm->msgtype), " prn=%3d iode=%3d iodc=%3d week=%d toe=%6.0f toc=%6.0f svh=%02X",
|
||||
prn, eph.iode, eph.iodc, week, eph.toes, toc, eph.svh);
|
||||
}
|
||||
if (!(sat = satno(sys, prn)))
|
||||
@ -1732,7 +1732,7 @@ int decode_type1045(rtcm_t *rtcm)
|
||||
if (rtcm->outtype)
|
||||
{
|
||||
msg = rtcm->msgtype + strlen(rtcm->msgtype);
|
||||
sprintf(msg, " prn=%2d iode=%3d week=%d toe=%6.0f toc=%6.0f hs=%d dvs=%d",
|
||||
std::snprintf(msg, sizeof(rtcm->msgtype), " prn=%2d iode=%3d week=%d toe=%6.0f toc=%6.0f hs=%d dvs=%d",
|
||||
prn, eph.iode, week, eph.toes, toc, e5a_hs, e5a_dvs);
|
||||
}
|
||||
if (!(sat = satno(sys, prn)))
|
||||
@ -1846,7 +1846,7 @@ int decode_type1046(rtcm_t *rtcm)
|
||||
if (rtcm->outtype)
|
||||
{
|
||||
msg = rtcm->msgtype + strlen(rtcm->msgtype);
|
||||
sprintf(msg, " prn=%2d iode=%3d week=%d toe=%6.0f toc=%6.0f hs=%d dvs=%d",
|
||||
std::snprintf(msg, sizeof(rtcm->msgtype), " prn=%2d iode=%3d week=%d toe=%6.0f toc=%6.0f hs=%d dvs=%d",
|
||||
prn, eph.iode, week, eph.toes, toc, e5a_hs, e5a_dvs);
|
||||
}
|
||||
if (!(sat = satno(sys, prn)))
|
||||
@ -1963,7 +1963,7 @@ int decode_type1047(rtcm_t *rtcm)
|
||||
if (rtcm->outtype)
|
||||
{
|
||||
msg = rtcm->msgtype + strlen(rtcm->msgtype);
|
||||
sprintf(msg, " prn=%2d iode=%3d iodc=%3d week=%d toe=%6.0f toc=%6.0f svh=%02X",
|
||||
std::snprintf(msg, sizeof(rtcm->msgtype), " prn=%2d iode=%3d iodc=%3d week=%d toe=%6.0f toc=%6.0f svh=%02X",
|
||||
prn, eph.iode, eph.iodc, week, eph.toes, toc, eph.svh);
|
||||
}
|
||||
if (!(sat = satno(sys, prn)))
|
||||
@ -2077,7 +2077,7 @@ int decode_type63(rtcm_t *rtcm)
|
||||
if (rtcm->outtype)
|
||||
{
|
||||
msg = rtcm->msgtype + strlen(rtcm->msgtype);
|
||||
sprintf(msg, " prn=%2d iode=%3d iodc=%3d week=%d toe=%6.0f toc=%6.0f svh=%02X",
|
||||
std::snprintf(msg, sizeof(rtcm->msgtype), " prn=%2d iode=%3d iodc=%3d week=%d toe=%6.0f toc=%6.0f svh=%02X",
|
||||
prn, eph.iode, eph.iodc, week, eph.toes, toc, eph.svh);
|
||||
}
|
||||
if (!(sat = satno(sys, prn)))
|
||||
@ -2162,7 +2162,7 @@ int decode_ssr1_head(rtcm_t *rtcm, int sys, int *sync, int *iod,
|
||||
if (rtcm->outtype)
|
||||
{
|
||||
msg = rtcm->msgtype + strlen(rtcm->msgtype);
|
||||
sprintf(msg, " %s nsat=%2d iod=%2d udi=%2d sync=%d",
|
||||
std::snprintf(msg, sizeof(rtcm->msgtype), " %s nsat=%2d iod=%2d udi=%2d sync=%d",
|
||||
time_str(rtcm->time, 2), nsat, *iod, udi, *sync);
|
||||
}
|
||||
*hsize = i;
|
||||
@ -2224,7 +2224,7 @@ int decode_ssr2_head(rtcm_t *rtcm, int sys, int *sync, int *iod,
|
||||
if (rtcm->outtype)
|
||||
{
|
||||
msg = rtcm->msgtype + strlen(rtcm->msgtype);
|
||||
sprintf(msg, " %s nsat=%2d iod=%2d udi=%2d sync=%d",
|
||||
std::snprintf(msg, sizeof(rtcm->msgtype), " %s nsat=%2d iod=%2d udi=%2d sync=%d",
|
||||
time_str(rtcm->time, 2), nsat, *iod, udi, *sync);
|
||||
}
|
||||
*hsize = i;
|
||||
@ -2290,7 +2290,7 @@ int decode_ssr7_head(rtcm_t *rtcm, int sys, int *sync, int *iod,
|
||||
if (rtcm->outtype)
|
||||
{
|
||||
msg = rtcm->msgtype + strlen(rtcm->msgtype);
|
||||
sprintf(msg, " %s nsat=%2d iod=%2d udi=%2d sync=%d",
|
||||
std::snprintf(msg, sizeof(rtcm->msgtype), " %s nsat=%2d iod=%2d udi=%2d sync=%d",
|
||||
time_str(rtcm->time, 2), nsat, *iod, udi, *sync);
|
||||
}
|
||||
*hsize = i;
|
||||
@ -3167,14 +3167,14 @@ void save_msm_obs(rtcm_t *rtcm, int sys, msm_h_t *h, const double *r,
|
||||
{
|
||||
if (q)
|
||||
{
|
||||
q += sprintf(q, "L%s%s", sig[i], i < h->nsig - 1 ? ", " : "");
|
||||
q += std::snprintf(q, sizeof(rtcm->msmtype[0]), "L%s%s", sig[i], i < h->nsig - 1 ? ", " : "");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (q)
|
||||
{
|
||||
q += sprintf(q, "(%d)%s", h->sigs[i], i < h->nsig - 1 ? ", " : "");
|
||||
q += std::snprintf(q, sizeof(rtcm->msmtype[0]), "(%d)%s", h->sigs[i], i < h->nsig - 1 ? ", " : "");
|
||||
}
|
||||
|
||||
trace(2, "rtcm3 %d: unknown signal id=%2d\n", type, h->sigs[i]);
|
||||
@ -3372,7 +3372,7 @@ int decode_msm_head(rtcm_t *rtcm, int sys, int *sync, int *iod,
|
||||
if (rtcm->outtype)
|
||||
{
|
||||
msg = rtcm->msgtype + strlen(rtcm->msgtype);
|
||||
sprintf(msg, " staid=%4d %s nsat=%2d nsig=%2d iod=%2d ncell=%2d sync=%d",
|
||||
std::snprintf(msg, sizeof(rtcm->msgtype), " staid=%4d %s nsat=%2d nsig=%2d iod=%2d ncell=%2d sync=%d",
|
||||
staid, time_str(rtcm->time, 2), h->nsat, h->nsig, *iod, ncell, *sync);
|
||||
}
|
||||
return ncell;
|
||||
@ -3893,7 +3893,7 @@ int decode_rtcm3(rtcm_t *rtcm)
|
||||
|
||||
if (rtcm->outtype)
|
||||
{
|
||||
sprintf(rtcm->msgtype, "RTCM %4d (%4d):", type, rtcm->len);
|
||||
std::snprintf(rtcm->msgtype, sizeof(rtcm->msgtype), "RTCM %4d (%4d):", type, rtcm->len);
|
||||
}
|
||||
/* real-time input option */
|
||||
if (strstr(rtcm->opt, "-RT_INP"))
|
||||
|
@ -476,34 +476,34 @@ int satid2no(const char *id)
|
||||
void satno2id(int sat, char *id)
|
||||
{
|
||||
int prn;
|
||||
char id_aux[16];
|
||||
switch (satsys(sat, &prn))
|
||||
{
|
||||
case SYS_GPS:
|
||||
sprintf(id, "G%02d", prn - MINPRNGPS + 1);
|
||||
std::snprintf(id, sizeof(id_aux), "G%02d", prn - MINPRNGPS + 1);
|
||||
return;
|
||||
case SYS_GLO:
|
||||
sprintf(id, "R%02d", prn - MINPRNGLO + 1);
|
||||
snprintf(id, sizeof(id_aux), "R%02d", prn - MINPRNGLO + 1);
|
||||
return;
|
||||
case SYS_GAL:
|
||||
sprintf(id, "E%02d", prn - MINPRNGAL + 1);
|
||||
std::snprintf(id, sizeof(id_aux), "E%02d", prn - MINPRNGAL + 1);
|
||||
return;
|
||||
case SYS_QZS:
|
||||
sprintf(id, "J%02d", prn - MINPRNQZS + 1);
|
||||
std::snprintf(id, sizeof(id_aux), "J%02d", prn - MINPRNQZS + 1);
|
||||
return;
|
||||
case SYS_BDS:
|
||||
sprintf(id, "C%02d", prn - MINPRNBDS + 1);
|
||||
std::snprintf(id, sizeof(id_aux), "C%02d", prn - MINPRNBDS + 1);
|
||||
return;
|
||||
case SYS_IRN:
|
||||
sprintf(id, "I%02d", prn - MINPRNIRN + 1);
|
||||
std::snprintf(id, sizeof(id_aux), "I%02d", prn - MINPRNIRN + 1);
|
||||
return;
|
||||
case SYS_LEO:
|
||||
sprintf(id, "L%02d", prn - MINPRNLEO + 1);
|
||||
std::snprintf(id, sizeof(id_aux), "L%02d", prn - MINPRNLEO + 1);
|
||||
return;
|
||||
case SYS_SBS:
|
||||
sprintf(id, "%03d", prn);
|
||||
std::snprintf(id, sizeof(id_aux), "%03d", prn);
|
||||
return;
|
||||
}
|
||||
std::strncpy(id, "", 1);
|
||||
}
|
||||
|
||||
|
||||
@ -1448,7 +1448,7 @@ void matsprint(const double A[], int n, int m, int p, int q, std::string &buffer
|
||||
for (j = 0; j < m; j++)
|
||||
{
|
||||
char buf_[256];
|
||||
sprintf(buf_, " %*.*f", p, q, A[i + j * n]);
|
||||
std::snprintf(buf_, sizeof(buf_), " %*.*f", p, q, A[i + j * n]);
|
||||
std::string s(buf_);
|
||||
buffer += s;
|
||||
}
|
||||
@ -2073,7 +2073,7 @@ void time2str(gtime_t t, char *s, int n)
|
||||
t.sec = 0.0;
|
||||
};
|
||||
time2epoch(t, ep);
|
||||
sprintf(s, "%04.0f/%02.0f/%02.0f %02.0f:%02.0f:%0*.*f", ep[0], ep[1], ep[2],
|
||||
std::snprintf(s, MAXSTATMSG, "%04.0f/%02.0f/%02.0f %02.0f:%02.0f:%0*.*f", ep[0], ep[1], ep[2],
|
||||
ep[3], ep[4], n <= 0 ? 2 : n + 3, n <= 0 ? 0 : n, ep[5]);
|
||||
}
|
||||
|
||||
@ -4147,7 +4147,7 @@ int repstr(char *str, const char *pat, const char *rep)
|
||||
}
|
||||
strncpy(r, p, q - p);
|
||||
r += q - p;
|
||||
r += sprintf(r, "%s", rep);
|
||||
r += std::snprintf(r, sizeof(buff), "%s", rep);
|
||||
}
|
||||
if (p <= str)
|
||||
{
|
||||
@ -4227,35 +4227,35 @@ int reppath(const char *path, char *rpath, gtime_t time, const char *rov,
|
||||
ep0[0] = ep[0];
|
||||
dow = static_cast<int>(floor(time2gpst(time, &week) / 86400.0));
|
||||
doy = static_cast<int>(floor(timediff(time, epoch2time(ep0)) / 86400.0)) + 1;
|
||||
sprintf(rep, "%02d", (static_cast<int>(ep[3]) / 3) * 3);
|
||||
std::snprintf(rep, sizeof(rep), "%02d", (static_cast<int>(ep[3]) / 3) * 3);
|
||||
stat |= repstr(rpath, "%ha", rep);
|
||||
sprintf(rep, "%02d", (static_cast<int>(ep[3]) / 6) * 6);
|
||||
std::snprintf(rep, sizeof(rep), "%02d", (static_cast<int>(ep[3]) / 6) * 6);
|
||||
stat |= repstr(rpath, "%hb", rep);
|
||||
sprintf(rep, "%02d", (static_cast<int>(ep[3]) / 12) * 12);
|
||||
std::snprintf(rep, sizeof(rep), "%02d", (static_cast<int>(ep[3]) / 12) * 12);
|
||||
stat |= repstr(rpath, "%hc", rep);
|
||||
sprintf(rep, "%04.0f", ep[0]);
|
||||
std::snprintf(rep, sizeof(rep), "%04.0f", ep[0]);
|
||||
stat |= repstr(rpath, "%Y", rep);
|
||||
sprintf(rep, "%02.0f", fmod(ep[0], 100.0));
|
||||
std::snprintf(rep, sizeof(rep), "%02.0f", fmod(ep[0], 100.0));
|
||||
stat |= repstr(rpath, "%y", rep);
|
||||
sprintf(rep, "%02.0f", ep[1]);
|
||||
std::snprintf(rep, sizeof(rep), "%02.0f", ep[1]);
|
||||
stat |= repstr(rpath, "%m", rep);
|
||||
sprintf(rep, "%02.0f", ep[2]);
|
||||
std::snprintf(rep, sizeof(rep), "%02.0f", ep[2]);
|
||||
stat |= repstr(rpath, "%d", rep);
|
||||
sprintf(rep, "%02.0f", ep[3]);
|
||||
std::snprintf(rep, sizeof(rep), "%02.0f", ep[3]);
|
||||
stat |= repstr(rpath, "%h", rep);
|
||||
sprintf(rep, "%02.0f", ep[4]);
|
||||
std::snprintf(rep, sizeof(rep), "%02.0f", ep[4]);
|
||||
stat |= repstr(rpath, "%M", rep);
|
||||
sprintf(rep, "%02.0f", floor(ep[5]));
|
||||
std::snprintf(rep, sizeof(rep), "%02.0f", floor(ep[5]));
|
||||
stat |= repstr(rpath, "%S", rep);
|
||||
sprintf(rep, "%03d", doy);
|
||||
std::snprintf(rep, sizeof(rep), "%03d", doy);
|
||||
stat |= repstr(rpath, "%n", rep);
|
||||
sprintf(rep, "%04d", week);
|
||||
std::snprintf(rep, sizeof(rep), "%04d", week);
|
||||
stat |= repstr(rpath, "%W", rep);
|
||||
sprintf(rep, "%d", dow);
|
||||
std::snprintf(rep, sizeof(rep), "%d", dow);
|
||||
stat |= repstr(rpath, "%D", rep);
|
||||
sprintf(rep, "%c", 'a' + static_cast<int>(ep[3]));
|
||||
std::snprintf(rep, sizeof(rep), "%c", 'a' + static_cast<int>(ep[3]));
|
||||
stat |= repstr(rpath, "%H", rep);
|
||||
sprintf(rep, "%02d", (static_cast<int>(ep[4]) / 15) * 15);
|
||||
std::snprintf(rep, sizeof(rep), "%02d", (static_cast<int>(ep[4]) / 15) * 15);
|
||||
stat |= repstr(rpath, "%t", rep);
|
||||
}
|
||||
else if (strstr(rpath, "%ha") || strstr(rpath, "%hb") || strstr(rpath, "%hc") ||
|
||||
@ -5114,7 +5114,7 @@ int rtk_uncompress(const char *file, char *uncfile)
|
||||
{
|
||||
std::strncpy(uncfile, tmpfile, 1024);
|
||||
uncfile[p - tmpfile] = '\0';
|
||||
sprintf(cmd, R"(gzip -f -d -c "%s" > "%s")", tmpfile, uncfile);
|
||||
std::snprintf(cmd, sizeof(cmd), R"(gzip -f -d -c "%s" > "%s")", tmpfile, uncfile);
|
||||
|
||||
if (execcmd(cmd))
|
||||
{
|
||||
@ -5144,8 +5144,6 @@ int rtk_uncompress(const char *file, char *uncfile)
|
||||
dir = fname;
|
||||
fname = p + 1;
|
||||
}
|
||||
// sprintf(cmd, "tar -C \"%s\" -xf \"%s\"", dir, tmpfile);
|
||||
// NOTE: This sprintf triggers a format overflow warning. Replaced by:
|
||||
std::ostringstream temp;
|
||||
std::string s_aux1(dir);
|
||||
std::string s_aux2(tmpfile);
|
||||
@ -5185,7 +5183,7 @@ int rtk_uncompress(const char *file, char *uncfile)
|
||||
{
|
||||
std::strncpy(uncfile, tmpfile, 1024);
|
||||
uncfile[p - tmpfile + 3] = *(p + 3) == 'D' ? 'O' : 'o';
|
||||
sprintf(cmd, R"(crx2rnx < "%s" > "%s")", tmpfile, uncfile);
|
||||
std::snprintf(cmd, sizeof(cmd), R"(crx2rnx < "%s" > "%s")", tmpfile, uncfile);
|
||||
|
||||
if (execcmd(cmd))
|
||||
{
|
||||
@ -5256,8 +5254,8 @@ int expath(const char *path, char *paths[], int nmax)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
sprintf(s1, "^%s$", d->d_name);
|
||||
sprintf(s2, "^%s$", file);
|
||||
std::snprintf(s1, sizeof(s1), "^%s$", d->d_name);
|
||||
std::snprintf(s2, sizeof(s2), "^%s$", file);
|
||||
for (p = s1; *p; p++)
|
||||
{
|
||||
*p = static_cast<char>(tolower(static_cast<int>(*p)));
|
||||
@ -5280,7 +5278,7 @@ int expath(const char *path, char *paths[], int nmax)
|
||||
}
|
||||
if (p && n < nmax)
|
||||
{
|
||||
sprintf(paths[n++], "%s%s", dir, d->d_name);
|
||||
std::snprintf(paths[n++], MAXSTRPATH, "%s%s", dir, d->d_name);
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
|
@ -524,7 +524,7 @@ void errmsg(rtk_t *rtk, const char *format, ...)
|
||||
int n;
|
||||
va_list ap;
|
||||
time2str(rtk->sol.time, tstr, 2);
|
||||
n = sprintf(buff, "%s: ", tstr + 11);
|
||||
n = std::snprintf(buff, sizeof(buff), "%s: ", tstr + 11);
|
||||
va_start(ap, format);
|
||||
n += vsprintf(buff + n, format, ap);
|
||||
va_end(ap);
|
||||
|
@ -64,7 +64,7 @@
|
||||
/* write solution header to output stream ------------------------------------*/
|
||||
void writesolhead(stream_t *stream, const solopt_t *solopt)
|
||||
{
|
||||
unsigned char buff[1024];
|
||||
unsigned char buff[MAXSOLMSG];
|
||||
int n;
|
||||
n = outsolheads(buff, solopt);
|
||||
strwrite(stream, buff, n);
|
||||
@ -88,7 +88,7 @@ void saveoutbuf(rtksvr_t *svr, unsigned char *buff, int n, int index)
|
||||
void writesol(rtksvr_t *svr, int index)
|
||||
{
|
||||
solopt_t solopt = SOLOPT_DEFAULT;
|
||||
unsigned char buff[1024];
|
||||
unsigned char buff[MAXSOLMSG];
|
||||
int i;
|
||||
int n;
|
||||
|
||||
@ -1247,7 +1247,7 @@ void rtksvrsstat(rtksvr_t *svr, int *sstat, char *msg)
|
||||
sstat[i] = strstat(svr->stream + i, s);
|
||||
if (*s)
|
||||
{
|
||||
p += sprintf(p, "(%d) %s ", i + 1, s);
|
||||
p += std::snprintf(p, MAXSTRMSG, "(%d) %s ", i + 1, s);
|
||||
}
|
||||
}
|
||||
rtksvrunlock(svr);
|
||||
|
@ -1411,7 +1411,7 @@ int readsolstatt(char *files[], int nfile, gtime_t ts, gtime_t te,
|
||||
|
||||
for (i = 0; i < nfile; i++)
|
||||
{
|
||||
sprintf(path, "%s.stat", files[i]);
|
||||
std::snprintf(path, sizeof(path), "%s.stat", files[i]);
|
||||
if (!(fp = fopen(path, "re")))
|
||||
{
|
||||
trace(1, "readsolstatt: file open error %s\n", path);
|
||||
@ -1447,7 +1447,7 @@ int outecef(unsigned char *buff, const char *s, const sol_t *sol,
|
||||
|
||||
trace(3, "outecef:\n");
|
||||
|
||||
p += snprintf(p, 255, "%s%s%14.4f%s%14.4f%s%14.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, MAXSOLBUF, "%s%s%14.4f%s%14.4f%s%14.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",
|
||||
s, sep, sol->rr[0], sep, sol->rr[1], sep, sol->rr[2], sep, sol->stat, sep,
|
||||
sol->ns, sep, SQRT_SOL(sol->qr[0]), sep, SQRT_SOL(sol->qr[1]), sep, SQRT_SOL(sol->qr[2]),
|
||||
sep, sqvar(sol->qr[3]), sep, sqvar(sol->qr[4]), sep, sqvar(sol->qr[5]),
|
||||
@ -1481,15 +1481,15 @@ int outpos(unsigned char *buff, const char *s, const sol_t *sol,
|
||||
{
|
||||
deg2dms(pos[0] * R2D, dms1);
|
||||
deg2dms(pos[1] * R2D, dms2);
|
||||
p += sprintf(p, "%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, "%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 += sprintf(p, "%s%s%14.9f%s%14.9f", s, sep, pos[0] * R2D, sep, pos[1] * R2D);
|
||||
p += std::snprintf(p, MAXSOLMSG, "%s%s%14.9f%s%14.9f", s, sep, pos[0] * R2D, sep, pos[1] * R2D);
|
||||
}
|
||||
p += sprintf(p, "%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, "%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);
|
||||
@ -1520,7 +1520,7 @@ int outenu(unsigned char *buff, const char *s, const sol_t *sol,
|
||||
soltocov(sol, P);
|
||||
covenu(pos, P, Q);
|
||||
ecef2enu(pos, rr, enu);
|
||||
p += sprintf(p, "%s%s%14.4f%s%14.4f%s%14.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, "%s%s%14.4f%s%14.4f%s%14.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",
|
||||
s, sep, enu[0], sep, enu[1], sep, enu[2], sep, sol->stat, sep, sol->ns, sep,
|
||||
SQRT_SOL(Q[0]), sep, SQRT_SOL(Q[4]), sep, SQRT_SOL(Q[8]), sep, sqvar(Q[1]),
|
||||
sep, sqvar(Q[5]), sep, sqvar(Q[2]), sep, sol->age, sep, sol->ratio);
|
||||
@ -1550,12 +1550,12 @@ int outnmea_rmc(unsigned char *buff, const sol_t *sol)
|
||||
|
||||
if (sol->stat <= SOLQ_NONE)
|
||||
{
|
||||
p += sprintf(p, "$GPRMC,,,,,,,,,,,,");
|
||||
p += std::snprintf(p, MAXSOLBUF, "$GPRMC,,,,,,,,,,,,");
|
||||
for (q = reinterpret_cast<char *>(buff) + 1, sum = 0; *q; q++)
|
||||
{
|
||||
sum ^= *q;
|
||||
}
|
||||
p += sprintf(p, "*%02X%c%c", sum, 0x0D, 0x0A);
|
||||
p += std::snprintf(p, MAXSOLBUF, "*%02X%c%c", sum, 0x0D, 0x0A);
|
||||
return p - reinterpret_cast<char *>(buff);
|
||||
}
|
||||
time = gpst2utc(sol->time);
|
||||
@ -1583,7 +1583,7 @@ int outnmea_rmc(unsigned char *buff, const sol_t *sol)
|
||||
}
|
||||
deg2dms(fabs(pos[0]) * R2D, dms1);
|
||||
deg2dms(fabs(pos[1]) * R2D, dms2);
|
||||
p += sprintf(p, "$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, "$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<int>(ep[0]) % 100, amag, emag,
|
||||
@ -1592,7 +1592,7 @@ int outnmea_rmc(unsigned char *buff, const sol_t *sol)
|
||||
{
|
||||
sum ^= *q; /* check-sum */
|
||||
}
|
||||
p += sprintf(p, "*%02X%c%c", sum, 0x0D, 0x0A);
|
||||
p += std::snprintf(p, MAXSOLBUF, "*%02X%c%c", sum, 0x0D, 0x0A);
|
||||
return p - reinterpret_cast<char *>(buff);
|
||||
}
|
||||
|
||||
@ -1616,12 +1616,12 @@ int outnmea_gga(unsigned char *buff, const sol_t *sol)
|
||||
|
||||
if (sol->stat <= SOLQ_NONE)
|
||||
{
|
||||
p += sprintf(p, "$GPGGA,,,,,,,,,,,,,,");
|
||||
p += std::snprintf(p, MAXSOLBUF, "$GPGGA,,,,,,,,,,,,,,");
|
||||
for (q = reinterpret_cast<char *>(buff) + 1, sum = 0; *q; q++)
|
||||
{
|
||||
sum ^= *q;
|
||||
}
|
||||
p += sprintf(p, "*%02X%c%c", sum, 0x0D, 0x0A);
|
||||
p += std::snprintf(p, MAXSOLBUF, "*%02X%c%c", sum, 0x0D, 0x0A);
|
||||
return p - reinterpret_cast<char *>(buff);
|
||||
}
|
||||
for (solq = 0; solq < 8; solq++)
|
||||
@ -1646,7 +1646,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 += sprintf(p, "$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, "$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);
|
||||
@ -1654,7 +1654,7 @@ int outnmea_gga(unsigned char *buff, const sol_t *sol)
|
||||
{
|
||||
sum ^= *q; /* check-sum */
|
||||
}
|
||||
p += sprintf(p, "*%02X%c%c", sum, 0x0D, 0x0A);
|
||||
p += std::snprintf(p, MAXSOLBUF, "*%02X%c%c", sum, 0x0D, 0x0A);
|
||||
return p - reinterpret_cast<char *>(buff);
|
||||
}
|
||||
|
||||
@ -1679,12 +1679,12 @@ int outnmea_gsa(unsigned char *buff, const sol_t *sol,
|
||||
|
||||
if (sol->stat <= SOLQ_NONE)
|
||||
{
|
||||
p += sprintf(p, "$GPGSA,A,1,,,,,,,,,,,,,,,");
|
||||
p += std::snprintf(p, MAXSOLBUF, "$GPGSA,A,1,,,,,,,,,,,,,,,");
|
||||
for (q = reinterpret_cast<char *>(buff) + 1, sum = 0; *q; q++)
|
||||
{
|
||||
sum ^= *q;
|
||||
}
|
||||
p += sprintf(p, "*%02X%c%c", sum, 0x0D, 0x0A);
|
||||
p += std::snprintf(p, MAXSOLBUF, "*%02X%c%c", sum, 0x0D, 0x0A);
|
||||
return p - reinterpret_cast<char *>(buff);
|
||||
}
|
||||
|
||||
@ -1713,25 +1713,25 @@ int outnmea_gsa(unsigned char *buff, const sol_t *sol,
|
||||
if (nsat > 0)
|
||||
{
|
||||
s = p;
|
||||
p += sprintf(p, "$GPGSA,A,%d", sol->stat <= 0 ? 1 : 3);
|
||||
p += std::snprintf(p, MAXSOLBUF, "$GPGSA,A,%d", sol->stat <= 0 ? 1 : 3);
|
||||
for (i = 0; i < 12; i++)
|
||||
{
|
||||
if (i < nsat)
|
||||
{
|
||||
p += sprintf(p, ",%02d", prn[i]);
|
||||
p += std::snprintf(p, MAXSOLBUF, ",%02d", prn[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
p += sprintf(p, ",");
|
||||
p += std::snprintf(p, MAXSOLBUF, ",");
|
||||
}
|
||||
}
|
||||
dops(nsat, azel, 0.0, dop);
|
||||
p += sprintf(p, ",%3.1f,%3.1f,%3.1f,1", dop[1], dop[2], dop[3]);
|
||||
p += std::snprintf(p, MAXSOLBUF, ",%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 += sprintf(p, "*%02X%c%c", sum, 0x0D, 0x0A);
|
||||
p += std::snprintf(p, MAXSOLBUF, "*%02X%c%c", sum, 0x0D, 0x0A);
|
||||
}
|
||||
/* GLGSA: glonass */
|
||||
for (sat = 1, nsat = 0; sat <= MAXSAT && nsat < 12; sat++)
|
||||
@ -1753,25 +1753,25 @@ int outnmea_gsa(unsigned char *buff, const sol_t *sol,
|
||||
if (nsat > 0)
|
||||
{
|
||||
s = p;
|
||||
p += sprintf(p, "$GLGSA,A,%d", sol->stat <= 0 ? 1 : 3);
|
||||
p += std::snprintf(p, MAXSOLBUF, "$GLGSA,A,%d", sol->stat <= 0 ? 1 : 3);
|
||||
for (i = 0; i < 12; i++)
|
||||
{
|
||||
if (i < nsat)
|
||||
{
|
||||
p += sprintf(p, ",%02d", prn[i] + 64);
|
||||
p += std::snprintf(p, MAXSOLBUF, ",%02d", prn[i] + 64);
|
||||
}
|
||||
else
|
||||
{
|
||||
p += sprintf(p, ",");
|
||||
p += std::snprintf(p, MAXSOLBUF, ",");
|
||||
}
|
||||
}
|
||||
dops(nsat, azel, 0.0, dop);
|
||||
p += sprintf(p, ",%3.1f,%3.1f,%3.1f,2", dop[1], dop[2], dop[3]);
|
||||
p += std::snprintf(p, MAXSOLBUF, ",%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 += sprintf(p, "*%02X%c%c", sum, 0x0D, 0x0A);
|
||||
p += std::snprintf(p, MAXSOLBUF, "*%02X%c%c", sum, 0x0D, 0x0A);
|
||||
}
|
||||
/* GAGSA: galileo */
|
||||
for (sat = 1, nsat = 0; sat <= MAXSAT && nsat < 12; sat++)
|
||||
@ -1793,25 +1793,25 @@ int outnmea_gsa(unsigned char *buff, const sol_t *sol,
|
||||
if (nsat > 0)
|
||||
{
|
||||
s = p;
|
||||
p += sprintf(p, "$GAGSA,A,%d", sol->stat <= 0 ? 1 : 3);
|
||||
p += std::snprintf(p, MAXSOLBUF, "$GAGSA,A,%d", sol->stat <= 0 ? 1 : 3);
|
||||
for (i = 0; i < 12; i++)
|
||||
{
|
||||
if (i < nsat)
|
||||
{
|
||||
p += sprintf(p, ",%02d", prn[i]);
|
||||
p += std::snprintf(p, MAXSOLBUF, ",%02d", prn[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
p += sprintf(p, ",");
|
||||
p += std::snprintf(p, MAXSOLBUF, ",");
|
||||
}
|
||||
}
|
||||
dops(nsat, azel, 0.0, dop);
|
||||
p += sprintf(p, ",%3.1f,%3.1f,%3.1f,3", dop[1], dop[2], dop[3]);
|
||||
p += std::snprintf(p, MAXSOLBUF, ",%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 += sprintf(p, "*%02X%c%c", sum, 0x0D, 0x0A);
|
||||
p += std::snprintf(p, MAXSOLBUF, "*%02X%c%c", sum, 0x0D, 0x0A);
|
||||
}
|
||||
return p - reinterpret_cast<char *>(buff);
|
||||
}
|
||||
@ -1842,12 +1842,12 @@ int outnmea_gsv(unsigned char *buff, const sol_t *sol,
|
||||
|
||||
if (sol->stat <= SOLQ_NONE)
|
||||
{
|
||||
p += sprintf(p, "$GPGSV,1,1,0,,,,,,,,,,,,,,,,");
|
||||
p += std::snprintf(p, MAXSOLBUF, "$GPGSV,1,1,0,,,,,,,,,,,,,,,,");
|
||||
for (q = reinterpret_cast<char *>(buff) + 1, sum = 0; *q; q++)
|
||||
{
|
||||
sum ^= *q;
|
||||
}
|
||||
p += sprintf(p, "*%02X%c%c", sum, 0x0D, 0x0A);
|
||||
p += std::snprintf(p, MAXSOLBUF, "*%02X%c%c", sum, 0x0D, 0x0A);
|
||||
return p - reinterpret_cast<char *>(buff);
|
||||
}
|
||||
/* GPGSV: gps/sbas */
|
||||
@ -1868,7 +1868,7 @@ int outnmea_gsv(unsigned char *buff, const sol_t *sol,
|
||||
for (i = k = 0; i < nmsg; i++)
|
||||
{
|
||||
s = p;
|
||||
p += sprintf(p, "$GPGSV,%d,%d,%02d", nmsg, i + 1, n);
|
||||
p += std::snprintf(p, MAXSOLBUF, "$GPGSV,%d,%d,%02d", nmsg, i + 1, n);
|
||||
|
||||
for (j = 0; j < 4; j++, k++)
|
||||
{
|
||||
@ -1885,19 +1885,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 += sprintf(p, ",%02d,%02.0f,%03.0f,%02.0f", prn, el, az, snr);
|
||||
p += std::snprintf(p, MAXSOLBUF, ",%02d,%02.0f,%03.0f,%02.0f", prn, el, az, snr);
|
||||
}
|
||||
else
|
||||
{
|
||||
p += sprintf(p, ",,,,");
|
||||
p += std::snprintf(p, MAXSOLBUF, ",,,,");
|
||||
}
|
||||
}
|
||||
p += sprintf(p, ",1"); /* L1C/A */
|
||||
p += std::snprintf(p, MAXSOLBUF, ",1"); /* L1C/A */
|
||||
for (q = s + 1, sum = 0; *q; q++)
|
||||
{
|
||||
sum ^= *q; /* check-sum */
|
||||
}
|
||||
p += sprintf(p, "*%02X%c%c", sum, 0x0D, 0x0A);
|
||||
p += std::snprintf(p, MAXSOLBUF, "*%02X%c%c", sum, 0x0D, 0x0A);
|
||||
}
|
||||
/* GLGSV: glonass */
|
||||
for (sat = 1, n = 0; sat < MAXSAT && n < 12; sat++)
|
||||
@ -1916,7 +1916,7 @@ int outnmea_gsv(unsigned char *buff, const sol_t *sol,
|
||||
for (i = k = 0; i < nmsg; i++)
|
||||
{
|
||||
s = p;
|
||||
p += sprintf(p, "$GLGSV,%d,%d,%02d", nmsg, i + 1, n);
|
||||
p += std::snprintf(p, MAXSOLBUF, "$GLGSV,%d,%d,%02d", nmsg, i + 1, n);
|
||||
|
||||
for (j = 0; j < 4; j++, k++)
|
||||
{
|
||||
@ -1931,19 +1931,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 += sprintf(p, ",%02d,%02.0f,%03.0f,%02.0f", prn, el, az, snr);
|
||||
p += std::snprintf(p, MAXSOLBUF, ",%02d,%02.0f,%03.0f,%02.0f", prn, el, az, snr);
|
||||
}
|
||||
else
|
||||
{
|
||||
p += sprintf(p, ",,,,");
|
||||
p += std::snprintf(p, MAXSOLBUF, ",,,,");
|
||||
}
|
||||
}
|
||||
p += sprintf(p, ",1"); /* L1C/A */
|
||||
p += std::snprintf(p, MAXSOLBUF, ",1"); /* L1C/A */
|
||||
for (q = s + 1, sum = 0; *q; q++)
|
||||
{
|
||||
sum ^= *q; /* check-sum */
|
||||
}
|
||||
p += sprintf(p, "*%02X%c%c", sum, 0x0D, 0x0A);
|
||||
p += std::snprintf(p, MAXSOLBUF, "*%02X%c%c", sum, 0x0D, 0x0A);
|
||||
}
|
||||
/* GAGSV: galileo */
|
||||
for (sat = 1, n = 0; sat < MAXSAT && n < 12; sat++)
|
||||
@ -1962,7 +1962,7 @@ int outnmea_gsv(unsigned char *buff, const sol_t *sol,
|
||||
for (i = k = 0; i < nmsg; i++)
|
||||
{
|
||||
s = p;
|
||||
p += sprintf(p, "$GAGSV,%d,%d,%02d", nmsg, i + 1, n);
|
||||
p += std::snprintf(p, MAXSOLBUF, "$GAGSV,%d,%d,%02d", nmsg, i + 1, n);
|
||||
|
||||
for (j = 0; j < 4; j++, k++)
|
||||
{
|
||||
@ -1976,19 +1976,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 += sprintf(p, ",%02d,%02.0f,%03.0f,%02.0f", prn, el, az, snr);
|
||||
p += std::snprintf(p, MAXSOLBUF, ",%02d,%02.0f,%03.0f,%02.0f", prn, el, az, snr);
|
||||
}
|
||||
else
|
||||
{
|
||||
p += sprintf(p, ",,,,");
|
||||
p += std::snprintf(p, MAXSOLBUF, ",,,,");
|
||||
}
|
||||
}
|
||||
p += sprintf(p, ",7"); /* L1BC */
|
||||
p += std::snprintf(p, MAXSOLBUF, ",7"); /* L1BC */
|
||||
for (q = s + 1, sum = 0; *q; q++)
|
||||
{
|
||||
sum ^= *q; /* check-sum */
|
||||
}
|
||||
p += sprintf(p, "*%02X%c%c", sum, 0x0D, 0x0A);
|
||||
p += std::snprintf(p, MAXSOLBUF, "*%02X%c%c", sum, 0x0D, 0x0A);
|
||||
}
|
||||
return p - reinterpret_cast<char *>(buff);
|
||||
}
|
||||
@ -2021,55 +2021,55 @@ int outprcopts(unsigned char *buff, const prcopt_t *opt)
|
||||
|
||||
trace(3, "outprcopts:\n");
|
||||
|
||||
p += sprintf(p, "%s pos mode : %s\n", COMMENTH, s1[opt->mode]);
|
||||
p += std::snprintf(p, MAXSOLMSG, "%s pos mode : %s\n", COMMENTH, s1[opt->mode]);
|
||||
|
||||
if (PMODE_DGPS <= opt->mode && opt->mode <= PMODE_FIXED)
|
||||
{
|
||||
p += sprintf(p, "%s freqs : %s\n", COMMENTH, s2[opt->nf - 1]);
|
||||
p += std::snprintf(p, MAXSOLMSG, "%s freqs : %s\n", COMMENTH, s2[opt->nf - 1]);
|
||||
}
|
||||
if (opt->mode > PMODE_SINGLE)
|
||||
{
|
||||
p += sprintf(p, "%s solution : %s\n", COMMENTH, s3[opt->soltype]);
|
||||
p += std::snprintf(p, MAXSOLMSG, "%s solution : %s\n", COMMENTH, s3[opt->soltype]);
|
||||
}
|
||||
p += sprintf(p, "%s elev mask : %.1f deg\n", COMMENTH, opt->elmin * R2D);
|
||||
p += std::snprintf(p, MAXSOLMSG, "%s elev mask : %.1f deg\n", COMMENTH, opt->elmin * R2D);
|
||||
if (opt->mode > PMODE_SINGLE)
|
||||
{
|
||||
p += sprintf(p, "%s dynamics : %s\n", COMMENTH, opt->dynamics ? "on" : "off");
|
||||
p += sprintf(p, "%s tidecorr : %s\n", COMMENTH, opt->tidecorr ? "on" : "off");
|
||||
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");
|
||||
}
|
||||
if (opt->mode <= PMODE_FIXED)
|
||||
{
|
||||
p += sprintf(p, "%s ionos opt : %s\n", COMMENTH, s4[opt->ionoopt]);
|
||||
p += std::snprintf(p, MAXSOLMSG, "%s ionos opt : %s\n", COMMENTH, s4[opt->ionoopt]);
|
||||
}
|
||||
p += sprintf(p, "%s tropo opt : %s\n", COMMENTH, s5[opt->tropopt]);
|
||||
p += sprintf(p, "%s ephemeris : %s\n", COMMENTH, s6[opt->sateph]);
|
||||
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]);
|
||||
if (opt->navsys != SYS_GPS)
|
||||
{
|
||||
p += sprintf(p, "%s navi sys :", COMMENTH);
|
||||
p += std::snprintf(p, MAXSOLMSG, "%s navi sys :", COMMENTH);
|
||||
for (i = 0; sys[i]; i++)
|
||||
{
|
||||
if (opt->navsys & sys[i])
|
||||
{
|
||||
p += sprintf(p, " %s", s7[i]);
|
||||
p += std::snprintf(p, MAXSOLMSG, " %s", s7[i]);
|
||||
}
|
||||
}
|
||||
p += sprintf(p, "\n");
|
||||
p += std::snprintf(p, MAXSOLMSG, "\n");
|
||||
}
|
||||
if (PMODE_KINEMA <= opt->mode && opt->mode <= PMODE_FIXED)
|
||||
{
|
||||
p += sprintf(p, "%s amb res : %s\n", COMMENTH, s8[opt->modear]);
|
||||
p += std::snprintf(p, MAXSOLMSG, "%s amb res : %s\n", COMMENTH, s8[opt->modear]);
|
||||
if (opt->navsys & SYS_GLO)
|
||||
{
|
||||
p += sprintf(p, "%s amb glo : %s\n", COMMENTH, s9[opt->glomodear]);
|
||||
p += std::snprintf(p, MAXSOLMSG, "%s amb glo : %s\n", COMMENTH, s9[opt->glomodear]);
|
||||
}
|
||||
if (opt->thresar[0] > 0.0)
|
||||
{
|
||||
p += sprintf(p, "%s val thres : %.1f\n", COMMENTH, opt->thresar[0]);
|
||||
p += std::snprintf(p, MAXSOLMSG, "%s val thres : %.1f\n", COMMENTH, opt->thresar[0]);
|
||||
}
|
||||
}
|
||||
if (opt->mode == PMODE_MOVEB && opt->baseline[0] > 0.0)
|
||||
{
|
||||
p += sprintf(p, "%s baseline : %.4f %.4f m\n", COMMENTH,
|
||||
p += std::snprintf(p, MAXSOLMSG, "%s baseline : %.4f %.4f m\n", COMMENTH,
|
||||
opt->baseline[0], opt->baseline[1]);
|
||||
}
|
||||
for (i = 0; i < 2; i++)
|
||||
@ -2078,7 +2078,7 @@ int outprcopts(unsigned char *buff, const prcopt_t *opt)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
p += sprintf(p, "%s antenna%d : %-21s (%7.4f %7.4f %7.4f)\n", COMMENTH,
|
||||
p += std::snprintf(p, MAXSOLMSG, "%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]);
|
||||
}
|
||||
@ -2110,35 +2110,35 @@ int outsolheads(unsigned char *buff, const solopt_t *opt)
|
||||
|
||||
if (opt->outhead)
|
||||
{
|
||||
p += sprintf(p, "%s (", COMMENTH);
|
||||
p += std::snprintf(p, MAXSOLMSG, "%s (", COMMENTH);
|
||||
if (opt->posf == SOLF_XYZ)
|
||||
{
|
||||
p += sprintf(p, "x/y/z-ecef=WGS84");
|
||||
p += std::snprintf(p, MAXSOLMSG, "x/y/z-ecef=WGS84");
|
||||
}
|
||||
else if (opt->posf == SOLF_ENU)
|
||||
{
|
||||
p += sprintf(p, "e/n/u-baseline=WGS84");
|
||||
p += std::snprintf(p, MAXSOLMSG, "e/n/u-baseline=WGS84");
|
||||
}
|
||||
else
|
||||
{
|
||||
p += sprintf(p, "lat/lon/height=%s/%s", s1[opt->datum], s2[opt->height]);
|
||||
p += std::snprintf(p, MAXSOLMSG, "lat/lon/height=%s/%s", s1[opt->datum], s2[opt->height]);
|
||||
}
|
||||
p += sprintf(p, ",Q=1:fix,2:float,3:sbas,4:dgps,5:single,6:ppp,ns=# of satellites)\n");
|
||||
p += std::snprintf(p, MAXSOLMSG, ",Q=1:fix,2:float,3:sbas,4:dgps,5:single,6:ppp,ns=# of satellites)\n");
|
||||
}
|
||||
p += sprintf(p, "%s %-*s%s", COMMENTH, (opt->timef ? 16 : 8) + timeu + 1, s3[opt->times], sep);
|
||||
p += std::snprintf(p, MAXSOLMSG, "%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 += sprintf(p, "%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, "%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 += sprintf(p, "%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, "%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");
|
||||
@ -2146,14 +2146,14 @@ int outsolheads(unsigned char *buff, const solopt_t *opt)
|
||||
}
|
||||
else if (opt->posf == SOLF_XYZ)
|
||||
{ /* x/y/z-ecef */
|
||||
p += sprintf(p, "%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, "%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 += sprintf(p, "%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, "%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");
|
||||
@ -2223,7 +2223,7 @@ int outsols(unsigned char *buff, const sol_t *sol, const double *rb,
|
||||
week++;
|
||||
gpst = 0.0;
|
||||
}
|
||||
snprintf(s, 255, "%4d%s%*.*f", week, sep, 6 + (timeu <= 0 ? 0 : timeu + 1), timeu, gpst);
|
||||
std::snprintf(s, sizeof(s), "%4d%s%*.*f", week, sep, 6 + (timeu <= 0 ? 0 : timeu + 1), timeu, gpst);
|
||||
}
|
||||
switch (opt->posf)
|
||||
{
|
||||
|
@ -131,14 +131,13 @@ serial_t *openserial(const char *path, int mode, char *msg)
|
||||
}
|
||||
if (i >= 11)
|
||||
{
|
||||
sprintf(msg, "bitrate error (%d)", brate);
|
||||
std::snprintf(msg, MAXSTRMSG, "bitrate error (%d)", brate);
|
||||
tracet(1, "openserial: %s path=%s\n", msg, path);
|
||||
free(serial);
|
||||
return nullptr;
|
||||
}
|
||||
parity = static_cast<char>(toupper(static_cast<int>(parity)));
|
||||
|
||||
// sprintf(dev, "/dev/%s", port); This line triggers a warning. Replaced by:
|
||||
std::string s_aux = "/dev/" + std::string(port);
|
||||
s_aux.resize(128, '\0');
|
||||
int n = s_aux.length();
|
||||
@ -166,7 +165,7 @@ serial_t *openserial(const char *path, int mode, char *msg)
|
||||
|
||||
if ((serial->dev = open(dev, rw | O_NOCTTY | O_NONBLOCK)) < 0)
|
||||
{
|
||||
sprintf(msg, "device open error (%d)", errno);
|
||||
std::snprintf(msg, MAXSTRMSG, "device open error (%d)", errno);
|
||||
tracet(1, "openserial: %s dev=%s\n", msg, dev);
|
||||
free(serial);
|
||||
return nullptr;
|
||||
@ -284,19 +283,19 @@ int openfile_(file_t *file, gtime_t time, char *msg)
|
||||
|
||||
if (!(file->fp = fopen(file->openpath, rw)))
|
||||
{
|
||||
sprintf(msg, "file open error: %s", file->openpath);
|
||||
std::snprintf(msg, MAXSTRMSG, "file open error");
|
||||
tracet(1, "openfile: %s\n", msg);
|
||||
return 0;
|
||||
}
|
||||
tracet(4, "openfile_: open file %s (%s)\n", file->openpath, rw);
|
||||
|
||||
sprintf(tagpath, "%s.tag", file->openpath);
|
||||
std::snprintf(tagpath, MAXSTRPATH + 4, "%s.tag", file->openpath);
|
||||
|
||||
if (file->timetag)
|
||||
{ /* output/sync time-tag */
|
||||
if (!(file->fp_tag = fopen(tagpath, rw)))
|
||||
{
|
||||
sprintf(msg, "tag open error: %s", tagpath);
|
||||
std::snprintf(msg, MAXSTRMSG, "tag open error");
|
||||
tracet(1, "openfile: %s\n", msg);
|
||||
fclose(file->fp);
|
||||
return 0;
|
||||
@ -319,7 +318,7 @@ int openfile_(file_t *file, gtime_t time, char *msg)
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(tagh, "TIMETAG RTKLIB %s", VER_RTKLIB);
|
||||
std::snprintf(tagh, TIMETAGH_LEN + 1, "TIMETAG RTKLIB %s", VER_RTKLIB);
|
||||
memcpy(tagh + TIMETAGH_LEN - 4, &file->tick_f, sizeof(file->tick_f));
|
||||
fwrite(&tagh, 1, TIMETAGH_LEN, file->fp_tag);
|
||||
fwrite(&file->time, 1, sizeof(file->time), file->fp_tag);
|
||||
@ -571,7 +570,7 @@ int readfile(file_t *file, unsigned char *buff, int nmax, char *msg)
|
||||
{
|
||||
trace(1, "fseek error");
|
||||
}
|
||||
sprintf(msg, "end");
|
||||
std::snprintf(msg, MAXSTRPATH, "end");
|
||||
break;
|
||||
}
|
||||
if (file->repmode || file->speed > 0.0)
|
||||
@ -586,7 +585,7 @@ int readfile(file_t *file, unsigned char *buff, int nmax, char *msg)
|
||||
tick_master = tick;
|
||||
}
|
||||
|
||||
sprintf(msg, "T%+.1fs", static_cast<int>(tick) < 0 ? 0.0 : static_cast<int>(tick) / 1000.0);
|
||||
std::snprintf(msg, MAXSTRPATH, "T%+.1fs", static_cast<int>(tick) < 0 ? 0.0 : static_cast<int>(tick) / 1000.0);
|
||||
|
||||
if (static_cast<int>(fpos - file->fpos) >= nmax)
|
||||
{
|
||||
@ -615,7 +614,7 @@ int readfile(file_t *file, unsigned char *buff, int nmax, char *msg)
|
||||
file->fpos += nr;
|
||||
if (nr <= 0)
|
||||
{
|
||||
sprintf(msg, "end");
|
||||
std::snprintf(msg, MAXSTRPATH, "end");
|
||||
}
|
||||
}
|
||||
tracet(5, "readfile: fp=%p \n nr=%d fpos=%u\n", file->fp, nr, file->fpos);
|
||||
@ -829,7 +828,7 @@ int setsock(socket_t sock, char *msg)
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, reinterpret_cast<const char *>(&tv), sizeof(tv)) == -1 ||
|
||||
setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, reinterpret_cast<const char *>(&tv), sizeof(tv)) == -1)
|
||||
{
|
||||
sprintf(msg, "sockopt error: notimeo");
|
||||
std::snprintf(msg, MAXSTRMSG, "sockopt error: notimeo");
|
||||
tracet(1, "setsock: setsockopt error 1 sock=%d err=%d\n", sock, errsock());
|
||||
closesocket(sock);
|
||||
return 0;
|
||||
@ -838,12 +837,12 @@ int setsock(socket_t sock, char *msg)
|
||||
setsockopt(sock, SOL_SOCKET, SO_SNDBUF, reinterpret_cast<const char *>(&bs), sizeof(bs)) == -1)
|
||||
{
|
||||
tracet(1, "setsock: setsockopt error 2 sock=%d err=%d bs=%d\n", sock, errsock(), bs);
|
||||
sprintf(msg, "sockopt error: bufsiz");
|
||||
std::snprintf(msg, MAXSTRMSG, "sockopt error: bufsiz");
|
||||
}
|
||||
if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<const char *>(&mode), sizeof(mode)) == -1)
|
||||
{
|
||||
tracet(1, "setsock: setsockopt error 3 sock=%d err=%d\n", sock, errsock());
|
||||
sprintf(msg, "sockopt error: nodelay");
|
||||
std::snprintf(msg, MAXSTRMSG, "sockopt error: nodelay");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@ -940,7 +939,7 @@ int gentcp(tcp_t *tcp, int type, char *msg)
|
||||
/* generate socket */
|
||||
if ((tcp->sock = socket(AF_INET, SOCK_STREAM, 0)) == -1)
|
||||
{
|
||||
sprintf(msg, "socket error (%d)", errsock());
|
||||
std::snprintf(msg, MAXSTRMSG, "socket error (%d)", errsock());
|
||||
tracet(1, "gentcp: socket error err=%d\n", errsock());
|
||||
tcp->state = -1;
|
||||
return 0;
|
||||
@ -963,7 +962,7 @@ int gentcp(tcp_t *tcp, int type, char *msg)
|
||||
#endif
|
||||
if (bind(tcp->sock, reinterpret_cast<struct sockaddr *>(&tcp->addr), sizeof(tcp->addr)) == -1)
|
||||
{
|
||||
sprintf(msg, "bind error (%d) : %d", errsock(), tcp->port);
|
||||
std::snprintf(msg, MAXSTRMSG, "bind error (%d) : %d", errsock(), tcp->port);
|
||||
tracet(1, "gentcp: bind error port=%d err=%d\n", tcp->port, errsock());
|
||||
closesocket(tcp->sock);
|
||||
tcp->state = -1;
|
||||
@ -975,7 +974,7 @@ int gentcp(tcp_t *tcp, int type, char *msg)
|
||||
{ /* client socket */
|
||||
if (!(hp = gethostbyname(tcp->saddr)))
|
||||
{
|
||||
sprintf(msg, "address error (%s)", tcp->saddr);
|
||||
std::snprintf(msg, MAXSTRMSG, "address error (%s)", tcp->saddr);
|
||||
tracet(1, "gentcp: gethostbyname error addr=%s err=%d\n", tcp->saddr, errsock());
|
||||
closesocket(tcp->sock);
|
||||
tcp->state = 0;
|
||||
@ -1019,7 +1018,7 @@ tcpsvr_t *opentcpsvr(const char *path, char *msg)
|
||||
decodetcppath(path, tcpsvr->svr.saddr, port, nullptr, nullptr, nullptr, nullptr);
|
||||
if (sscanf(port, "%d", &tcpsvr->svr.port) < 1)
|
||||
{
|
||||
sprintf(msg, "port error: %s", port);
|
||||
std::snprintf(msg, MAXSTRMSG, "port error: %s", port);
|
||||
tracet(1, "opentcpsvr: port error port=%s\n", port);
|
||||
free(tcpsvr);
|
||||
return nullptr;
|
||||
@ -1096,17 +1095,17 @@ void updatetcpsvr(tcpsvr_t *tcpsvr, char *msg)
|
||||
if (n == 0)
|
||||
{
|
||||
tcpsvr->svr.state = 1;
|
||||
sprintf(msg, "waiting...");
|
||||
std::snprintf(msg, MAXSTRMSG, "waiting...");
|
||||
return;
|
||||
}
|
||||
tcpsvr->svr.state = 2;
|
||||
if (n == 1)
|
||||
{
|
||||
sprintf(msg, "%s", saddr);
|
||||
std::snprintf(msg, MAXSTRMSG, "%s", saddr);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(msg, "%d clients", n);
|
||||
std::snprintf(msg, MAXSTRMSG, "%d clients", n);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1139,7 +1138,7 @@ int accsock(tcpsvr_t *tcpsvr, char *msg)
|
||||
if ((sock = accept_nb(tcpsvr->svr.sock, reinterpret_cast<struct sockaddr *>(&addr), &len)) == -1)
|
||||
{
|
||||
err = errsock();
|
||||
sprintf(msg, "accept error (%d)", err);
|
||||
std::snprintf(msg, MAXSTRMSG, "accept error (%d)", err);
|
||||
tracet(1, "accsock: accept error sock=%d err=%d\n", tcpsvr->svr.sock, err);
|
||||
closesocket(tcpsvr->svr.sock);
|
||||
tcpsvr->svr.state = 0;
|
||||
@ -1161,7 +1160,7 @@ int accsock(tcpsvr_t *tcpsvr, char *msg)
|
||||
std::strncpy(tcpsvr->cli[i].saddr, inet_ntoa(addr.sin_addr), 256);
|
||||
tcpsvr->cli[i].saddr[255] = '\0';
|
||||
}
|
||||
sprintf(msg, "%s", tcpsvr->cli[i].saddr);
|
||||
std::snprintf(msg, MAXSTRMSG, "%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;
|
||||
tcpsvr->cli[i].tact = tickget();
|
||||
@ -1203,7 +1202,7 @@ int readtcpsvr(tcpsvr_t *tcpsvr, unsigned char *buff, int n, char *msg)
|
||||
{
|
||||
err = errsock();
|
||||
tracet(1, "readtcpsvr: recv error sock=%d err=%d\n", tcpsvr->cli[0].sock, err);
|
||||
sprintf(msg, "recv error (%d)", err);
|
||||
std::snprintf(msg, MAXSTRMSG, "recv error (%d)", err);
|
||||
discontcp(&tcpsvr->cli[0], ticonnect);
|
||||
updatetcpsvr(tcpsvr, msg);
|
||||
return 0;
|
||||
@ -1242,7 +1241,7 @@ int writetcpsvr(tcpsvr_t *tcpsvr, unsigned char *buff, int n, char *msg)
|
||||
{
|
||||
err = errsock();
|
||||
tracet(1, "writetcpsvr: send error i=%d sock=%d err=%d\n", i, tcpsvr->cli[i].sock, err);
|
||||
sprintf(msg, "send error (%d)", err);
|
||||
std::snprintf(msg, MAXSTRMSG, "send error (%d)", err);
|
||||
discontcp(&tcpsvr->cli[i], ticonnect);
|
||||
updatetcpsvr(tcpsvr, msg);
|
||||
return 0;
|
||||
@ -1283,7 +1282,7 @@ int consock(tcpcli_t *tcpcli, char *msg)
|
||||
sizeof(tcpcli->svr.addr))) == -1)
|
||||
{
|
||||
err = errsock();
|
||||
sprintf(msg, "connect error (%d)", err);
|
||||
std::snprintf(msg, MAXSTRMSG, "connect error (%d)", err);
|
||||
tracet(1, "consock: connect error sock=%d err=%d\n", tcpcli->svr.sock, err);
|
||||
closesocket(tcpcli->svr.sock);
|
||||
tcpcli->svr.state = 0;
|
||||
@ -1291,10 +1290,10 @@ int consock(tcpcli_t *tcpcli, char *msg)
|
||||
}
|
||||
if (!stat)
|
||||
{ /* not connect */
|
||||
sprintf(msg, "connecting...");
|
||||
std::snprintf(msg, MAXSTRMSG, "connecting...");
|
||||
return 0;
|
||||
}
|
||||
sprintf(msg, "%s", tcpcli->svr.saddr);
|
||||
std::snprintf(msg, MAXSTRMSG, "%s", tcpcli->svr.saddr);
|
||||
tracet(2, "consock: connected sock=%d addr=%s\n", tcpcli->svr.sock, tcpcli->svr.saddr);
|
||||
tcpcli->svr.state = 2;
|
||||
tcpcli->svr.tact = tickget();
|
||||
@ -1319,7 +1318,7 @@ tcpcli_t *opentcpcli(const char *path, char *msg)
|
||||
decodetcppath(path, tcpcli->svr.saddr, port, nullptr, nullptr, nullptr, nullptr);
|
||||
if (sscanf(port, "%d", &tcpcli->svr.port) < 1)
|
||||
{
|
||||
sprintf(msg, "port error: %s", port);
|
||||
std::snprintf(msg, MAXSTRMSG, "port error: %s", port);
|
||||
tracet(1, "opentcp: port error port=%s\n", port);
|
||||
free(tcpcli);
|
||||
return nullptr;
|
||||
@ -1369,7 +1368,7 @@ int waittcpcli(tcpcli_t *tcpcli, char *msg)
|
||||
if (tcpcli->toinact > 0 &&
|
||||
static_cast<int>(tickget() - tcpcli->svr.tact) > tcpcli->toinact)
|
||||
{
|
||||
sprintf(msg, "timeout");
|
||||
std::snprintf(msg, MAXSTRMSG, "timeout");
|
||||
tracet(2, "waittcpcli: inactive timeout sock=%d\n", tcpcli->svr.sock);
|
||||
discontcp(&tcpcli->svr, tcpcli->tirecon);
|
||||
return 0;
|
||||
@ -1396,7 +1395,7 @@ int readtcpcli(tcpcli_t *tcpcli, unsigned char *buff, int n, char *msg)
|
||||
{
|
||||
err = errsock();
|
||||
tracet(1, "readtcpcli: recv error sock=%d err=%d\n", tcpcli->svr.sock, err);
|
||||
sprintf(msg, "recv error (%d)", err);
|
||||
std::snprintf(msg, MAXSTRMSG, "recv error (%d)", err);
|
||||
discontcp(&tcpcli->svr, tcpcli->tirecon);
|
||||
return 0;
|
||||
}
|
||||
@ -1426,7 +1425,7 @@ int writetcpcli(tcpcli_t *tcpcli, unsigned char *buff, int n, char *msg)
|
||||
{
|
||||
err = errsock();
|
||||
tracet(1, "writetcp: send error sock=%d err=%d\n", tcpcli->svr.sock, err);
|
||||
sprintf(msg, "send error (%d)", err);
|
||||
std::snprintf(msg, MAXSTRMSG, "send error (%d)", err);
|
||||
discontcp(&tcpcli->svr, tcpcli->tirecon);
|
||||
return 0;
|
||||
}
|
||||
@ -1488,10 +1487,10 @@ int reqntrip_s(ntrip_t *ntrip, char *msg)
|
||||
|
||||
tracet(3, "reqntrip_s: state=%d\n", ntrip->state);
|
||||
|
||||
p += snprintf(p, 256 + NTRIP_MAXSTR, "SOURCE %s %s\r\n", ntrip->passwd, ntrip->mntpnt);
|
||||
p += sprintf(p, "Source-Agent: NTRIP %s\r\n", NTRIP_AGENT);
|
||||
p += sprintf(p, "STR: %s\r\n", ntrip->str);
|
||||
p += sprintf(p, "\r\n");
|
||||
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");
|
||||
|
||||
if (writetcpcli(ntrip->tcp, reinterpret_cast<unsigned char *>(buff), p - buff, msg) != p - buff)
|
||||
{
|
||||
@ -1514,22 +1513,22 @@ int reqntrip_c(ntrip_t *ntrip, char *msg)
|
||||
|
||||
tracet(3, "reqntrip_c: state=%d\n", ntrip->state);
|
||||
|
||||
p += sprintf(p, "GET %s/%s HTTP/1.0\r\n", ntrip->url, ntrip->mntpnt);
|
||||
p += sprintf(p, "User-Agent: NTRIP %s\r\n", NTRIP_AGENT);
|
||||
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);
|
||||
|
||||
if (!*ntrip->user)
|
||||
{
|
||||
p += sprintf(p, "Accept: */*\r\n");
|
||||
p += sprintf(p, "Connection: close\r\n");
|
||||
p += std::snprintf(p, NTRIP_MAXSTR, "Accept: */*\r\n");
|
||||
p += std::snprintf(p, NTRIP_MAXSTR, "Connection: close\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(user, "%s:%s", ntrip->user, ntrip->passwd);
|
||||
p += sprintf(p, "Authorization: Basic ");
|
||||
std::snprintf(user, sizeof(user), "%s:%s", ntrip->user, ntrip->passwd);
|
||||
p += std::snprintf(p, NTRIP_MAXSTR, "Authorization: Basic ");
|
||||
p += encbase64(p, reinterpret_cast<unsigned char *>(user), strlen(user));
|
||||
p += sprintf(p, "\r\n");
|
||||
p += std::snprintf(p, NTRIP_MAXSTR, "\r\n");
|
||||
}
|
||||
p += sprintf(p, "\r\n");
|
||||
p += std::snprintf(p, NTRIP_MAXSTR, "\r\n");
|
||||
|
||||
if (writetcpcli(ntrip->tcp, reinterpret_cast<unsigned char *>(buff), p - buff, msg) != p - buff)
|
||||
{
|
||||
@ -1565,7 +1564,7 @@ int rspntrip_s(ntrip_t *ntrip, char *msg)
|
||||
*q++ = *p++;
|
||||
}
|
||||
ntrip->state = 2;
|
||||
sprintf(msg, "%s/%s", ntrip->tcp->svr.saddr, ntrip->mntpnt);
|
||||
std::snprintf(msg, MAXSTRMSG, "%s/%s", ntrip->tcp->svr.saddr, ntrip->mntpnt);
|
||||
tracet(2, "rspntrip_s: response ok nb=%d\n", ntrip->nb);
|
||||
return 1;
|
||||
}
|
||||
@ -1589,7 +1588,7 @@ int rspntrip_s(ntrip_t *ntrip, char *msg)
|
||||
}
|
||||
else if (ntrip->nb >= NTRIP_MAXRSP)
|
||||
{ /* buffer overflow */
|
||||
sprintf(msg, "response overflow");
|
||||
std::snprintf(msg, MAXSTRMSG, "response overflow");
|
||||
tracet(1, "rspntrip_s: response overflow nb=%d\n", ntrip->nb);
|
||||
ntrip->nb = 0;
|
||||
ntrip->buff[0] = '\0';
|
||||
@ -1622,7 +1621,7 @@ int rspntrip_c(ntrip_t *ntrip, char *msg)
|
||||
*q++ = *p++;
|
||||
}
|
||||
ntrip->state = 2;
|
||||
sprintf(msg, "%s/%s", ntrip->tcp->svr.saddr, ntrip->mntpnt);
|
||||
std::snprintf(msg, MAXSTRMSG, "%s/%s", ntrip->tcp->svr.saddr, ntrip->mntpnt);
|
||||
tracet(2, "rspntrip_c: response ok nb=%d\n", ntrip->nb);
|
||||
return 1;
|
||||
}
|
||||
@ -1631,11 +1630,11 @@ int rspntrip_c(ntrip_t *ntrip, char *msg)
|
||||
if (!*ntrip->mntpnt)
|
||||
{ /* source table request */
|
||||
ntrip->state = 2;
|
||||
sprintf(msg, "source table received");
|
||||
std::snprintf(msg, MAXSTRMSG, "source table received");
|
||||
tracet(2, "rspntrip_c: receive source table nb=%d\n", ntrip->nb);
|
||||
return 1;
|
||||
}
|
||||
sprintf(msg, "no mountp. reconnect...");
|
||||
std::snprintf(msg, MAXSTRMSG, "no mountp. reconnect...");
|
||||
tracet(2, "rspntrip_c: no mount point nb=%d\n", ntrip->nb);
|
||||
ntrip->nb = 0;
|
||||
ntrip->buff[0] = '\0';
|
||||
@ -1661,7 +1660,7 @@ int rspntrip_c(ntrip_t *ntrip, char *msg)
|
||||
}
|
||||
else if (ntrip->nb >= NTRIP_MAXRSP)
|
||||
{ /* buffer overflow */
|
||||
sprintf(msg, "response overflow");
|
||||
std::snprintf(msg, MAXSTRMSG, "response overflow");
|
||||
tracet(1, "rspntrip_s: response overflow nb=%d\n", ntrip->nb);
|
||||
ntrip->nb = 0;
|
||||
ntrip->buff[0] = '\0';
|
||||
@ -1750,14 +1749,13 @@ ntrip_t *openntrip(const char *path, int type, char *msg)
|
||||
/* use default port if no port specified */
|
||||
if (!*port)
|
||||
{
|
||||
sprintf(port, "%d", type ? NTRIP_CLI_PORT : NTRIP_SVR_PORT);
|
||||
std::snprintf(port, sizeof(port), "%d", type ? NTRIP_CLI_PORT : NTRIP_SVR_PORT);
|
||||
}
|
||||
sprintf(tpath, "%s:%s", addr, port);
|
||||
std::snprintf(tpath, MAXSTRPATH, "%s:%s", addr, port);
|
||||
|
||||
/* ntrip access via proxy server */
|
||||
if (*proxyaddr)
|
||||
{
|
||||
// sprintf(ntrip->url, "http://%s", tpath); This line triggers a warning. Replaced by:
|
||||
std::string s_aux = "http://" + std::string(tpath);
|
||||
int n = s_aux.length();
|
||||
if (n < 256)
|
||||
@ -1978,7 +1976,6 @@ void *ftpthread(void *arg)
|
||||
{
|
||||
p = remote;
|
||||
}
|
||||
// sprintf(local, "%s%c%s", localdir, FILEPATHSEP, p); This line triggers a warning. Replaced by:
|
||||
std::string s_aux = std::string(localdir) + std::to_string(FILEPATHSEP) + std::string(p);
|
||||
int n = s_aux.length();
|
||||
if (n < 1024)
|
||||
@ -1989,7 +1986,6 @@ void *ftpthread(void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
// sprintf(errfile, "%s.err", local); This line triggers a warning. Replaced by:
|
||||
std::string s_aux2 = std::string(local) + ".err";
|
||||
n = s_aux2.length();
|
||||
if (n < 1024)
|
||||
@ -2022,14 +2018,12 @@ void *ftpthread(void *arg)
|
||||
if (*proxyaddr)
|
||||
{
|
||||
proto = ftp->proto ? const_cast<char *>("http") : const_cast<char *>("ftp");
|
||||
sprintf(env, "set %s_proxy=http://%s & ", proto, proxyaddr);
|
||||
std::snprintf(env, sizeof(env), "set %s_proxy=http://%s & ", proto, proxyaddr);
|
||||
proxyopt = const_cast<char *>("--proxy=on ");
|
||||
}
|
||||
/* download command (ref [2]) */
|
||||
if (ftp->proto == 0)
|
||||
{ /* ftp */
|
||||
// sprintf(opt, "--ftp-user=%s --ftp-password=%s --glob=off --passive-ftp %s-t 1 -T %d -O \"%s\"",
|
||||
// ftp->user, ftp->passwd, proxyopt, FTP_TIMEOUT, local); This line triggers a warning. Replaced by:
|
||||
std::string s_aux = "--ftp-user=" + std::string(ftp->user) + " --ftp-password=" + std::string(ftp->passwd) +
|
||||
" --glob=off --passive-ftp " + std::string(proxyopt) + "s-t 1 -T " + std::to_string(FTP_TIMEOUT) +
|
||||
" -O \"" + std::string(local) + "\"";
|
||||
@ -2042,8 +2036,6 @@ void *ftpthread(void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
// sprintf(cmd, "%s%s %s \"ftp://%s/%s\" 2> \"%s\"\n", env, FTP_CMD, opt, ftp->addr,
|
||||
// remote, errfile); This line triggers a warning. Replaced by:
|
||||
std::string s_aux2 = std::string(env) + std::string(FTP_CMD) + " " + std::string(opt) + " " +
|
||||
"\"ftp://" + std::string(ftp->addr) + "/" + std::string(remote) + "\" 2> \"" + std::string(errfile) + "\"\n";
|
||||
k = s_aux2.length();
|
||||
@ -2054,7 +2046,6 @@ void *ftpthread(void *arg)
|
||||
}
|
||||
else
|
||||
{ /* http */
|
||||
// sprintf(opt, "%s-t 1 -T %d -O \"%s\"", proxyopt, FTP_TIMEOUT, local); This line triggers a warning. Replaced by:
|
||||
std::string s_aux = std::string(proxyopt) + " -t 1 -T " + std::to_string(FTP_TIMEOUT) + " -O \"" + std::string(local) + "\"";
|
||||
int l = s_aux.length();
|
||||
for (int i = 0; (i < l) && (i < 1024); i++)
|
||||
@ -2062,8 +2053,6 @@ void *ftpthread(void *arg)
|
||||
opt[i] = s_aux[i];
|
||||
}
|
||||
|
||||
// sprintf(cmd, "%s%s %s \"http://%s/%s\" 2> \"%s\"\n", env, FTP_CMD, opt, ftp->addr,
|
||||
// remote, errfile); This line triggers a warning. Replaced by:
|
||||
std::string s_aux2 = std::string(env) + std::string(FTP_CMD) + " " + std::string(opt) + " " +
|
||||
"\"http://" + std::string(ftp->addr) + "/" + std::string(remote) + "\" 2> \"" + std::string(errfile) + "\"\n";
|
||||
l = s_aux2.length();
|
||||
@ -2186,7 +2175,10 @@ int readftp(ftp_t *ftp, unsigned char *buff, int n, char *msg)
|
||||
if (ftp->state <= 0)
|
||||
{ /* ftp/http not executed? */
|
||||
ftp->state = 1;
|
||||
sprintf(msg, "%s://%s", ftp->proto ? "http" : "ftp", ftp->addr);
|
||||
if (std::snprintf(msg, sizeof(ftp->addr), "%s://%s", ftp->proto ? "http" : "ftp", ftp->addr) < 0)
|
||||
{
|
||||
tracet(1, "readftp: ftp address truncation\n");
|
||||
}
|
||||
|
||||
if (pthread_create(&ftp->thread, nullptr, ftpthread, ftp))
|
||||
{
|
||||
@ -2203,7 +2195,10 @@ int readftp(ftp_t *ftp, unsigned char *buff, int n, char *msg)
|
||||
|
||||
if (ftp->state == 3)
|
||||
{ /* ftp error */
|
||||
sprintf(msg, "%s error (%d)", ftp->proto ? "http" : "ftp", ftp->error);
|
||||
if (std::snprintf(msg, sizeof(ftp->addr), "%s error (%d)", ftp->proto ? "http" : "ftp", ftp->error) < 0)
|
||||
{
|
||||
tracet(1, "readftp: ftp address truncation\n");
|
||||
}
|
||||
|
||||
/* set next retry time */
|
||||
ftp->tnext = nextdltime(ftp->topts, 0);
|
||||
@ -2217,7 +2212,7 @@ int readftp(ftp_t *ftp, unsigned char *buff, int n, char *msg)
|
||||
{
|
||||
*p++ = *q++;
|
||||
}
|
||||
p += sprintf(reinterpret_cast<char *>(p), "\r\n");
|
||||
p += std::snprintf(reinterpret_cast<char *>(p), sizeof("\r\n") + 1, "\r\n");
|
||||
|
||||
/* set next download time */
|
||||
ftp->tnext = nextdltime(ftp->topts, 1);
|
||||
|
Loading…
Reference in New Issue
Block a user