unaligned int access - fix.

SVN revision: 23702
This commit is contained in:
Carsten Haitzler 2006-07-03 20:15:54 +00:00
parent 4cedfd95b9
commit f1316fa8e9
1 changed files with 17 additions and 13 deletions

View File

@ -562,18 +562,22 @@ eet_open(const char *file, Eet_File_Mode mode)
ef->data_size = file_stat.st_size; ef->data_size = file_stat.st_size;
ef->data = mmap(NULL, ef->data_size, PROT_READ, MAP_SHARED, fileno(ef->fp), 0); ef->data = mmap(NULL, ef->data_size, PROT_READ, MAP_SHARED, fileno(ef->fp), 0);
if (eet_test_close(ef->data == (void*) -1 || ef->data == NULL, ef)) if (eet_test_close((ef->data == (void *)-1) || (ef->data == NULL), ef))
return NULL; return NULL;
/* build header table if read mode */ /* build header table if read mode */
/* geat header */ /* geat header */
index += sizeof (int); index += sizeof(int);
if (eet_test_close((int) ntohl (*((int*) ef->data)) != EET_MAGIC_FILE, ef)) if (eet_test_close((int)ntohl(*((int *)ef->data)) != EET_MAGIC_FILE, ef))
return NULL; return NULL;
#define EXTRACT_INT(Value, Pointer, Index) \ #define EXTRACT_INT(Value, Pointer, Index) \
Value = ntohl (*((int*)(Pointer + Index))); \ { \
Index += sizeof(int); int tmp; \
memcpy(&tmp, Pointer + Index, sizeof(int)); \
Value = ntohl(tmp); \
Index += sizeof(int); \
}
/* get entries count and byte count */ /* get entries count and byte count */
EXTRACT_INT(num_entries, ef->data, index); EXTRACT_INT(num_entries, ef->data, index);
@ -621,7 +625,7 @@ eet_open(const char *file, Eet_File_Mode mode)
int hash; int hash;
int k; int k;
#define HEADER_SIZE sizeof (uint32_t) * 5 #define HEADER_SIZE (sizeof(int) * 5)
/* out directory block is inconsistent - we have oveerun our */ /* out directory block is inconsistent - we have oveerun our */
/* dynamic block buffer before we finished scanning dir entries */ /* dynamic block buffer before we finished scanning dir entries */
@ -630,7 +634,7 @@ eet_open(const char *file, Eet_File_Mode mode)
/* allocate all the ram needed for this stored node accounting */ /* allocate all the ram needed for this stored node accounting */
efn = malloc (sizeof(Eet_File_Node)); efn = malloc (sizeof(Eet_File_Node));
if (eet_test_close (!efn, ef)) if (eet_test_close(!efn, ef))
return NULL; return NULL;
/* get entrie header */ /* get entrie header */
@ -662,14 +666,14 @@ eet_open(const char *file, Eet_File_Mode mode)
} }
/* This code is useless if we dont want backward compatibility */ /* This code is useless if we dont want backward compatibility */
for (k = name_size; k > 0 && ((uint8_t)*(p + HEADER_SIZE + k)) != 0; --k) for (k = name_size; k > 0 && ((uint8_t) * (p + HEADER_SIZE + k)) != 0; --k)
; ;
efn->free_name = ((uint8_t)*(p + HEADER_SIZE + k)) != 0; efn->free_name = ((uint8_t) * (p + HEADER_SIZE + k)) != 0;
if (efn->free_name) if (efn->free_name)
{ {
efn->name = malloc(sizeof (char) * name_size + 1); efn->name = malloc(sizeof(char) * name_size + 1);
if (eet_test_close(efn->name == NULL, ef)) if (eet_test_close(efn->name == NULL, ef))
{ {
free (efn); free (efn);
@ -683,7 +687,7 @@ eet_open(const char *file, Eet_File_Mode mode)
} }
else else
/* The only really usefull peace of code for efn->name (no backward compatibility) */ /* The only really usefull peace of code for efn->name (no backward compatibility) */
efn->name = (char*) ((uint8_t*)(p + HEADER_SIZE)); efn->name = (char*)((uint8_t*)(p + HEADER_SIZE));
/* get hash bucket it should go in */ /* get hash bucket it should go in */
hash = eet_hash_gen(efn->name, ef->header->directory->size); hash = eet_hash_gen(efn->name, ef->header->directory->size);
@ -698,7 +702,7 @@ eet_open(const char *file, Eet_File_Mode mode)
{ {
data = malloc(efn->size); data = malloc(efn->size);
if (data) if (data)
memcpy (data, ef->data + efn->offset, efn->size); memcpy(data, ef->data + efn->offset, efn->size);
efn->data = data; efn->data = data;
} }
/* advance */ /* advance */