mirror of
https://github.com/gryf/wmaker.git
synced 2026-01-28 02:45:47 +01:00
Fix segfault when SwitchPanelImages = None and user press Alt+tab.
This commit is contained in:
committed by
Carlos R. Mafra
parent
7bf8efef54
commit
527f5f1730
@@ -77,6 +77,9 @@ void WMEmptyArray(WMArray * array)
|
|||||||
|
|
||||||
void WMFreeArray(WMArray * array)
|
void WMFreeArray(WMArray * array)
|
||||||
{
|
{
|
||||||
|
if (array == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
WMEmptyArray(array);
|
WMEmptyArray(array);
|
||||||
wfree(array->items);
|
wfree(array->items);
|
||||||
wfree(array);
|
wfree(array);
|
||||||
@@ -84,11 +87,17 @@ void WMFreeArray(WMArray * array)
|
|||||||
|
|
||||||
int WMGetArrayItemCount(WMArray * array)
|
int WMGetArrayItemCount(WMArray * array)
|
||||||
{
|
{
|
||||||
|
if (array == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
return array->itemCount;
|
return array->itemCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WMAppendArray(WMArray * array, WMArray * other)
|
void WMAppendArray(WMArray * array, WMArray * other)
|
||||||
{
|
{
|
||||||
|
if (array == NULL || other == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
if (other->itemCount == 0)
|
if (other->itemCount == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -103,6 +112,9 @@ void WMAppendArray(WMArray * array, WMArray * other)
|
|||||||
|
|
||||||
void WMAddToArray(WMArray * array, void *item)
|
void WMAddToArray(WMArray * array, void *item)
|
||||||
{
|
{
|
||||||
|
if (array == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
if (array->itemCount >= array->allocSize) {
|
if (array->itemCount >= array->allocSize) {
|
||||||
array->allocSize += RESIZE_INCREMENT;
|
array->allocSize += RESIZE_INCREMENT;
|
||||||
array->items = wrealloc(array->items, sizeof(void *) * array->allocSize);
|
array->items = wrealloc(array->items, sizeof(void *) * array->allocSize);
|
||||||
@@ -116,6 +128,9 @@ void WMInsertInArray(WMArray * array, int index, void *item)
|
|||||||
{
|
{
|
||||||
wassertr(index >= 0 && index <= array->itemCount);
|
wassertr(index >= 0 && index <= array->itemCount);
|
||||||
|
|
||||||
|
if (array == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
if (array->itemCount >= array->allocSize) {
|
if (array->itemCount >= array->allocSize) {
|
||||||
array->allocSize += RESIZE_INCREMENT;
|
array->allocSize += RESIZE_INCREMENT;
|
||||||
array->items = wrealloc(array->items, sizeof(void *) * array->allocSize);
|
array->items = wrealloc(array->items, sizeof(void *) * array->allocSize);
|
||||||
@@ -135,6 +150,9 @@ void *WMReplaceInArray(WMArray * array, int index, void *item)
|
|||||||
|
|
||||||
wassertrv(index >= 0 && index <= array->itemCount, NULL);
|
wassertrv(index >= 0 && index <= array->itemCount, NULL);
|
||||||
|
|
||||||
|
if (array == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
/* is it really useful to perform append if index == array->itemCount ? -Dan */
|
/* is it really useful to perform append if index == array->itemCount ? -Dan */
|
||||||
if (index == array->itemCount) {
|
if (index == array->itemCount) {
|
||||||
WMAddToArray(array, item);
|
WMAddToArray(array, item);
|
||||||
@@ -151,6 +169,9 @@ int WMDeleteFromArray(WMArray * array, int index)
|
|||||||
{
|
{
|
||||||
wassertrv(index >= 0 && index < array->itemCount, 0);
|
wassertrv(index >= 0 && index < array->itemCount, 0);
|
||||||
|
|
||||||
|
if (array == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (array->destructor) {
|
if (array->destructor) {
|
||||||
array->destructor(array->items[index]);
|
array->destructor(array->items[index]);
|
||||||
}
|
}
|
||||||
@@ -169,6 +190,9 @@ int WMRemoveFromArrayMatching(WMArray * array, WMMatchDataProc * match, void *cd
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if (array == NULL)
|
||||||
|
return 1;
|
||||||
|
|
||||||
if (match != NULL) {
|
if (match != NULL) {
|
||||||
for (i = 0; i < array->itemCount; i++) {
|
for (i = 0; i < array->itemCount; i++) {
|
||||||
if ((*match) (array->items[i], cdata)) {
|
if ((*match) (array->items[i], cdata)) {
|
||||||
@@ -190,7 +214,7 @@ int WMRemoveFromArrayMatching(WMArray * array, WMMatchDataProc * match, void *cd
|
|||||||
|
|
||||||
void *WMGetFromArray(WMArray * array, int index)
|
void *WMGetFromArray(WMArray * array, int index)
|
||||||
{
|
{
|
||||||
if (index < 0 || index >= array->itemCount)
|
if (index < 0 || array == NULL || index >= array->itemCount)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return array->items[index];
|
return array->items[index];
|
||||||
@@ -198,7 +222,7 @@ void *WMGetFromArray(WMArray * array, int index)
|
|||||||
|
|
||||||
void *WMPopFromArray(WMArray * array)
|
void *WMPopFromArray(WMArray * array)
|
||||||
{
|
{
|
||||||
if (array->itemCount <= 0)
|
if (array->itemCount <= 0 || array == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
array->itemCount--;
|
array->itemCount--;
|
||||||
@@ -210,6 +234,9 @@ int WMFindInArray(WMArray * array, WMMatchDataProc * match, void *cdata)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if (array == NULL)
|
||||||
|
return WANotFound;
|
||||||
|
|
||||||
if (match != NULL) {
|
if (match != NULL) {
|
||||||
for (i = 0; i < array->itemCount; i++) {
|
for (i = 0; i < array->itemCount; i++) {
|
||||||
if ((*match) (array->items[i], cdata))
|
if ((*match) (array->items[i], cdata))
|
||||||
@@ -229,6 +256,9 @@ int WMCountInArray(WMArray * array, void *item)
|
|||||||
{
|
{
|
||||||
int i, count;
|
int i, count;
|
||||||
|
|
||||||
|
if (array == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
for (i = 0, count = 0; i < array->itemCount; i++) {
|
for (i = 0, count = 0; i < array->itemCount; i++) {
|
||||||
if (array->items[i] == item)
|
if (array->items[i] == item)
|
||||||
count++;
|
count++;
|
||||||
@@ -239,6 +269,9 @@ int WMCountInArray(WMArray * array, void *item)
|
|||||||
|
|
||||||
void WMSortArray(WMArray * array, WMCompareDataProc * comparer)
|
void WMSortArray(WMArray * array, WMCompareDataProc * comparer)
|
||||||
{
|
{
|
||||||
|
if (array == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
if (array->itemCount > 1) { /* Don't sort empty or single element arrays */
|
if (array->itemCount > 1) { /* Don't sort empty or single element arrays */
|
||||||
qsort(array->items, array->itemCount, sizeof(void *), comparer);
|
qsort(array->items, array->itemCount, sizeof(void *), comparer);
|
||||||
}
|
}
|
||||||
@@ -248,6 +281,9 @@ void WMMapArray(WMArray * array, void (*function) (void *, void *), void *data)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if (array == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
for (i = 0; i < array->itemCount; i++) {
|
for (i = 0; i < array->itemCount; i++) {
|
||||||
(*function) (array->items[i], data);
|
(*function) (array->items[i], data);
|
||||||
}
|
}
|
||||||
@@ -257,7 +293,7 @@ WMArray *WMGetSubarrayWithRange(WMArray * array, WMRange aRange)
|
|||||||
{
|
{
|
||||||
WMArray *newArray;
|
WMArray *newArray;
|
||||||
|
|
||||||
if (aRange.count <= 0)
|
if (aRange.count <= 0 || array == NULL)
|
||||||
return WMCreateArray(0);
|
return WMCreateArray(0);
|
||||||
|
|
||||||
if (aRange.position < 0)
|
if (aRange.position < 0)
|
||||||
@@ -276,7 +312,7 @@ WMArray *WMGetSubarrayWithRange(WMArray * array, WMRange aRange)
|
|||||||
|
|
||||||
void *WMArrayFirst(WMArray * array, WMArrayIterator * iter)
|
void *WMArrayFirst(WMArray * array, WMArrayIterator * iter)
|
||||||
{
|
{
|
||||||
if (array->itemCount == 0) {
|
if (array == NULL || array->itemCount == 0) {
|
||||||
*iter = WANotFound;
|
*iter = WANotFound;
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
@@ -287,7 +323,7 @@ void *WMArrayFirst(WMArray * array, WMArrayIterator * iter)
|
|||||||
|
|
||||||
void *WMArrayLast(WMArray * array, WMArrayIterator * iter)
|
void *WMArrayLast(WMArray * array, WMArrayIterator * iter)
|
||||||
{
|
{
|
||||||
if (array->itemCount == 0) {
|
if (array == NULL || array->itemCount == 0) {
|
||||||
*iter = WANotFound;
|
*iter = WANotFound;
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
@@ -298,6 +334,11 @@ void *WMArrayLast(WMArray * array, WMArrayIterator * iter)
|
|||||||
|
|
||||||
void *WMArrayNext(WMArray * array, WMArrayIterator * iter)
|
void *WMArrayNext(WMArray * array, WMArrayIterator * iter)
|
||||||
{
|
{
|
||||||
|
if (array == NULL) {
|
||||||
|
*iter = WANotFound;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (*iter >= 0 && *iter < array->itemCount - 1) {
|
if (*iter >= 0 && *iter < array->itemCount - 1) {
|
||||||
return array->items[++(*iter)];
|
return array->items[++(*iter)];
|
||||||
} else {
|
} else {
|
||||||
@@ -308,6 +349,11 @@ void *WMArrayNext(WMArray * array, WMArrayIterator * iter)
|
|||||||
|
|
||||||
void *WMArrayPrevious(WMArray * array, WMArrayIterator * iter)
|
void *WMArrayPrevious(WMArray * array, WMArrayIterator * iter)
|
||||||
{
|
{
|
||||||
|
if (array == NULL) {
|
||||||
|
*iter = WANotFound;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (*iter > 0 && *iter < array->itemCount) {
|
if (*iter > 0 && *iter < array->itemCount) {
|
||||||
return array->items[--(*iter)];
|
return array->items[--(*iter)];
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user