X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=typedef.c;h=731ab7f2ff1ff545f7cd21fca770957aa13717e3;hb=b76ffe8304dd59cf53c35f53b4b42f5a2fbac2bf;hp=d9be47817df95489a427cc26b268afa6496ca1d3;hpb=7849f8c597dce0e380a34b8b3a31a10ee5b0530d;p=xonotic%2Fgmqcc.git diff --git a/typedef.c b/typedef.c index d9be478..731ab7f 100644 --- a/typedef.c +++ b/typedef.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 + * Copyright (C) 2012 * Dale Weiler * * Permission is hereby granted, free of charge, to any person obtaining a copy of @@ -49,29 +49,35 @@ void typedef_clear() { } } -int typedef_add(struct lex_file *file, const char *from, const char *to) { +int typedef_add(lex_file *file, const char *from, const char *to) { unsigned int hash = typedef_hash(to); typedef_node *find = typedef_table[hash]; - + if (find) return error(file, ERROR_PARSE, "typedef for %s already exists or conflicts\n", to); - + /* check if the type exists first */ if (strncmp(from, "float", sizeof("float")) == 0 || strncmp(from, "vector", sizeof("vector")) == 0 || strncmp(from, "string", sizeof("string")) == 0 || strncmp(from, "entity", sizeof("entity")) == 0 || strncmp(from, "void", sizeof("void")) == 0) { - - typedef_table[hash] = mem_a(sizeof(typedef_node)); - typedef_table[hash]->name = util_strdup(from); + + typedef_table[hash] = mem_a(sizeof(typedef_node)); + if (typedef_table[hash]) + typedef_table[hash]->name = util_strdup(from); + else + return error(file, ERROR_PARSE, "ran out of resources for typedef %s\n", to); return -100; } else { /* search the typedefs for it (typedef-a-typedef?) */ - typedef_node *find = typedef_table[typedef_hash(from)]; + find = typedef_table[typedef_hash(from)]; if (find) { - typedef_table[hash] = mem_a(sizeof(typedef_node)); - typedef_table[hash]->name = util_strdup(find->name); + typedef_table[hash] = mem_a(sizeof(typedef_node)); + if (typedef_table[hash]) + typedef_table[hash]->name = util_strdup(find->name); + else + return error(file, ERROR_PARSE, "ran out of resources for typedef %s\n", to); return -100; } }