Permalink
Browse files

pstore: Fix '-Wcast-align' warning

Clang emits a warning for PSTORE_MAGIC due to '-Wcast-align' and
the casting of a 'char *' into a 'uint64_t *'. Fix it by changing
the type of the 'magic' field in the disk format from a 'uint64_t'
into an eight character array.

Signed-off-by: Jussi Virtanen <jussi.k.virtanen@gmail.com>
  • Loading branch information...
1 parent 0e5cb03 commit 3d512f25a05a2337be6f6c61e957310c51558e32 @jvirtanen jvirtanen committed Feb 22, 2012
Showing with 9 additions and 8 deletions.
  1. +5 −7 header.c
  2. +4 −1 include/pstore/disk-format.h
View
@@ -7,10 +7,7 @@
#include <inttypes.h>
#include <stdlib.h>
-
-static const char *pstore_magic = "PSTORE02";
-
-#define PSTORE_MAGIC (*(uint64_t *)pstore_magic)
+#include <string.h>
struct pstore_header *pstore_header_new(void)
{
@@ -60,8 +57,8 @@ struct pstore_header *pstore_header_read(int fd)
read_or_die(fd, &f_header, sizeof(f_header));
- if (f_header.magic != PSTORE_MAGIC)
- die("bad magic: %" PRIX64, f_header.magic);
+ if (memcmp(f_header.magic, PSTORE_MAGIC, PSTORE_MAGIC_LEN) != 0)
+ die("bad magic");
self = pstore_header_new();
@@ -100,10 +97,11 @@ void pstore_header_write(struct pstore_header *self, int fd)
seek_or_die(fd, -(sizeof(f_header) + sizeof(f_index) + size), SEEK_CUR);
f_header = (struct pstore_file_header) {
- .magic = PSTORE_MAGIC,
.n_index_offset = PSTORE_END_OF_CHAIN,
.t_index_offset = t_index_off,
};
+ strncpy(f_header.magic, PSTORE_MAGIC, PSTORE_MAGIC_LEN);
+
write_or_die(fd, &f_header, sizeof(f_header));
f_index = (struct pstore_file_table_idx) {
@@ -7,8 +7,11 @@
* This header file contains on-disk data structures of pstore files.
*/
+#define PSTORE_MAGIC "PSTORE02"
+#define PSTORE_MAGIC_LEN 8
+
struct pstore_file_header {
- uint64_t magic;
+ char magic[PSTORE_MAGIC_LEN];
uint64_t n_index_offset;
uint64_t t_index_offset;
};

0 comments on commit 3d512f2

Please sign in to comment.