Skip to content

Commit 1d284db

Browse files
committed
NULL array after freeing in cvec_free functions
Bump to 4.2.1 Change Copyright to 2025
1 parent e930ee7 commit 1d284db

16 files changed

+79
-38
lines changed

Doxyfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ PROJECT_NAME = CVector
3232
# This could be handy for archiving the generated documentation or
3333
# if some version control system is used.
3434

35-
PROJECT_NUMBER = 4.2.0
35+
PROJECT_NUMBER = 4.2.1
3636

3737
# Using the PROJECT_BRIEF tag one can provide an optional one line description
3838
# for a project that appears at the top of each page and should give viewer

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2011-2024 Robert Winkler
3+
Copyright (c) 2011-2025 Robert Winkler
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
66
documentation files (the "Software"), to deal in the Software without restriction, including without limitation

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ LICENSE
150150
=======
151151
CVector is licensed under the MIT License.
152152

153-
Copyright (c) 2011-2024 Robert Winkler
153+
Copyright (c) 2011-2025 Robert Winkler
154154

155155
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
156156
documentation files (the "Software"), to deal in the Software without restriction, including without limitation

cvector.h

+19-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
3-
CVector 4.2.0 MIT Licensed vector (dynamic array) library in strict C89
3+
CVector 4.2.1 MIT Licensed vector (dynamic array) library in strict C89
44
http://www.robertwinkler.com/projects/cvector.html
55
http://www.robertwinkler.com/projects/cvector/
66
@@ -16,7 +16,7 @@ more practical examples:
1616
1717
The MIT License (MIT)
1818
19-
Copyright (c) 2011-2024 Robert Winkler
19+
Copyright (c) 2011-2025 Robert Winkler
2020
2121
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
2222
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -602,6 +602,7 @@ void cvec_free_void(void* vec);
602602
{ \
603603
cvector_##TYPE* tmp = (cvector_##TYPE*)vec; \
604604
CVEC_FREE(tmp->a); \
605+
tmp->a = NULL; \
605606
tmp->size = 0; \
606607
tmp->capacity = 0; \
607608
}
@@ -1171,7 +1172,7 @@ void cvec_free_void(void* vec);
11711172
} \
11721173
\
11731174
CVEC_FREE(tmp->a); \
1174-
\
1175+
tmp->a = NULL; \
11751176
tmp->size = 0; \
11761177
tmp->capacity = 0; \
11771178
}
@@ -1513,11 +1514,13 @@ void cvec_free_i_heap(void* vec)
15131514
CVEC_FREE(tmp);
15141515
}
15151516

1516-
/** Frees the internal array and sets size and capacity to 0 */
1517+
/** Frees the internal array and zeros out the members to maintain a
1518+
* consistent state */
15171519
void cvec_free_i(void* vec)
15181520
{
15191521
cvector_i* tmp = (cvector_i*)vec;
15201522
CVEC_FREE(tmp->a);
1523+
tmp->a = NULL;
15211524
tmp->size = 0;
15221525
tmp->capacity = 0;
15231526
}
@@ -1852,11 +1855,14 @@ void cvec_free_d_heap(void* vec)
18521855
CVEC_FREE(tmp);
18531856
}
18541857

1855-
/** Frees the internal array and sets size and capacity to 0 */
1858+
/** Frees the internal array and zeros out the members to maintain a
1859+
* consistent state */
18561860
void cvec_free_d(void* vec)
18571861
{
18581862
cvector_d* tmp = (cvector_d*)vec;
1859-
CVEC_FREE(tmp->a); tmp->size = 0;
1863+
CVEC_FREE(tmp->a);
1864+
tmp->a = NULL;
1865+
tmp->size = 0;
18601866
tmp->capacity = 0;
18611867
}
18621868
#endif
@@ -2354,7 +2360,8 @@ void cvec_free_str_heap(void* vec)
23542360
CVEC_FREE(tmp);
23552361
}
23562362

2357-
/** Frees the internal array and sets size and capacity to 0 */
2363+
/** Frees the internal array and zeros out the members to maintain a
2364+
* consistent state */
23582365
void cvec_free_str(void* vec)
23592366
{
23602367
cvec_sz i;
@@ -2364,6 +2371,7 @@ void cvec_free_str(void* vec)
23642371
}
23652372

23662373
CVEC_FREE(tmp->a);
2374+
tmp->a = NULL;
23672375
tmp->size = 0;
23682376
tmp->capacity = 0;
23692377
}
@@ -3008,7 +3016,8 @@ void cvec_free_void_heap(void* vec)
30083016
CVEC_FREE(tmp);
30093017
}
30103018

3011-
/** Frees the internal array and sets size and capacity to 0 */
3019+
/** Frees the internal array and sets it, size, and capacity to NULL/0 to
3020+
* maintain a consistent state */
30123021
void cvec_free_void(void* vec)
30133022
{
30143023
cvec_sz i;
@@ -3020,7 +3029,7 @@ void cvec_free_void(void* vec)
30203029
}
30213030

