]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal: fix definition of _OBJECT_COMPRESSED_MAX
authorLennart Poettering <lennart@poettering.net>
Mon, 1 Jun 2020 22:26:34 +0000 (00:26 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 25 Jun 2020 13:00:37 +0000 (15:00 +0200)
The object flags field is a bitmask, hence don't sloppily define
_OBJECT_COMPRESSED_MAX as one mor than the previous flag. That worked OK
as long as we only had two flags, but will fall apart as soon as we have
three. Let's fix this.

(It's kinda sloppy how the string table is built here, as it will be
quite sparse as soon as we have more enum entries, but let's keep it for
now.)

src/journal/compress.c
src/journal/journal-def.h

index 2bbfc7644aed53c58d8d57bda085de47f5b03c33..6e3d350c6fb1119fe93a49fb449edcb7d865115a 100644 (file)
@@ -57,8 +57,10 @@ static int zstd_ret_to_errno(size_t ret) {
 #define ALIGN_8(l) ALIGN_TO(l, sizeof(size_t))
 
 static const char* const object_compressed_table[_OBJECT_COMPRESSED_MAX] = {
-        [OBJECT_COMPRESSED_XZ] = "XZ",
-        [OBJECT_COMPRESSED_LZ4] = "LZ4",
+        [OBJECT_COMPRESSED_XZ]   = "XZ",
+        [OBJECT_COMPRESSED_LZ4]  = "LZ4",
+        /* If we add too many more entries here, it's going to grow quite large (and be mostly sparse), since
+         * the array key is actually a bitmask, not a plain enum */
 };
 
 DEFINE_STRING_TABLE_LOOKUP(object_compressed, int);
index ff4e71a31ba44fef6891a2a304cdf7db8101867d..3f981e4e3994ab500c0d64bce73a6b06ba41d7ee 100644 (file)
@@ -44,12 +44,12 @@ typedef enum ObjectType {
 
 /* Object flags */
 enum {
-        OBJECT_COMPRESSED_XZ = 1 << 0,
-        OBJECT_COMPRESSED_LZ4 = 1 << 1,
-        _OBJECT_COMPRESSED_MAX
+        OBJECT_COMPRESSED_XZ   = 1 << 0,
+        OBJECT_COMPRESSED_LZ4  = 1 << 1,
+        OBJECT_COMPRESSION_MASK = (OBJECT_COMPRESSED_XZ | OBJECT_COMPRESSED_LZ4),
+        _OBJECT_COMPRESSED_MAX = OBJECT_COMPRESSION_MASK,
 };
 
-#define OBJECT_COMPRESSION_MASK (OBJECT_COMPRESSED_XZ | OBJECT_COMPRESSED_LZ4)
 
 struct ObjectHeader {
         uint8_t type;
@@ -145,8 +145,8 @@ enum {
 
 /* Header flags */
 enum {
-        HEADER_INCOMPATIBLE_COMPRESSED_XZ = 1 << 0,
-        HEADER_INCOMPATIBLE_COMPRESSED_LZ4 = 1 << 1,
+        HEADER_INCOMPATIBLE_COMPRESSED_XZ   = 1 << 0,
+        HEADER_INCOMPATIBLE_COMPRESSED_LZ4  = 1 << 1,
 };
 
 #define HEADER_INCOMPATIBLE_ANY (HEADER_INCOMPATIBLE_COMPRESSED_XZ|HEADER_INCOMPATIBLE_COMPRESSED_LZ4)
@@ -162,7 +162,7 @@ enum {
 #endif
 
 enum {
-        HEADER_COMPATIBLE_SEALED = 1
+        HEADER_COMPATIBLE_SEALED = 1 << 0,
 };
 
 #define HEADER_COMPATIBLE_ANY HEADER_COMPATIBLE_SEALED