mirror of
https://gitee.com/apaki/unicstl.git
synced 2025-07-04 16:06:53 +08:00
修改变量
This commit is contained in:
parent
e5ea2efe84
commit
65a60df00b
28
src/list.c
28
src/list.c
@ -209,6 +209,7 @@ struct _list* list_slice(struct _list* self, int start, int end, int step)
|
|||||||
assert(self != NULL);
|
assert(self != NULL);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
bool contains_last_obj = false;
|
bool contains_last_obj = false;
|
||||||
|
int size = (int)self->size(self);
|
||||||
if (step == 0)
|
if (step == 0)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -223,15 +224,14 @@ struct _list* list_slice(struct _list* self, int start, int end, int step)
|
|||||||
|
|
||||||
if (end == LIST_UNLIMITED)
|
if (end == LIST_UNLIMITED)
|
||||||
{
|
{
|
||||||
end = (int)self->size(self);
|
end = size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (start == LIST_UNLIMITED)
|
if (start == LIST_UNLIMITED)
|
||||||
{
|
{
|
||||||
start = (int)self->size(self) - 1;
|
start = size - 1;
|
||||||
contains_last_obj = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (end == LIST_UNLIMITED)
|
if (end == LIST_UNLIMITED)
|
||||||
@ -243,33 +243,33 @@ struct _list* list_slice(struct _list* self, int start, int end, int step)
|
|||||||
|
|
||||||
if (start < 0)
|
if (start < 0)
|
||||||
{
|
{
|
||||||
if (start < -(int)self->size(self))
|
if (start < -size)
|
||||||
{
|
{
|
||||||
start = -(int)self->size(self);
|
start = -size;
|
||||||
}
|
}
|
||||||
start += (int)self->size(self);
|
start += size;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (start > (int)self->size(self))
|
if (start > size)
|
||||||
{
|
{
|
||||||
start = (int)self->size(self);
|
start = size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (end < 0)
|
if (end < 0)
|
||||||
{
|
{
|
||||||
if (end < -(int)self->size(self))
|
if (end < -size)
|
||||||
{
|
{
|
||||||
end = -(int)self->size(self);
|
end = -size;
|
||||||
}
|
}
|
||||||
end += (int)self->size(self);
|
end += size;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (end > (int)self->size(self))
|
if (end > size)
|
||||||
{
|
{
|
||||||
end = (int)self->size(self);
|
end = size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -285,7 +285,7 @@ struct _list* list_slice(struct _list* self, int start, int end, int step)
|
|||||||
list->compare = self->compare;
|
list->compare = self->compare;
|
||||||
list->print_obj = self->print_obj;
|
list->print_obj = self->print_obj;
|
||||||
|
|
||||||
if (capicity == 0 || start > self->size(self) || end > self->size(self))
|
if (capicity == 0 || start > size || end > size)
|
||||||
{
|
{
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user