Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gmsh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Romin Tomasetti
gmsh
Commits
75074b0d
Commit
75074b0d
authored
7 years ago
by
Christophe Geuzaine
Browse files
Options
Downloads
Patches
Plain Diff
check null input list, always
parent
826526cd
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Common/ListUtils.cpp
+27
-27
27 additions, 27 deletions
Common/ListUtils.cpp
with
27 additions
and
27 deletions
Common/ListUtils.cpp
+
27
−
27
View file @
75074b0d
...
@@ -70,15 +70,14 @@ List_T *List_Create(int n, int incr, int size)
...
@@ -70,15 +70,14 @@ List_T *List_Create(int n, int incr, int size)
void
List_Delete
(
List_T
*
liste
)
void
List_Delete
(
List_T
*
liste
)
{
{
if
(
!
liste
)
if
(
!
liste
)
return
;
return
;
Free
(
liste
->
array
);
Free
(
liste
->
array
);
Free
(
liste
);
Free
(
liste
);
}
}
void
List_Realloc
(
List_T
*
liste
,
int
n
)
void
List_Realloc
(
List_T
*
liste
,
int
n
)
{
{
if
(
n
<=
0
)
if
(
!
liste
||
n
<=
0
)
return
;
return
;
if
(
liste
->
array
==
NULL
)
{
if
(
liste
->
array
==
NULL
)
{
...
@@ -96,6 +95,7 @@ void List_Realloc(List_T * liste, int n)
...
@@ -96,6 +95,7 @@ void List_Realloc(List_T * liste, int n)
void
List_Add
(
List_T
*
liste
,
void
*
data
)
void
List_Add
(
List_T
*
liste
,
void
*
data
)
{
{
if
(
!
liste
)
return
;
liste
->
n
++
;
liste
->
n
++
;
List_Realloc
(
liste
,
liste
->
n
);
List_Realloc
(
liste
,
liste
->
n
);
...
@@ -105,6 +105,7 @@ void List_Add(List_T * liste, void *data)
...
@@ -105,6 +105,7 @@ void List_Add(List_T * liste, void *data)
void
List_Add
(
List_T
*
liste
,
int
data
)
void
List_Add
(
List_T
*
liste
,
int
data
)
{
{
if
(
!
liste
)
return
;
List_Add
(
liste
,
&
data
);
List_Add
(
liste
,
&
data
);
}
}
...
@@ -115,7 +116,7 @@ int List_Nbr(List_T * liste)
...
@@ -115,7 +116,7 @@ int List_Nbr(List_T * liste)
void
List_Read
(
List_T
*
liste
,
int
index
,
void
*
data
)
void
List_Read
(
List_T
*
liste
,
int
index
,
void
*
data
)
{
{
if
((
index
<
0
)
||
(
index
>=
liste
->
n
)){
if
(
!
liste
||
(
index
<
0
)
||
(
index
>=
liste
->
n
)){
Msg
::
Error
(
"Wrong list index (read)"
);
Msg
::
Error
(
"Wrong list index (read)"
);
index
=
0
;
index
=
0
;
}
}
...
@@ -124,7 +125,7 @@ void List_Read(List_T * liste, int index, void *data)
...
@@ -124,7 +125,7 @@ void List_Read(List_T * liste, int index, void *data)
void
List_Write
(
List_T
*
liste
,
int
index
,
void
*
data
)
void
List_Write
(
List_T
*
liste
,
int
index
,
void
*
data
)
{
{
if
((
index
<
0
)
||
(
index
>=
liste
->
n
))
if
(
!
liste
||
(
index
<
0
)
||
(
index
>=
liste
->
n
))
Msg
::
Error
(
"Wrong list index (write)"
);
Msg
::
Error
(
"Wrong list index (write)"
);
else
{
else
{
liste
->
isorder
=
0
;
liste
->
isorder
=
0
;
...
@@ -134,7 +135,7 @@ void List_Write(List_T * liste, int index, void *data)
...
@@ -134,7 +135,7 @@ void List_Write(List_T * liste, int index, void *data)
void
List_Put
(
List_T
*
liste
,
int
index
,
void
*
data
)
void
List_Put
(
List_T
*
liste
,
int
index
,
void
*
data
)
{
{
if
(
index
<
0
)
if
(
!
liste
||
index
<
0
)
Msg
::
Error
(
"Wrong list index (put)"
);
Msg
::
Error
(
"Wrong list index (put)"
);
else
{
else
{
if
(
index
>=
liste
->
n
)
{
if
(
index
>=
liste
->
n
)
{
...
@@ -150,13 +151,14 @@ void List_Put(List_T * liste, int index, void *data)
...
@@ -150,13 +151,14 @@ void List_Put(List_T * liste, int index, void *data)
void
List_Pop
(
List_T
*
liste
)
void
List_Pop
(
List_T
*
liste
)
{
{
if
(
!
liste
)
return
;
if
(
liste
->
n
>
0
)
if
(
liste
->
n
>
0
)
liste
->
n
--
;
liste
->
n
--
;
}
}
void
*
List_Pointer
(
List_T
*
liste
,
int
index
)
void
*
List_Pointer
(
List_T
*
liste
,
int
index
)
{
{
if
((
index
<
0
)
||
(
index
>=
liste
->
n
)){
if
(
!
liste
||
(
index
<
0
)
||
(
index
>=
liste
->
n
)){
Msg
::
Error
(
"Wrong list index (pointer)"
);
Msg
::
Error
(
"Wrong list index (pointer)"
);
index
=
0
;
index
=
0
;
}
}
...
@@ -166,7 +168,7 @@ void *List_Pointer(List_T * liste, int index)
...
@@ -166,7 +168,7 @@ void *List_Pointer(List_T * liste, int index)
void
*
List_Pointer_NoChange
(
List_T
*
liste
,
int
index
)
void
*
List_Pointer_NoChange
(
List_T
*
liste
,
int
index
)
{
{
if
((
index
<
0
)
||
(
index
>=
liste
->
n
)){
if
(
!
liste
||
(
index
<
0
)
||
(
index
>=
liste
->
n
)){
Msg
::
Error
(
"Wrong list index (pointer)"
);
Msg
::
Error
(
"Wrong list index (pointer)"
);
index
=
0
;
index
=
0
;
}
}
...
@@ -180,11 +182,13 @@ void *List_Pointer_Fast(List_T * liste, int index)
...
@@ -180,11 +182,13 @@ void *List_Pointer_Fast(List_T * liste, int index)
void
List_Sort
(
List_T
*
liste
,
int
(
*
fcmp
)
(
const
void
*
a
,
const
void
*
b
))
void
List_Sort
(
List_T
*
liste
,
int
(
*
fcmp
)
(
const
void
*
a
,
const
void
*
b
))
{
{
if
(
!
liste
)
return
;
qsort
(
liste
->
array
,
liste
->
n
,
liste
->
size
,
fcmp
);
qsort
(
liste
->
array
,
liste
->
n
,
liste
->
size
,
fcmp
);
}
}
void
List_Unique
(
List_T
*
liste
,
int
(
*
fcmp
)
(
const
void
*
a
,
const
void
*
b
))
void
List_Unique
(
List_T
*
liste
,
int
(
*
fcmp
)
(
const
void
*
a
,
const
void
*
b
))
{
{
if
(
!
liste
)
return
;
if
(
liste
->
isorder
!=
1
)
{
if
(
liste
->
isorder
!=
1
)
{
List_Sort
(
liste
,
fcmp
);
List_Sort
(
liste
,
fcmp
);
liste
->
isorder
=
1
;
liste
->
isorder
=
1
;
...
@@ -203,6 +207,7 @@ void List_Unique(List_T * liste, int (*fcmp) (const void *a, const void *b))
...
@@ -203,6 +207,7 @@ void List_Unique(List_T * liste, int (*fcmp) (const void *a, const void *b))
int
List_Search
(
List_T
*
liste
,
void
*
data
,
int
List_Search
(
List_T
*
liste
,
void
*
data
,
int
(
*
fcmp
)
(
const
void
*
a
,
const
void
*
b
))
int
(
*
fcmp
)
(
const
void
*
a
,
const
void
*
b
))
{
{
if
(
!
liste
)
return
0
;
void
*
ptr
;
void
*
ptr
;
if
(
liste
->
isorder
!=
1
)
{
if
(
liste
->
isorder
!=
1
)
{
...
@@ -218,11 +223,9 @@ int List_Search(List_T * liste, void *data,
...
@@ -218,11 +223,9 @@ int List_Search(List_T * liste, void *data,
int
List_ISearchSeq
(
List_T
*
liste
,
void
*
data
,
int
List_ISearchSeq
(
List_T
*
liste
,
void
*
data
,
int
(
*
fcmp
)
(
const
void
*
a
,
const
void
*
b
))
int
(
*
fcmp
)
(
const
void
*
a
,
const
void
*
b
))
{
{
int
i
;
if
(
!
liste
)
if
(
!
liste
)
return
-
1
;
return
-
1
;
i
=
0
;
int
i
=
0
;
while
((
i
<
List_Nbr
(
liste
))
&&
fcmp
(
data
,
(
void
*
)
List_Pointer
(
liste
,
i
)))
while
((
i
<
List_Nbr
(
liste
))
&&
fcmp
(
data
,
(
void
*
)
List_Pointer
(
liste
,
i
)))
i
++
;
i
++
;
if
(
i
==
List_Nbr
(
liste
))
if
(
i
==
List_Nbr
(
liste
))
...
@@ -233,8 +236,8 @@ int List_ISearchSeq(List_T * liste, void *data,
...
@@ -233,8 +236,8 @@ int List_ISearchSeq(List_T * liste, void *data,
void
*
List_PQuery
(
List_T
*
liste
,
void
*
data
,
void
*
List_PQuery
(
List_T
*
liste
,
void
*
data
,
int
(
*
fcmp
)
(
const
void
*
a
,
const
void
*
b
))
int
(
*
fcmp
)
(
const
void
*
a
,
const
void
*
b
))
{
{
if
(
!
liste
)
return
0
;
void
*
ptr
;
void
*
ptr
;
if
(
liste
->
isorder
!=
1
)
if
(
liste
->
isorder
!=
1
)
List_Sort
(
liste
,
fcmp
);
List_Sort
(
liste
,
fcmp
);
liste
->
isorder
=
1
;
liste
->
isorder
=
1
;
...
@@ -245,29 +248,23 @@ void *List_PQuery(List_T * liste, void *data,
...
@@ -245,29 +248,23 @@ void *List_PQuery(List_T * liste, void *data,
int
List_Suppress
(
List_T
*
liste
,
void
*
data
,
int
List_Suppress
(
List_T
*
liste
,
void
*
data
,
int
(
*
fcmp
)(
const
void
*
a
,
const
void
*
b
))
int
(
*
fcmp
)(
const
void
*
a
,
const
void
*
b
))
{
{
char
*
ptr
;
if
(
!
liste
)
return
0
;
int
len
;
char
*
ptr
=
(
char
*
)
List_PQuery
(
liste
,
data
,
fcmp
)
;
ptr
=
(
char
*
)
List_PQuery
(
liste
,
data
,
fcmp
)
;
if
(
ptr
==
NULL
)
return
(
0
);
if
(
ptr
==
NULL
)
return
(
0
);
liste
->
n
--
;
liste
->
n
--
;
len
=
liste
->
n
-
(((
intptr_t
)
ptr
-
(
intptr_t
)
liste
->
array
)
/
liste
->
size
);
int
len
=
liste
->
n
-
(((
intptr_t
)
ptr
-
(
intptr_t
)
liste
->
array
)
/
liste
->
size
);
if
(
len
>
0
)
memmove
(
ptr
,
ptr
+
liste
->
size
,
len
*
liste
->
size
);
if
(
len
>
0
)
memmove
(
ptr
,
ptr
+
liste
->
size
,
len
*
liste
->
size
);
return
(
1
);
return
(
1
);
}
}
int
List_PSuppress
(
List_T
*
liste
,
int
index
)
int
List_PSuppress
(
List_T
*
liste
,
int
index
)
{
{
char
*
ptr
;
if
(
!
liste
)
return
0
;
int
len
;
char
*
ptr
=
(
char
*
)
List_Pointer_NoChange
(
liste
,
index
);
ptr
=
(
char
*
)
List_Pointer_NoChange
(
liste
,
index
);
if
(
ptr
==
NULL
)
if
(
ptr
==
NULL
)
return
(
0
);
return
(
0
);
liste
->
n
--
;
liste
->
n
--
;
len
=
liste
->
n
-
(((
intptr_t
)
ptr
-
(
intptr_t
)
liste
->
array
)
/
liste
->
size
);
int
len
=
liste
->
n
-
(((
intptr_t
)
ptr
-
(
intptr_t
)
liste
->
array
)
/
liste
->
size
);
if
(
len
>
0
)
if
(
len
>
0
)
memmove
(
ptr
,
ptr
+
liste
->
size
,
len
*
liste
->
size
);
memmove
(
ptr
,
ptr
+
liste
->
size
,
len
*
liste
->
size
);
return
(
1
);
return
(
1
);
...
@@ -275,6 +272,7 @@ int List_PSuppress(List_T * liste, int index)
...
@@ -275,6 +272,7 @@ int List_PSuppress(List_T * liste, int index)
void
List_Invert
(
List_T
*
a
,
List_T
*
b
)
void
List_Invert
(
List_T
*
a
,
List_T
*
b
)
{
{
if
(
!
a
||
!
b
)
return
;
int
i
,
N
;
int
i
,
N
;
N
=
List_Nbr
(
a
);
N
=
List_Nbr
(
a
);
for
(
i
=
0
;
i
<
N
;
i
++
)
{
for
(
i
=
0
;
i
<
N
;
i
++
)
{
...
@@ -284,21 +282,21 @@ void List_Invert(List_T * a, List_T * b)
...
@@ -284,21 +282,21 @@ void List_Invert(List_T * a, List_T * b)
void
List_Reset
(
List_T
*
liste
)
void
List_Reset
(
List_T
*
liste
)
{
{
if
(
!
liste
)
if
(
!
liste
)
return
;
return
;
liste
->
n
=
0
;
liste
->
n
=
0
;
}
}
void
List_Action
(
List_T
*
liste
,
void
(
*
action
)
(
void
*
data
,
void
*
dummy
))
void
List_Action
(
List_T
*
liste
,
void
(
*
action
)
(
void
*
data
,
void
*
dummy
))
{
{
if
(
!
liste
)
return
;
int
i
,
dummy
;
int
i
,
dummy
;
for
(
i
=
0
;
i
<
List_Nbr
(
liste
);
i
++
)
for
(
i
=
0
;
i
<
List_Nbr
(
liste
);
i
++
)
(
*
action
)
(
List_Pointer_NoChange
(
liste
,
i
),
&
dummy
);
(
*
action
)
(
List_Pointer_NoChange
(
liste
,
i
),
&
dummy
);
}
}
void
List_Copy
(
List_T
*
a
,
List_T
*
b
)
void
List_Copy
(
List_T
*
a
,
List_T
*
b
)
{
{
if
(
!
a
||
!
b
)
return
;
int
i
,
N
;
int
i
,
N
;
N
=
List_Nbr
(
a
);
N
=
List_Nbr
(
a
);
for
(
i
=
0
;
i
<
N
;
i
++
)
{
for
(
i
=
0
;
i
<
N
;
i
++
)
{
...
@@ -308,6 +306,7 @@ void List_Copy(List_T * a, List_T * b)
...
@@ -308,6 +306,7 @@ void List_Copy(List_T * a, List_T * b)
void
List_Remove
(
List_T
*
a
,
int
i
)
void
List_Remove
(
List_T
*
a
,
int
i
)
{
{
if
(
!
a
)
return
;
memcpy
(
&
a
->
array
[
i
*
a
->
size
],
&
a
->
array
[(
i
+
1
)
*
a
->
size
],
memcpy
(
&
a
->
array
[
i
*
a
->
size
],
&
a
->
array
[(
i
+
1
)
*
a
->
size
],
a
->
size
*
(
a
->
n
-
i
-
1
));
a
->
size
*
(
a
->
n
-
i
-
1
));
a
->
n
--
;
a
->
n
--
;
...
@@ -316,6 +315,7 @@ void List_Remove(List_T *a, int i)
...
@@ -316,6 +315,7 @@ void List_Remove(List_T *a, int i)
//insert a in b before i
//insert a in b before i
void
List_Insert_In_List
(
List_T
*
a
,
int
i
,
List_T
*
b
)
void
List_Insert_In_List
(
List_T
*
a
,
int
i
,
List_T
*
b
)
{
{
if
(
!
a
||
!
b
)
return
;
int
oldn
=
b
->
n
;
int
oldn
=
b
->
n
;
b
->
n
+=
a
->
n
;
b
->
n
+=
a
->
n
;
List_Realloc
(
b
,
b
->
n
);
List_Realloc
(
b
,
b
->
n
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment