Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dynamic_vectors
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
Environments
Terraform modules
Monitor
Incidents
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PREMIERE
PROG_SEQ
dynamic_vectors
Commits
17b14223
Commit
17b14223
authored
3 years ago
by
abivarma.kandiah
Browse files
Options
Downloads
Patches
Plain Diff
Add asserts in functions
parent
0ed98ea3
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
header/vectors.h
+1
-0
1 addition, 0 deletions
header/vectors.h
src/test_vectors.c
+2
-2
2 additions, 2 deletions
src/test_vectors.c
src/vectors.c
+6
-0
6 additions, 0 deletions
src/vectors.c
with
9 additions
and
2 deletions
header/vectors.h
+
1
−
0
View file @
17b14223
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
#include
<stdlib.h>
#include
<stdlib.h>
#include
<stdint.h>
#include
<stdint.h>
#include
<stdbool.h>
#include
<stdbool.h>
#include
<assert.h>
typedef
int
type
;
typedef
int
type
;
typedef
struct
vector_
*
vector
;
typedef
struct
vector_
*
vector
;
...
...
This diff is collapsed.
Click to expand it.
src/test_vectors.c
+
2
−
2
View file @
17b14223
...
@@ -14,10 +14,10 @@ int main()
...
@@ -14,10 +14,10 @@ int main()
{
{
vector
test
=
vector_create
();
vector
test
=
vector_create
();
printf
(
"%d
\n
"
,
vector_length
(
test
));
printf
(
"
Created Vector lenght :
%d
\n
"
,
vector_length
(
test
));
vector_push
(
test
,
15
);
vector_push
(
test
,
15
);
printf
(
"%d
\n
"
,
vector_length
(
test
));
printf
(
"
Modified Vector lenght :
%d
\n
"
,
vector_length
(
test
));
return
0
;
return
0
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/vectors.c
+
6
−
0
View file @
17b14223
...
@@ -17,7 +17,11 @@ vector vector_create()
...
@@ -17,7 +17,11 @@ vector vector_create()
{
{
vector
vec
=
malloc
(
sizeof
(
*
vec
));
//!BUG POSSIBLE
vector
vec
=
malloc
(
sizeof
(
*
vec
));
//!BUG POSSIBLE
assert
(
vec
!=
NULL
);
vec
->
content
=
malloc
(
sizeof
(
type
)
*
VECTOR_INIT_CAPACITY
);
vec
->
content
=
malloc
(
sizeof
(
type
)
*
VECTOR_INIT_CAPACITY
);
assert
(
vec
->
content
!=
NULL
);
vec
->
capacity
=
VECTOR_INIT_CAPACITY
;
vec
->
capacity
=
VECTOR_INIT_CAPACITY
;
vec
->
length
=
0
;
vec
->
length
=
0
;
...
@@ -34,6 +38,8 @@ void vector_push(vector vec, type element)
...
@@ -34,6 +38,8 @@ void vector_push(vector vec, type element)
if
(
vec
->
length
>=
vec
->
capacity
)
if
(
vec
->
length
>=
vec
->
capacity
)
{
{
vec
->
content
=
realloc
(
vec
->
content
,
sizeof
(
type
)
*
vec
->
capacity
*
2
);
vec
->
content
=
realloc
(
vec
->
content
,
sizeof
(
type
)
*
vec
->
capacity
*
2
);
assert
(
vec
->
content
!=
NULL
);
vec
->
capacity
=
vec
->
capacity
*
2
;
vec
->
capacity
=
vec
->
capacity
*
2
;
}
}
...
...
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