Sanitize saltCharacter()

- the array of salt chars should be const, it's read-only
 - the array of salt chars should be static, since it is
   initialized to a constant value anyway and can live beyond
   this one function
 - sizeof(char) is 1 by the standard, so remove the weird
   array-size calculation: here saltCharacters has type
   (const) char[63], and its sizeof() is 63
wilder-5.24
Adriaan de Groot 6 years ago committed by Devin Lin
parent 0056b709a3
commit c9ab7d4769
  1. 9
      kcms/users/src/user.cpp

@ -175,12 +175,11 @@ void User::setPath(const QDBusObjectPath &path) {
static char
saltCharacter() {
char saltCharacters[] = "ABCDEFGHIJKLMNOPQRSTUVXYZ"
"abcdefghijklmnopqrstuvxyz"
"./0123456789";
static const char saltCharacters[] = "ABCDEFGHIJKLMNOPQRSTUVXYZ"
"abcdefghijklmnopqrstuvxyz"
"./0123456789";
const quint32 index =
QRandomGenerator::system()->bounded(0u, (sizeof(saltCharacters)/sizeof(*saltCharacters)));
const quint32 index = QRandomGenerator::system()->bounded(0u, sizeof(saltCharacters));
return saltCharacters[index];
}

Loading…
Cancel
Save