30223031
CVEC_FREE(tmp->a);
3023-
3032+
tmp->a = NULL;
30243033
tmp->size = 0;
30253034
tmp->capacity = 0;
30263035
}
@@ -3185,7 +3194,7 @@ action and how it should behave, look at cvector_tests.c
31853194
\section LICENSE
31863195
CVector is licensed under the MIT License.
31873196
3188-
Copyright (c) 2011-2024 Robert Winkler
3197+
Copyright (c) 2011-2025 Robert Winkler
31893198
31903199
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
31913200
documentation files (the "Software"), to deal in the Software without restriction, including without limitation

cvector_d.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,13 @@ void cvec_free_d_heap(void* vec)
353353
CVEC_FREE(tmp);
354354
}
355355

356-
/** Frees the internal array and sets size and capacity to 0 */
356+
/** Frees the internal array and zeros out the members to maintain a
357+
* consistent state */
357358
void cvec_free_d(void* vec)
358359
{
359360
cvector_d* tmp = (cvector_d*)vec;
360-
CVEC_FREE(tmp->a); tmp->size = 0;
361+
CVEC_FREE(tmp->a);
362+
tmp->a = NULL;
363+
tmp->size = 0;
361364
tmp->capacity = 0;
362365
}

cvector_f_struct.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
3-
CVector 4.2.0 MIT Licensed vector (dynamic array) library in strict C89
3+
CVector 4.2.1 MIT Licensed vector (dynamic array) library in strict C89
44
http://www.robertwinkler.com/projects/cvector.html
55
http://www.robertwinkler.com/projects/cvector/
66
@@ -16,7 +16,7 @@ more practical examples:
1616
1717
The MIT License (MIT)
1818
19-
Copyright (c) 2011-2024 Robert Winkler
19+
Copyright (c) 2011-2025 Robert Winkler
2020
2121
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
2222
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -647,7 +647,7 @@ void cvec_free_f_struct(void* vec)
647647
}
648648

649649
CVEC_FREE(tmp->a);
650-
650+
tmp->a = NULL;
651651
tmp->size = 0;
652652
tmp->capacity = 0;
653653
}

cvector_i.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,13 @@ void cvec_free_i_heap(void* vec)
354354
CVEC_FREE(tmp);
355355
}
356356

357-
/** Frees the internal array and sets size and capacity to 0 */
357+
/** Frees the internal array and zeros out the members to maintain a
358+
* consistent state */
358359
void cvec_free_i(void* vec)
359360
{
360361
cvector_i* tmp = (cvector_i*)vec;
361362
CVEC_FREE(tmp->a);
363+
tmp->a = NULL;
362364
tmp->size = 0;
363365
tmp->capacity = 0;
364366
}

cvector_macro.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
3-
CVector 4.2.0 MIT Licensed vector (dynamic array) library in strict C89
3+
CVector 4.2.1 MIT Licensed vector (dynamic array) library in strict C89
44
http://www.robertwinkler.com/projects/cvector.html
55
http://www.robertwinkler.com/projects/cvector/
66
@@ -16,7 +16,7 @@ more practical examples:
1616
1717
The MIT License (MIT)
1818
19-
Copyright (c) 2011-2024 Robert Winkler
19+
Copyright (c) 2011-2025 Robert Winkler
2020
2121
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
2222
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -376,6 +376,7 @@ typedef CVEC_SIZE_TYPE cvec_sz;
376376
{ \
377377
cvector_##TYPE* tmp = (cvector_##TYPE*)vec; \
378378
CVEC_FREE(tmp->a); \
379+
tmp->a = NULL; \
379380
tmp->size = 0; \
380381
tmp->capacity = 0; \
381382
}
@@ -945,7 +946,7 @@ typedef CVEC_SIZE_TYPE cvec_sz;
945946
} \
946947
\
947948
CVEC_FREE(tmp->a); \
948-
\
949+
tmp->a = NULL; \
949950
tmp->size = 0; \
950951
tmp->capacity = 0; \
951952
}

cvector_short.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
3-
CVector 4.2.0 MIT Licensed vector (dynamic array) library in strict C89
3+
CVector 4.2.1 MIT Licensed vector (dynamic array) library in strict C89
44
http://www.robertwinkler.com/projects/cvector.html
55
http://www.robertwinkler.com/projects/cvector/
66
@@ -16,7 +16,7 @@ more practical examples:
1616
1717
The MIT License (MIT)
1818
19-
Copyright (c) 2011-2024 Robert Winkler
19+
Copyright (c) 2011-2025 Robert Winkler
2020
2121
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
2222
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -392,6 +392,7 @@ void cvec_free_short(void* vec)
392392
{
393393
cvector_short* tmp = (cvector_short*)vec;
394394
CVEC_FREE(tmp->a);
395+
tmp->a = NULL;
395396
tmp->size = 0;
396397
tmp->capacity = 0;
397398
}

