GIB: Even more bugfixes.

This commit is contained in:
Brian Koropoff 2003-01-31 05:22:20 +00:00
parent 92fc8109e6
commit b0e6f46b7e
3 changed files with 18 additions and 12 deletions

View file

@ -353,13 +353,13 @@ GIB_Slice_f (void)
{
dstring_t *ret;
int start, end, len;
if (GIB_Argc() != 4)
GIB_USAGE ("string start end");
if (GIB_Argc() < 3 || GIB_Argc() > 4)
GIB_USAGE ("string start [end]");
else {
len = strlen (GIB_Argv(1));
start = atoi (GIB_Argv(2));
end = atoi (GIB_Argv(3));
if (end < 1)
end = *GIB_Argv(3) ? atoi (GIB_Argv(3)) : len;
if (end < 0)
end += len;
else if (end > len)
end = len;

View file

@ -86,16 +86,19 @@ GIB_Execute_Split_Array (cbuf_t *cbuf)
if (str[i] == '[') {
str[i] = 0;
start = atoi (str+i+1);
if ((c = strchr (str+i+1, ':')))
end = atoi (c+1);
else
end = start;
if ((c = strchr (str+i+1, ':'))) {
if (c[1] != ']')
end = atoi (c+1);
else
end = (int) ((unsigned int)~0>>1);
} else
end = start+1;
break;
}
cbuf->args->argc--;
if (!(var = GIB_Var_Get_Complex (&GIB_DATA(cbuf)->locals, &GIB_DATA(cbuf)->globals, str, &i, false)))
return;
if (end < 1)
if (end < 0)
end += var->size;
else if (end > var->size)
end = var->size;

View file

@ -307,7 +307,8 @@ DONE:
*embedded = embs;
return nodes;
ERROR:
GIB_Tree_Free_Recursive (nodes);
if (nodes)
GIB_Tree_Free_Recursive (nodes);
gib_parse_error = true;
return 0;
}
@ -471,7 +472,8 @@ GIB_Parse_Lines (const char *program, unsigned int flags)
}
return lines;
ERROR:
GIB_Tree_Free_Recursive (lines);
if (lines)
GIB_Tree_Free_Recursive (lines);
return 0;
}
@ -569,6 +571,7 @@ GIB_Parse_Embedded (const char *program, unsigned int flags, gib_tree_t **embedd
return lines;
ERROR:
gib_parse_error = true;
GIB_Tree_Free_Recursive (lines);
if (lines)
GIB_Tree_Free_Recursive (lines);
return 0;
}