X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fhelperfuncs.cpp;h=800d147ebf8e4989b22bbe11b1631c7effd2499e;hb=e2b0f3dc9ef4d56c71d7abda13e6139ca092e387;hp=64fadc015dc05c2cde96d25c21e31136b729bebb;hpb=44489ddf7e90413d8f656aea24d74445bab227af;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index 64fadc015..800d147eb 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -6,13 +6,13 @@ * Copyright (C) 2013 Daniel Vassdal * Copyright (C) 2013 Adam * Copyright (C) 2012-2015 Attila Molnar - * Copyright (C) 2012-2014, 2017-2018 Sadie Powell + * Copyright (C) 2012-2014, 2017-2018, 2020 Sadie Powell * Copyright (C) 2012, 2018 Robby * Copyright (C) 2012 ChrisTX * Copyright (C) 2009-2010 Daniel De Graaf - * Copyright (C) 2007, 2010 Craig Edwards * Copyright (C) 2007 Dennis Friis * Copyright (C) 2006-2008 Robin Burchell + * Copyright (C) 2005, 2007, 2010 Craig Edwards * * This file is part of InspIRCd. InspIRCd is free software: you can * redistribute it and/or modify it under the terms of the GNU General Public @@ -35,8 +35,6 @@ #include "inspircd.h" #include "xline.h" -#include "exitcodes.h" -#include /* Find a user record by nickname and return a pointer to it */ User* InspIRCd::FindNick(const std::string &nick) @@ -517,14 +515,12 @@ std::string InspIRCd::TimeString(time_t curtime, const char* format, bool utc) std::string InspIRCd::GenRandomStr(unsigned int length, bool printable) { - char* buf = new char[length]; - GenRandom(buf, length); - std::string rv; - rv.resize(length); - for(size_t i = 0; i < length; i++) - rv[i] = printable ? 0x3F + (buf[i] & 0x3F) : buf[i]; - delete[] buf; - return rv; + std::vector str(length); + GenRandom(&str[0], length); + if (printable) + for (size_t i = 0; i < length; i++) + str[i] = 0x3F + (str[i] & 0x3F); + return std::string(&str[0], str.size()); } // NOTE: this has a slight bias for lower values if max is not a power of 2.