diff --git a/src/xpdev/ini_file.c b/src/xpdev/ini_file.c index 7e5d5a9a0ee8dabf987bb9d46f97a8898e3ac555..0316088b6f8c35b62893d87a705b23a6863612ac 100644 --- a/src/xpdev/ini_file.c +++ b/src/xpdev/ini_file.c @@ -453,7 +453,7 @@ bool iniRemoveSectionFast(str_list_t list, const char* section) if(list[i]==NULL) /* not found */ return(false); do { - strListFastDelete(list,i); + strListFastDelete(list,i, /* count: */1); } while(list[i]!=NULL && *list[i]!=INI_OPEN_SECTION_CHAR); return(true); diff --git a/src/xpdev/str_list.c b/src/xpdev/str_list.c index dcb92dc28d3d5a4bd0e6593015dcaf8eb0ea4abc..d28aa297ea5adbe78daff30e558f89a27bb9ff19 100644 --- a/src/xpdev/str_list.c +++ b/src/xpdev/str_list.c @@ -152,25 +152,23 @@ char* strListRemove(str_list_t* list, size_t index) } // Remove without realloc -char* strListFastRemove(str_list_t list, size_t index) +bool strListFastRemove(str_list_t list, size_t index, size_t count) { - char* str; size_t i; - size_t count; + size_t total; - count = strListCount(list); + total = strListCount(list); - if(index == STR_LIST_LAST_INDEX && count) - index = count-1; + if(index == STR_LIST_LAST_INDEX && total) + index = total-1; - if(index >= count) /* invalid index, do nothing */ - return NULL; + if(index + count > total) /* invalid index, do nothing */ + return false; - str = list[index]; - for(i = index; i < count; i++) - list[i] = list[i + 1]; + for(i = index; i <= total - count; ++i) + list[i] = list[i + count]; - return str; + return true; } bool strListDelete(str_list_t* list, size_t index) @@ -185,16 +183,18 @@ bool strListDelete(str_list_t* list, size_t index) return(true); } -bool strListFastDelete(str_list_t list, size_t index) +bool strListFastDelete(str_list_t list, size_t index, size_t count) { - char* str; + size_t i; - if((str=strListFastRemove(list, index))==NULL) - return(false); + for(i = 0; i < count; ++i) + if(list[index + i] == NULL) + return false; - free(str); + for(i = 0; i < count; ++i) + free(list[index + i]); - return(true); + return strListFastRemove(list, index, count); } char* strListReplace(const str_list_t list, size_t index, const char* str) @@ -917,7 +917,7 @@ int strListFastDeleteBlanks(str_list_t list) for(i = 0; list[i] != NULL; ) { if(list[i][0] == '\0') - strListFastDelete(list, i); + strListFastDelete(list, i, /* count: */1); else i++; } diff --git a/src/xpdev/str_list.h b/src/xpdev/str_list.h index 7baee4c9bc822aa74dd022d959f97845ef8f4180..f601cc8245b48d6ef6b73ac7e2e488b788c9e0f9 100644 --- a/src/xpdev/str_list.h +++ b/src/xpdev/str_list.h @@ -73,11 +73,11 @@ DLLEXPORT char* strListInsertFormat(str_list_t* list, size_t index, const char /* Remove a string at a specific index */ DLLEXPORT char* strListRemove(str_list_t*, size_t index); -DLLEXPORT char* strListFastRemove(str_list_t, size_t index); +DLLEXPORT bool strListFastRemove(str_list_t, size_t index, size_t count); /* Remove and free a string at a specific index */ DLLEXPORT bool strListDelete(str_list_t*, size_t index); -DLLEXPORT bool strListFastDelete(str_list_t, size_t index); +DLLEXPORT bool strListFastDelete(str_list_t, size_t index, size_t count); /* Replace a string at a specific index */ DLLEXPORT char* strListReplace(const str_list_t, size_t index, const char* str);