HuntnGather

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 18  →  ?path2? @ 19
/trunk/HuntnGather/Gather/StringStack.c
@@ -30,8 +30,8 @@
* Creates a new stringStack with a given size.
*/
stringStack* stringStackCreate(unsigned int size) {
stringStack *s = malloc(sizeof(stringStack));
if ((s->store = malloc(size * sizeof(char *))) == NULL)
stringStack *s = (stringStack*)malloc(sizeof(stringStack));
if ((s->store = (char**)malloc(size * sizeof(*s->store))) == NULL)
return NULL;
s->size = size;
s->top = 0;
@@ -52,8 +52,8 @@
*/
void stringStackPush(stringStack *s, char *e) {
if (s->top > s->size - 1)
s->store = realloc(s->store, ++s->size * sizeof(char *));
s->store[s->top] = malloc((strlen(e) + 1) * sizeof(char));
s->store = (char**)realloc(s->store, ++s->size * sizeof(*s->store));
s->store[s->top] = (char*)malloc((strlen(e) + 1) * sizeof(*s->store[s->top]));
strncpy(s->store[s->top], e, strlen(e) + 1);
++s->top;
}
@@ -67,7 +67,7 @@
if (stringStackIsEmpty(s))
return NULL;
--s->top;
e = (char *)malloc((strlen(s->store[s->top]) + 1) * sizeof(char *));
e = (char *)malloc((strlen(s->store[s->top]) + 1) * sizeof(*e));
strncpy(e, s->store[s->top], strlen(s->store[s->top]) + 1);
free(s->store[s->top]);
return e;