Index: client/attribute.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/attribute.c,v retrieving revision 1.11 diff -u -r1.11 attribute.c --- client/attribute.c 2002/05/25 17:44:05 1.11 +++ client/attribute.c 2002/06/07 08:46:47 @@ -11,7 +11,7 @@ #include "attribute.h" -#define ATTRIBUTE_LOG_LEVEL LOG_DEBUG +#define ATTRIBUTE_LOG_LEVEL LOG_NORMAL static struct hash_table *attribute_hash = NULL; @@ -44,6 +44,8 @@ void attribute_init() { assert(attribute_hash == NULL); + /* If there is padding memcmp can't be used. */ + assert(sizeof(struct attr_key) == 4 * sizeof(int)); attribute_hash = hash_new(attr_hash_val_fn, attr_hash_cmp_fn); } @@ -259,7 +261,7 @@ if (data_length != 0) { pvalue = fc_malloc(data_length + sizeof(int)); ((int *) pvalue)[0] = data_length; - memcpy((char *)pvalue + sizeof(int), data, data_length); + memcpy(ADD_TO_POINTER(pvalue, sizeof(int)), data, data_length); } if (hash_key_exists(attribute_hash, pkey)) { @@ -301,6 +303,21 @@ if (!pvalue) { freelog(ATTRIBUTE_LOG_LEVEL, " not found"); + { + int i; + + for (i = 0; i < hash_num_entries(attribute_hash); i++) { + const struct attr_key *pkey = hash_key_by_number(attribute_hash, i); + + pvalue = hash_lookup_data(attribute_hash, pkey); + assert(pvalue); + length = ((int *) pvalue)[0]; + + freelog(LOG_NORMAL, + " [%d], key=(key=%d, id=%d, x=%d, y=%d) value_len=%d", i, + pkey->key, pkey->id, pkey->x, pkey->y, length); + } + } return 0; } @@ -320,7 +337,7 @@ exit(EXIT_FAILURE); } - memcpy(data, (char *)pvalue + sizeof(int), length); + memcpy(data, ADD_TO_POINTER(pvalue, sizeof(int)), length); freelog(ATTRIBUTE_LOG_LEVEL, " found length=%d", length); return length;