]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- coding style 830/head
authorArvin Schnell <aschnell@suse.de>
Thu, 10 Aug 2023 07:34:05 +0000 (09:34 +0200)
committerArvin Schnell <aschnell@suse.de>
Thu, 10 Aug 2023 07:34:05 +0000 (09:34 +0200)
client/mksubvolume.cc
snapper/FileUtils.cc

index 792ee7517ef41d0b84601a567cce82e17b9ecf3d..36e29572687e966b9e57387dbdfe64a092c0b86d 100644 (file)
@@ -20,7 +20,7 @@
  */
 
 
-#include <string.h>
+#include <cstring>
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
index 9da572f30d029ba05ef5a37dc4a86e52abb6f333..aa6bc165cdee3418c2cbd1cc9234f5d107d78a79 100644 (file)
@@ -405,23 +405,27 @@ namespace snapper
        static const char letters[] = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
            "0123456789";
 
+       const size_t num_letters = strlen(letters);
+
        static uint64_t value;
 
        struct timeval tv;
        gettimeofday(&tv, NULL);
        value += ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec;
 
-       unsigned int attempts = 62 * 62 * 62;
+       unsigned int attempts = num_letters * num_letters * num_letters;
 
        string::size_type length = name.size();
 
+       assert(length >= 6);
+
        for (unsigned int count = 0; count < attempts; value += 7777, ++count)
        {
            uint64_t v = value;
            for (string::size_type i = length - 6; i < length; ++i)
            {
-               name[i] = letters[v % 62];
-               v /= 62;
+               name[i] = letters[v % num_letters];
+               v /= num_letters;
            }
 
            int fd = open(name, O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC, S_IRUSR | S_IWUSR);