From 5ddf977b16343d0b79d169e3e822b7f6f62e2488 Mon Sep 17 00:00:00 2001 From: psychon Date: Mon, 12 May 2008 19:35:15 +0000 Subject: [PATCH] Fix CString::RandomString() to not insert NULL bytes in its result sizeof() also includes the trailing NULL byte and thus that character was chosen sometimes, too. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1052 726aef4b-f618-498e-8847-2d620e286838 --- String.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/String.cpp b/String.cpp index 56d144c8..8cc1ec0e 100644 --- a/String.cpp +++ b/String.cpp @@ -665,7 +665,8 @@ CString CString::RandomString(unsigned int uLength) { const char chars[] = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789!?.,:;/*-+_()"; - const size_t len = sizeof(chars) / sizeof(char); + // -1 because sizeof() includes the trailing '\0' byte + const size_t len = sizeof(chars) / sizeof(chars[0]) - 1; size_t p; CString sRet;