cvector_str.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,8 @@ void cvec_free_str_heap(void* vec)
518518
CVEC_FREE(tmp);
519519
}
520520

521-
/** Frees the internal array and sets size and capacity to 0 */
521+
/** Frees the internal array and zeros out the members to maintain a
522+
* consistent state */
522523
void cvec_free_str(void* vec)
523524
{
524525
cvec_sz i;
@@ -528,6 +529,7 @@ void cvec_free_str(void* vec)
528529
}
529530

530531
CVEC_FREE(tmp->a);
532+
tmp->a = NULL;
531533
tmp->size = 0;
532534
tmp->capacity = 0;
533535
}

cvector_template.h

+1
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ void cvec_free_TYPE(void* vec)
358358
{
359359
cvector_TYPE* tmp = (cvector_TYPE*)vec;
360360
CVEC_FREE(tmp->a);
361+
tmp->a = NULL;
361362
tmp->size = 0;
362363
tmp->capacity = 0;
363364
}

cvector_template2.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ void cvec_free_TYPE(void* vec)
613613
}
614614

615615
CVEC_FREE(tmp->a);
616-
616+
tmp->a = NULL;
617617
tmp->size = 0;
618618
tmp->capacity = 0;
619619
}

cvector_tests.c

+24-3
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void erase_i_test()
116116
cvec_free_i(&vec);
117117
}
118118

119-
/* zeroing is valid initialization */
119+
/* zeroing is valid initialization and cvec_free_i returns to this state */
120120
void zero_init_i_test()
121121
{
122122
int i;
@@ -138,6 +138,9 @@ void zero_init_i_test()
138138
CU_ASSERT_EQUAL(i, vec.a[i]);
139139

140140
cvec_free_i(&vec);
141+
CU_ASSERT(vec.capacity == 0)
142+
CU_ASSERT(vec.size == 0)
143+
CU_ASSERT(vec.a == NULL)
141144
}
142145

143146

@@ -391,7 +394,7 @@ void erase_d_test()
391394
cvec_free_d(&vec);
392395
}
393396

394-
/* zeroing is valid initialization */
397+
/* zeroing is valid initialization and cvec_free_d returns to this state */
395398
void zero_init_d_test()
396399
{
397400
int i;
@@ -413,6 +416,9 @@ void zero_init_d_test()
413416
CU_ASSERT_EQUAL(i+0.5, vec.a[i]);
414417

415418
cvec_free_d(&vec);
419+
CU_ASSERT(vec.capacity == 0)
420+
CU_ASSERT(vec.size == 0)
421+
CU_ASSERT(vec.a == NULL)
416422
}
417423

418424
void insert_d_test()
@@ -700,7 +706,7 @@ void remove_str_test()
700706

701707
}
702708

703-
/* zeroing is valid initialization */
709+
/* zeroing is valid initialization and cvec_free_s returns to this state */
704710
void zero_init_str_test()
705711
{
706712
int i;
@@ -727,6 +733,9 @@ void zero_init_str_test()
727733
}
728734

729735
cvec_free_str(&vec);
736+
CU_ASSERT(vec.capacity == 0)
737+
CU_ASSERT(vec.size == 0)
738+
CU_ASSERT(vec.a == NULL)
730739
}
731740

732741

@@ -1392,6 +1401,12 @@ void zero_init_void_test()
13921401

13931402
cvec_free_void(&vec1);
13941403
cvec_free_void(&vec2);
1404+
CU_ASSERT(vec1.capacity == 0)
1405+
CU_ASSERT(vec1.size == 0)
1406+
CU_ASSERT(vec1.a == NULL)
1407+
CU_ASSERT(vec2.capacity == 0)
1408+
CU_ASSERT(vec2.size == 0)
1409+
CU_ASSERT(vec2.a == NULL)
13951410
}
13961411

13971412

@@ -1986,6 +2001,9 @@ void template_test()
19862001
CU_ASSERT_EQUAL(i, vec.a[i]);
19872002

19882003
cvec_free_short(&vec);
2004+
CU_ASSERT(vec.capacity == 0)
2005+
CU_ASSERT(vec.size == 0)
2006+
CU_ASSERT(vec.a == NULL)
19892007
}
19902008

19912009
void template_test2()
@@ -2194,6 +2212,9 @@ void template_test2()
21942212
CU_ASSERT_EQUAL(vec.size, 101);
21952213

21962214
cvec_free_f_struct(&vec);
2215+
CU_ASSERT(vec.capacity == 0)
2216+
CU_ASSERT(vec.size == 0)
2217+
CU_ASSERT(vec.a == NULL)
21972218
}
21982219

21992220

0 commit comments

Comments
 (0)