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

View file

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

View file

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