checked/changed all sprintf calls

This commit is contained in:
Jean-Francois Dockes
2010-11-15 11:57:39 +01:00
parent c34e945299
commit 061ffda545
13 changed files with 31 additions and 20 deletions
+4 -2
View File
@@ -391,7 +391,8 @@ public:
{
char bf[CIRCACHE_HEADER_SIZE];
memset(bf, 0, CIRCACHE_HEADER_SIZE);
sprintf(bf, headerformat, d.dicsize, d.datasize, d.padsize, d.flags);
snprintf(bf, CIRCACHE_HEADER_SIZE,
headerformat, d.dicsize, d.datasize, d.padsize, d.flags);
if (lseek(m_fd, offset, 0) != offset) {
m_reason << "CirCache::weh: lseek(" << offset <<
") failed: errno " << errno;
@@ -1000,7 +1001,8 @@ bool CirCache::put(const string& udi, const ConfSimple *iconf,
char head[CIRCACHE_HEADER_SIZE];
memset(head, 0, CIRCACHE_HEADER_SIZE);
sprintf(head, headerformat, dic.size(), datalen, npadsize, flags);
snprintf(head, CIRCACHE_HEADER_SIZE,
headerformat, dic.size(), datalen, npadsize, flags);
struct iovec vecs[3];
vecs[0].iov_base = head;
vecs[0].iov_len = CIRCACHE_HEADER_SIZE;
+5 -5
View File
@@ -182,12 +182,12 @@ static bool fileInFiles(const string& file)
#ifdef _WINDOWS
#include <windows.h>
static void datestring(char *d) {
static void datestring(char *d, int sz) {
SYSTEMTIME buf;
GetLocalTime(&buf);
int year = buf.wYear % 100;
sprintf(d, "%02d%02d%02d%02d%02d%02d", year, int(buf.wMonth),
snprintf(d, sz, "%02d%02d%02d%02d%02d%02d", year, int(buf.wMonth),
int(buf.wDay), int(buf.wHour), int(buf.wMinute), int(buf.wSecond));
}
#define vsnprintf _vsnprintf
@@ -195,13 +195,13 @@ static void datestring(char *d) {
#else // !WINDOWS ->
#include <time.h>
static void datestring(char *d)
static void datestring(char *d, int sz)
{
struct tm *tmp;
time_t tim = time((time_t)0);
tmp = localtime(&tim);
int year = tmp->tm_year % 100;
sprintf(d, "%02d%02d%02d%02d%02d%02d", year, tmp->tm_mon+1,
snprintf(d, sz, "%02d%02d%02d%02d%02d%02d", year, tmp->tm_mon+1,
tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
}
@@ -220,7 +220,7 @@ DebugLog::prolog(int lev, const char *f, int line)
}
if (dodate) {
char dts[100];
datestring(dts);
datestring(dts, 100);
writer->put(dts);
}
char buf[100];
+2 -2
View File
@@ -389,7 +389,7 @@ int NetconData::send(const char *buf, int cnt, int expedited)
// Note: byte count may be different from cnt if fd is non-blocking
if (ret < 0) {
char fdcbuf[10];sprintf(fdcbuf, "%d", m_fd);
char fdcbuf[20];sprintf(fdcbuf, "%d", m_fd);
LOGSYSERR("NetconData::send", "send", fdcbuf);
}
return ret;
@@ -453,7 +453,7 @@ int NetconData::receive(char *buf, int cnt, int timeo)
}
m_didtimo = 0;
if ((cnt = read(m_fd, buf + fromibuf, cnt)) < 0) {
char fdcbuf[10];sprintf(fdcbuf, "%d", m_fd);
char fdcbuf[20];sprintf(fdcbuf, "%d", m_fd);
LOGSYSERR("NetconData::receive", "read", fdcbuf);
return -1;
}
+1 -1
View File
@@ -49,7 +49,7 @@ static void caterrno(string *reason, const char *what, int _errno)
if (reason) {
reason->append(what);
reason->append(": errno: ");
char nbuf[10];
char nbuf[20];
sprintf(nbuf, "%d", _errno);
reason->append(nbuf);
reason->append(" : ");