From d397cb8ad25d43bbf795674a7ca933b14072cceb Mon Sep 17 00:00:00 2001 From: psychon Date: Tue, 17 Jun 2008 08:25:04 +0000 Subject: [PATCH] Add CZNC::GetVersion() CZNC::GetVersion() returns something like '0.057-r1234'. This also cleans up CZNC::GetTag() a little. A theoretical buffer overflow less and some higher speed is the result. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1097 726aef4b-f618-498e-8847-2d620e286838 --- znc.cpp | 15 +++++++++++++-- znc.h | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/znc.cpp b/znc.cpp index bb5a5d61..b9095cdf 100644 --- a/znc.cpp +++ b/znc.cpp @@ -71,14 +71,25 @@ CZNC::~CZNC() { DeletePidFile(); } +CString CZNC::GetVersion() { + char szBuf[128]; + + snprintf(szBuf, sizeof(szBuf), "%1.3f"VERSION_EXTRA, VERSION); + // If snprintf overflows (which I doubt), we want to be on the safe side + szBuf[sizeof(szBuf) - 1] = '\0'; + + return szBuf; +} + CString CZNC::GetTag(bool bIncludeVersion) { if (!bIncludeVersion) { return "ZNC - http://znc.sourceforge.net"; } char szBuf[128]; - memset(szBuf, 0, 128); - snprintf(szBuf, 127, "ZNC %1.3f"VERSION_EXTRA" - http://znc.sourceforge.net", VERSION); + snprintf(szBuf, sizeof(szBuf), "ZNC %1.3f"VERSION_EXTRA" - http://znc.sourceforge.net", VERSION); + // If snprintf overflows (which I doubt), we want to be on the safe side + szBuf[sizeof(szBuf) - 1] = '\0'; return szBuf; } diff --git a/znc.h b/znc.h index 64602ee7..647c60aa 100644 --- a/znc.h +++ b/znc.h @@ -108,6 +108,7 @@ public: bool WriteConfig(); bool ParseConfig(const CString& sConfig); bool RehashConfig(CString& sError); + static CString GetVersion(); static CString GetTag(bool bIncludeVersion = true); // This returns the path to the .so and to the data dir // which is where static data (webadmin skins) are saved