Skip to content

Commit

Permalink
pstore: Fix '-Wcast-align' warning
Browse files Browse the repository at this point in the history
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
jvirtanen committed Feb 22, 2012
1 parent 0e5cb03 commit 3d512f2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
12 changes: 5 additions & 7 deletions header.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@


#include <inttypes.h> #include <inttypes.h>
#include <stdlib.h> #include <stdlib.h>

#include <string.h>
static const char *pstore_magic = "PSTORE02";

#define PSTORE_MAGIC (*(uint64_t *)pstore_magic)


struct pstore_header *pstore_header_new(void) struct pstore_header *pstore_header_new(void)
{ {
Expand Down Expand Up @@ -60,8 +57,8 @@ struct pstore_header *pstore_header_read(int fd)


read_or_die(fd, &f_header, sizeof(f_header)); read_or_die(fd, &f_header, sizeof(f_header));


if (f_header.magic != PSTORE_MAGIC) if (memcmp(f_header.magic, PSTORE_MAGIC, PSTORE_MAGIC_LEN) != 0)
die("bad magic: %" PRIX64, f_header.magic); die("bad magic");


self = pstore_header_new(); self = pstore_header_new();


Expand Down Expand Up @@ -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); seek_or_die(fd, -(sizeof(f_header) + sizeof(f_index) + size), SEEK_CUR);


f_header = (struct pstore_file_header) { f_header = (struct pstore_file_header) {
.magic = PSTORE_MAGIC,
.n_index_offset = PSTORE_END_OF_CHAIN, .n_index_offset = PSTORE_END_OF_CHAIN,
.t_index_offset = t_index_off, .t_index_offset = t_index_off,
}; };
strncpy(f_header.magic, PSTORE_MAGIC, PSTORE_MAGIC_LEN);

write_or_die(fd, &f_header, sizeof(f_header)); write_or_die(fd, &f_header, sizeof(f_header));


f_index = (struct pstore_file_table_idx) { f_index = (struct pstore_file_table_idx) {
Expand Down
5 changes: 4 additions & 1 deletion include/pstore/disk-format.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
* This header file contains on-disk data structures of pstore files. * This header file contains on-disk data structures of pstore files.
*/ */


#define PSTORE_MAGIC "PSTORE02"
#define PSTORE_MAGIC_LEN 8

struct pstore_file_header { struct pstore_file_header {
uint64_t magic; char magic[PSTORE_MAGIC_LEN];
uint64_t n_index_offset; uint64_t n_index_offset;
uint64_t t_index_offset; uint64_t t_index_offset;
}; };
Expand Down

0 comments on commit 3d512f2

Please sign in to comment.