diff --git a/libs/gib/gib_builtin.c b/libs/gib/gib_builtin.c index 43b720048..fa972cb57 100644 --- a/libs/gib/gib_builtin.c +++ b/libs/gib/gib_builtin.c @@ -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; diff --git a/libs/gib/gib_execute.c b/libs/gib/gib_execute.c index 70672be37..e2980a950 100644 --- a/libs/gib/gib_execute.c +++ b/libs/gib/gib_execute.c @@ -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; diff --git a/libs/gib/gib_parse.c b/libs/gib/gib_parse.c index 892ae08c7..c20ee8f7e 100644 --- a/libs/gib/gib_parse.c +++ b/libs/gib/gib_parse.c @@ -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; }