From d9422420479df5f829dfb596d7879fc7bb439caa Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Sat, 3 Oct 2015 17:25:17 +0200 Subject: [PATCH] replace all %lld instances --- src/index/beaglequeue.cpp | 8 ++------ src/index/fsindexer.cpp | 15 ++++----------- src/internfile/mh_mbox.cpp | 6 +++--- src/internfile/mh_text.cpp | 12 ++++++------ src/internfile/uncomp.cpp | 7 ++++--- src/query/docseqhist.cpp | 4 +--- src/rcldb/rcldb.cpp | 5 +++-- src/rcldb/searchdatatox.cpp | 5 ++--- src/utils/circache.cpp | 16 +++++++++------- src/utils/smallut.cpp | 5 +---- 10 files changed, 35 insertions(+), 48 deletions(-) diff --git a/src/index/beaglequeue.cpp b/src/index/beaglequeue.cpp index 8a763b46..20511e15 100644 --- a/src/index/beaglequeue.cpp +++ b/src/index/beaglequeue.cpp @@ -401,9 +401,7 @@ BeagleQueueIndexer::processone(const string &path, if (dotdoc.fmtime.empty()) dotdoc.fmtime = ascdate; - char cbuf[100]; - sprintf(cbuf, "%lld", (long long)stp->st_size); - dotdoc.pcbytes = cbuf; + dotdoc.pcbytes = lltodecstr(stp->st_size); // Document signature for up to date checks: none. dotdoc.sig.clear(); @@ -441,9 +439,7 @@ BeagleQueueIndexer::processone(const string &path, doc.fmtime = ascdate; dotdoc.fmtime = doc.fmtime; - char cbuf[100]; - sprintf(cbuf, "%lld", (long long)stp->st_size); - doc.pcbytes = cbuf; + doc.pcbytes = lltodecstr(stp->st_size); // Document signature for up to date checks: none. doc.sig.clear(); doc.url = dotdoc.url; diff --git a/src/index/fsindexer.cpp b/src/index/fsindexer.cpp index f7de8120..fcb9375b 100644 --- a/src/index/fsindexer.cpp +++ b/src/index/fsindexer.cpp @@ -487,11 +487,8 @@ void FsIndexer::setlocalfields(const map& fields, Rcl::Doc& doc) void FsIndexer::makesig(const struct stat *stp, string& out) { - char cbuf[100]; - sprintf(cbuf, "%lld" "%ld", (long long)stp->st_size, - o_uptodate_test_use_mtime ? - (long)stp->st_mtime : (long)stp->st_ctime); - out = cbuf; + out = lltodecstr(stp->st_size) + + lltodecstr(o_uptodate_test_use_mtime ? stp->st_mtime : stp->st_ctime); } #ifdef IDX_THREADS @@ -778,9 +775,7 @@ FsIndexer::processonefile(RclConfig *config, // Set container file name for all docs, top or subdoc doc.meta[Rcl::Doc::keytcfn] = utf8fn; - char cbuf[100]; - sprintf(cbuf, "%lld", (long long)stp->st_size); - doc.pcbytes = cbuf; + doc.pcbytes = lltodecstr(stp->st_size); // Document signature for up to date checks. All subdocs inherit the // file's. doc.sig = sig; @@ -868,9 +863,7 @@ FsIndexer::processonefile(RclConfig *config, fileDoc.url = path_pathtofileurl(fn); if (m_havelocalfields) setlocalfields(localfields, fileDoc); - char cbuf[100]; - sprintf(cbuf, "%lld", (long long)stp->st_size); - fileDoc.pcbytes = cbuf; + fileDoc.pcbytes = lltodecstr(stp->st_size); } fileDoc.sig = sig; diff --git a/src/internfile/mh_mbox.cpp b/src/internfile/mh_mbox.cpp index db2b4f33..1b506c0e 100644 --- a/src/internfile/mh_mbox.cpp +++ b/src/internfile/mh_mbox.cpp @@ -123,8 +123,8 @@ public: return -1; } if (fseeko(fp, cacheoffset(msgnum), SEEK_SET) != 0) { - LOGDEB0(("MboxCache::get_offsets: seek %lld errno %d\n", - cacheoffset(msgnum), errno)); + LOGDEB0(("MboxCache::get_offsets: seek %s errno %d\n", + lltodecstr(cacheoffset(msgnum)).c_str(), errno)); return -1; } mbhoff_type offset = -1; @@ -135,7 +135,7 @@ public: ret, errno)); return -1; } - LOGDEB0(("MboxCache::get_offsets: ret %lld\n", (long long)offset)); + LOGDEB0(("MboxCache::get_offsets: ret %s\n", lltodecstr(offset).c_str())); return offset; } diff --git a/src/internfile/mh_text.cpp b/src/internfile/mh_text.cpp index a72b14e8..3061ab5f 100644 --- a/src/internfile/mh_text.cpp +++ b/src/internfile/mh_text.cpp @@ -43,8 +43,8 @@ const int KB = 1024; // Process a plain text file bool MimeHandlerText::set_document_file(const string& mt, const string &fn) { - LOGDEB(("MimeHandlerText::set_document_file: [%s] offs %lld\n", - fn.c_str(), m_offs)); + LOGDEB(("MimeHandlerText::set_document_file: [%s] offs %s\n", + fn.c_str(), lltodecstr(m_offs).c_str())); RecollFilter::set_document_file(mt, fn); @@ -109,8 +109,9 @@ bool MimeHandlerText::set_document_string(const string& mt, const string& otext) bool MimeHandlerText::skip_to_document(const string& ipath) { - long long t; - if (sscanf(ipath.c_str(), "%lld", &t) != 1) { + char *endptr; + long long t = strtoll(ipath.c_str(), &endptr, 10); + if (endptr == ipath.c_str()) { LOGERR(("MimeHandlerText::skip_to_document: bad ipath offs [%s]\n", ipath.c_str())); return false; @@ -156,8 +157,7 @@ bool MimeHandlerText::next_document() // first chunk). This is a hack. The right thing to do would // be to use a different mtype for files over the page size, // and keep text/plain only for smaller files. - char buf[30]; - sprintf(buf, "%lld", (long long)(m_offs - srclen)); + string buf = lltodecstr(m_offs - srclen); if (m_offs - srclen != 0) m_metaData[cstr_dj_keyipath] = buf; readnext(); diff --git a/src/internfile/uncomp.cpp b/src/internfile/uncomp.cpp index 61556967..76952e5a 100644 --- a/src/internfile/uncomp.cpp +++ b/src/internfile/uncomp.cpp @@ -85,9 +85,10 @@ bool Uncomp::uncompressfile(const string& ifn, long long filembs = fsize / (1024 * 1024); if (availmbs < 2 * filembs + 1) { - LOGERR(("uncompressfile. %lld MBs available in %s not enough " - "to uncompress %s of size %lld mbs\n", availmbs, - m_dir->dirname(), ifn.c_str(), filembs)); + LOGERR(("uncompressfile. %s MBs available in %s not enough " + "to uncompress %s of size %s mbs\n", + lltodecstr(availmbs).c_str(), m_dir->dirname(), + ifn.c_str(), lltodecstr(filembs).c_str())); return false; } } diff --git a/src/query/docseqhist.cpp b/src/query/docseqhist.cpp index abffe77d..c89a93c1 100644 --- a/src/query/docseqhist.cpp +++ b/src/query/docseqhist.cpp @@ -34,11 +34,9 @@ using std::list; // The U distinguishes udi-based entries from older fn+ipath ones bool RclDHistoryEntry::encode(string& value) { - char chartime[30]; - sprintf(chartime,"%lld", (long long)unixtime); string budi; base64_encode(udi, budi); - value = string("U ") + string(chartime) + " " + budi; + value = string("U ") + lltodecstr(unixtime) + " " + budi; return true; } diff --git a/src/rcldb/rcldb.cpp b/src/rcldb/rcldb.cpp index 7ed4cf47..054d3027 100644 --- a/src/rcldb/rcldb.cpp +++ b/src/rcldb/rcldb.cpp @@ -26,6 +26,7 @@ #include #include #include +#include using namespace std; @@ -1690,8 +1691,8 @@ void Db::waitUpdIdle() LOGERR(("Db::waitUpdIdle: flush() failed: %s\n", ermsg.c_str())); } m_ndb->m_totalworkns += chron.nanos(); - LOGINFO(("Db::waitUpdIdle: total xapian work %lld mS\n", - m_ndb->m_totalworkns/1000000)); + LOGINFO(("Db::waitUpdIdle: total xapian work %s mS\n", + lltodecstr(m_ndb->m_totalworkns/1000000).c_str())); } } #endif diff --git a/src/rcldb/searchdatatox.cpp b/src/rcldb/searchdatatox.cpp index fa68aa26..6dfcbceb 100644 --- a/src/rcldb/searchdatatox.cpp +++ b/src/rcldb/searchdatatox.cpp @@ -219,9 +219,8 @@ bool SearchData::toNativeQuery(Rcl::Db &db, void *d) if (m_minSize != size_t(-1) || m_maxSize != size_t(-1)) { Xapian::Query sq; - char min[50], max[50]; - sprintf(min, "%lld", (long long)m_minSize); - sprintf(max, "%lld", (long long)m_maxSize); + string min = lltodecstr(m_minSize); + string max = lltodecstr(m_maxSize); if (m_minSize == size_t(-1)) { string value(max); leftzeropad(value, 12); diff --git a/src/utils/circache.cpp b/src/utils/circache.cpp index a9f51714..f3b77781 100644 --- a/src/utils/circache.cpp +++ b/src/utils/circache.cpp @@ -653,8 +653,8 @@ public: { headoffs = offs; padsize = d.padsize; - LOGDEB2(("CCScanHookRecord::takeone: offs %lld padsize %lld\n", - headoffs, padsize)); + LOGDEB2(("CCScanHookRecord::takeone: offs %s padsize %s\n", + lltodecstr(headoffs).c_str(), lltodecstr(padsize).c_str())); return Continue; } }; @@ -666,8 +666,8 @@ string CirCache::getpath() bool CirCache::create(off_t maxsize, int flags) { - LOGDEB(("CirCache::create: [%s] maxsz %lld flags 0x%x\n", - m_dir.c_str(), maxsize, flags)); + LOGDEB(("CirCache::create: [%s] maxsz %s flags 0x%x\n", + m_dir.c_str(), lltodecstr((long long)maxsize).c_str(), flags)); if (m_d == 0) { LOGERR(("CirCache::create: null data\n")); return false; @@ -708,10 +708,12 @@ bool CirCache::create(off_t maxsize, int flags) } m_d->m_maxsize = maxsize; m_d->m_uniquentries = ((flags & CC_CRUNIQUE) != 0); - LOGDEB(("CirCache::create: rewriting header with " - "maxsize %lld oheadoffs %lld nheadoffs %lld " + LOGDEB2(("CirCache::create: rewriting header with " + "maxsize %s oheadoffs %s nheadoffs %s " "npadsize %d unient %d\n", - m_d->m_maxsize, m_d->m_oheadoffs, m_d->m_nheadoffs, + lltodecstr(m_d->m_maxsize).c_str(), + lltodecstr(m_d->m_oheadoffs).c_str(), + lltodecstr(m_d->m_nheadoffs).c_str(), m_d->m_npadsize, int(m_d->m_uniquentries))); return m_d->writefirstblock(); } diff --git a/src/utils/smallut.cpp b/src/utils/smallut.cpp index 8d814da5..ed729256 100644 --- a/src/utils/smallut.cpp +++ b/src/utils/smallut.cpp @@ -633,7 +633,6 @@ inline static void ullcopyreverse(const char *rbuf, string& buf, int idx) for (int i = idx - 1; i >= 0; i--) { buf.push_back(rbuf[i]); } - buf.push_back(0); } void ulltodecstr(unsigned long long val, string& buf) @@ -691,7 +690,6 @@ string ulltodecstr(unsigned long long val) // Convert byte count into unit (KB/MB...) appropriate for display string displayableBytes(off_t size) { - char sizebuf[50]; const char *unit; double roundable = 0; @@ -709,8 +707,7 @@ string displayableBytes(off_t size) roundable = double(size) / 1E9; } size = off_t(round(roundable)); - sprintf(sizebuf, "%lld" "%s", (long long)size, unit); - return string(sizebuf); + return lltodecstr(size).append(unit); } string breakIntoLines(const string& in, unsigned int ll,