don't crash when removing out of bounds
This commit is contained in:
10
ds.c
10
ds.c
@ -67,7 +67,7 @@ void
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = -1, cur = *ll;; i++, cur = cur->next) {
|
||||
for (i = -1, cur = *ll; cur; i++, cur = cur->next) {
|
||||
if (i + 1 == idx) {
|
||||
if (idx == 0) {
|
||||
rm = cur;
|
||||
@ -86,6 +86,10 @@ void
|
||||
}
|
||||
}
|
||||
|
||||
if (!rm) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
data = rm->data;
|
||||
free(rm);
|
||||
return data;
|
||||
@ -127,6 +131,10 @@ void
|
||||
}
|
||||
}
|
||||
|
||||
if (!rm) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
data = rm->data;
|
||||
free(rm);
|
||||
return data;
|
||||
|
Reference in New Issue
Block a user