Compilation fixes

This commit is contained in:
CeRiAl 2012-07-04 23:34:24 +02:00
parent cd1a34c253
commit 9dfe447e6d
2 changed files with 12 additions and 11 deletions

View file

@ -50,7 +50,6 @@
typedef struct Section Section; typedef struct Section Section;
typedef struct ParseState ParseState; typedef struct ParseState ParseState;
typedef enum ConvertMode ConvertMode;
struct Settings { struct Settings {
Section *sections; Section *sections;
@ -74,6 +73,8 @@ enum ConvertMode {
CONVERT_MODE_DOUBLE, CONVERT_MODE_DOUBLE,
}; };
typedef enum ConvertMode ConvertMode;
static void trim_str(const char *str, char *out_buf); static void trim_str(const char *str, char *out_buf);
static int parse_str(Settings *settings, char *str, ParseState *parse_state); static int parse_str(Settings *settings, char *str, ParseState *parse_state);
static int is_blank_char(char c); static int is_blank_char(char c);
@ -95,7 +96,7 @@ Settings * settings_new()
{ {
Settings *settings; Settings *settings;
settings = malloc(sizeof(Settings)); settings = (Settings*)malloc(sizeof(Settings));
if (settings == NULL) { if (settings == NULL) {
return NULL; return NULL;
} }
@ -257,7 +258,7 @@ int settings_set(Settings *settings, const char *section, const char *key, const
s = get_section(settings->sections, settings->section_count, section); s = get_section(settings->sections, settings->section_count, section);
if (s == NULL) { if (s == NULL) {
/* The section is not created---create it */ /* The section is not created---create it */
s = realloc(settings->sections, (settings->section_count + 1) * sizeof(Section)); s = (Section*)realloc(settings->sections, (settings->section_count + 1) * sizeof(Section));
if (s == NULL) { if (s == NULL) {
return 0; return 0;
} }
@ -269,7 +270,7 @@ int settings_set(Settings *settings, const char *section, const char *key, const
free(s); free(s);
return 0; return 0;
} }
s->name = malloc((strlen(section) + 1) * sizeof(char)); s->name = (char*)malloc((strlen(section) + 1) * sizeof(char));
if (s->name == NULL) { if (s->name == NULL) {
sm_delete(s->map); sm_delete(s->map);
free(s); free(s);

View file

@ -61,12 +61,12 @@ StrMap * sm_new(unsigned int capacity)
{ {
StrMap *map; StrMap *map;
map = malloc(sizeof(StrMap)); map = (StrMap*)malloc(sizeof(StrMap));
if (map == NULL) { if (map == NULL) {
return NULL; return NULL;
} }
map->count = capacity; map->count = capacity;
map->buckets = malloc(map->count * sizeof(Bucket)); map->buckets = (Bucket*)malloc(map->count * sizeof(Bucket));
if (map->buckets == NULL) { if (map->buckets == NULL) {
free(map); free(map);
return NULL; return NULL;
@ -187,7 +187,7 @@ int sm_put(StrMap *map, const char *key, const char *value)
/* If the new value is larger than the old value, re-allocate /* If the new value is larger than the old value, re-allocate
* space for the new larger value. * space for the new larger value.
*/ */
tmp_value = realloc(pair->value, (value_len + 1) * sizeof(char)); tmp_value = (char*)realloc(pair->value, (value_len + 1) * sizeof(char));
if (tmp_value == NULL) { if (tmp_value == NULL) {
return 0; return 0;
} }
@ -198,11 +198,11 @@ int sm_put(StrMap *map, const char *key, const char *value)
return 1; return 1;
} }
/* Allocate space for a new key and value */ /* Allocate space for a new key and value */
new_key = malloc((key_len + 1) * sizeof(char)); new_key = (char*)malloc((key_len + 1) * sizeof(char));
if (new_key == NULL) { if (new_key == NULL) {
return 0; return 0;
} }
new_value = malloc((value_len + 1) * sizeof(char)); new_value = (char*)malloc((value_len + 1) * sizeof(char));
if (new_value == NULL) { if (new_value == NULL) {
free(new_key); free(new_key);
return 0; return 0;
@ -212,7 +212,7 @@ int sm_put(StrMap *map, const char *key, const char *value)
/* The bucket is empty, lazily allocate space for a single /* The bucket is empty, lazily allocate space for a single
* key-value pair. * key-value pair.
*/ */
bucket->pairs = malloc(sizeof(Pair)); bucket->pairs = (Pair*)malloc(sizeof(Pair));
if (bucket->pairs == NULL) { if (bucket->pairs == NULL) {
free(new_key); free(new_key);
free(new_value); free(new_value);
@ -224,7 +224,7 @@ int sm_put(StrMap *map, const char *key, const char *value)
/* The bucket wasn't empty but no pair existed that matches the provided /* The bucket wasn't empty but no pair existed that matches the provided
* key, so create a new key-value pair. * key, so create a new key-value pair.
*/ */
tmp_pairs = realloc(bucket->pairs, (bucket->count + 1) * sizeof(Pair)); tmp_pairs = (Pair*)realloc(bucket->pairs, (bucket->count + 1) * sizeof(Pair));
if (tmp_pairs == NULL) { if (tmp_pairs == NULL) {
free(new_key); free(new_key);
free(new_value); free(new_value);