Skip to content

Commit 4b2b49f

Browse files
committed
Merge remote-tracking branch 'origin/master' into gh-pages
2 parents 02bbaef + 8ece66a commit 4b2b49f

8 files changed

Lines changed: 146 additions & 22 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 71 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,54 @@ env:
1010
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
1111

1212
jobs:
13-
gcc_ubuntu_18_04:
13+
ubuntu_18_04_gcc:
1414
strategy:
1515
matrix:
1616
version: [4.8, 5, 6, 8]
17-
runs-on: ubuntu-22.04
18-
container:
19-
image: ubuntu:18.04
17+
runs-on: ubuntu-24.04
2018
env:
2119
CPP: cpp-${{ matrix.version }}
2220
CC: gcc-${{ matrix.version }}
2321
CXX: g++-${{ matrix.version }}
2422
steps:
25-
- name: "Install git..."
23+
- name: "Checkout libcdada"
24+
uses: actions/checkout@v3
25+
with:
26+
path: libcdada
27+
28+
- name: Run tests in Ubuntu 18.04 container
2629
run: |
27-
apt-get update && apt-get install -y software-properties-common && \
28-
apt-get update && add-apt-repository -y ppa:git-core/ppa && \
29-
apt-get update && apt-get install -y git
30+
docker run --rm \
31+
-v ${{ github.workspace }}:/workspace \
32+
-w /workspace \
33+
-e CPP="${CPP}" \
34+
-e CC="${CC}" \
35+
-e CXX="${CXX}" \
36+
-e CONFIG_FLAGS="--disable-silent-rules" \
37+
ubuntu:18.04 \
38+
bash -c "
39+
set -e
40+
apt-get update
41+
apt-get install -y software-properties-common
42+
add-apt-repository -y ppa:git-core/ppa
43+
apt-get update
44+
apt-get install -y git
45+
git config --global --add safe.directory /workspace/libcdada
46+
./libcdada/.github/workflows/deps.sh gcc ${{ matrix.version }}
47+
cd libcdada && .github/workflows/test_script.sh
48+
CONFIG_FLAGS=\"\$CONFIG_FLAGS --enable-debug\" .github/workflows/test_script.sh
49+
"
3050
51+
ubuntu_22_04_gcc:
52+
strategy:
53+
matrix:
54+
version: [9, 10, 11, 12]
55+
runs-on: ubuntu-22.04
56+
env:
57+
CPP: cpp-${{ matrix.version }}
58+
CC: gcc-${{ matrix.version }}
59+
CXX: g++-${{ matrix.version }}
60+
steps:
3161
- name: "Checkout libcdada"
3262
uses: actions/checkout@v3
3363
with:
@@ -45,11 +75,11 @@ jobs:
4575
env:
4676
CONFIG_FLAGS: --disable-silent-rules --enable-debug
4777

48-
gcc_ubuntu_22_04:
78+
ubuntu_24_04_gcc:
4979
strategy:
5080
matrix:
51-
version: [9, 10, 11, 12]
52-
runs-on: ubuntu-22.04
81+
version: [13, 14]
82+
runs-on: ubuntu-24.04
5383
env:
5484
CPP: cpp-${{ matrix.version }}
5585
CC: gcc-${{ matrix.version }}
@@ -72,7 +102,7 @@ jobs:
72102
env:
73103
CONFIG_FLAGS: --disable-silent-rules --enable-debug
74104

75-
clang_ubuntu_22_04:
105+
ubuntu_22_04_clang:
76106
strategy:
77107
matrix:
78108
version: [11, 12, 13, 14]
@@ -100,3 +130,32 @@ jobs:
100130
run: cd libcdada && .github/workflows/test_script.sh
101131
env:
102132
CONFIG_FLAGS: --disable-silent-rules --enable-debug
133+
134+
ubuntu_24_04_clang:
135+
strategy:
136+
matrix:
137+
version: [15, 16, 17, 18, 19]
138+
runs-on: ubuntu-24.04
139+
env:
140+
CPP: clang-cpp-${{ matrix.version }}
141+
CC: clang-${{ matrix.version }}
142+
CXX: clang++-${{ matrix.version }}
143+
CFLAGS: -gdwarf-4 #clang14 and on use dwarf5, but valgrind doesn't support it
144+
CXXFLAGS: -gdwarf-4
145+
steps:
146+
- name: "Checkout libcdada"
147+
uses: actions/checkout@v3
148+
with:
149+
path: libcdada
150+
151+
- name: "Install deps"
152+
run: ./libcdada/.github/workflows/deps.sh clang ${{ matrix.version }}
153+
154+
- name: "Compile and test using clang-${{ matrix.version }}"
155+
run: cd libcdada && .github/workflows/test_script.sh
156+
env:
157+
CONFIG_FLAGS: --disable-silent-rules
158+
- name: "Compile and test using clang-${{ matrix.version }} (DEBUG)"
159+
run: cd libcdada && .github/workflows/test_script.sh
160+
env:
161+
CONFIG_FLAGS: --disable-silent-rules --enable-debug

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,4 @@ include/cdada/version.h
4545

4646
!.gitignore
4747
!.travis.yml
48+
!.github/

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ Legend:
99
- [O] Other
1010
```
1111

12+
### v0.6.2 (24th October 2025)
13+
14+
- [B] map: fix garbage in `prev_val` when key not in map for `cdada_map_insert_replace()`
15+
- [O] CI fixes
16+
1217
### v0.6.1 (29th July 2024)
1318

1419
- [O] tests: fix segfault in map_test.c

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
master [![Build status](https://github.com/msune/libcdada/workflows/ci/badge.svg?branch=master)](https://github.com/msune/libcdada/actions), devel [![Build status](https://github.com/msune/libcdada/workflows/ci/badge.svg?branch=devel)](https://github.com/msune/libcdada/actions)
1+
master [![Build status](https://github.com/msune/libcdada/actions/workflows/ci.yaml/badge.svg?branch=master)](https://github.com/msune/libcdada/actions/workflows/ci.yaml), devel [![Build status](https://github.com/msune/libcdada/actions/workflows/ci.yaml/badge.svg?branch=devel)](https://github.com/msune/libcdada/actions/workflows/ci.yaml)
22

33
**libcdada** - basic data structures in C (`libstdc++` wrapper)
44
---------------------------------------------------------------

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.6.1
1+
v0.6.2

include/cdada/__map_internal.h

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,23 @@ int cdada_map_insert_u(__cdada_map_int_t* m, std::map<T, void*>* m_u,
105105
void** prev_val){
106106
typename std::map<T, void*>::iterator it;
107107

108+
if(prev_val)
109+
*prev_val = NULL;
110+
108111
if(m->key_len == m->user_key_len){
109112
T* __attribute((__may_alias__)) aux;
110113

111114
aux = (T*)key;
112115

113116
it = m_u->find(*aux);
114-
if(!replace && it != m_u->end())
115-
return CDADA_E_EXISTS;
116117

117-
if(replace && prev_val)
118-
*prev_val = it->second;
118+
if(it != m_u->end()){
119+
if(!replace)
120+
return CDADA_E_EXISTS;
121+
122+
if(prev_val)
123+
*prev_val = it->second;
124+
}
119125

120126
(*m_u)[*aux] = val;
121127

@@ -132,8 +138,13 @@ int cdada_map_insert_u(__cdada_map_int_t* m, std::map<T, void*>* m_u,
132138
if(!replace && it != m_u->end())
133139
return CDADA_E_EXISTS;
134140

135-
if(replace && prev_val)
136-
*prev_val = it->second;
141+
if(it != m_u->end()){
142+
if(!replace)
143+
return CDADA_E_EXISTS;
144+
145+
if(prev_val)
146+
*prev_val = it->second;
147+
}
137148

138149
(*m_u)[aux] = val;
139150

include/cdada/map.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,9 @@ int cdada_map_insert(cdada_map_t* map, const void* key, void* val);
179179
* @param map Map pointer
180180
* @param key Key. The key type _must_ have all bytes initialized
181181
* @param val Pointer to the value
182-
* @param prev_val If not NULL, when replacing a value the previous value will be
183-
* set here, regardless if the operation is successful or not
182+
* @param prev_val If not NULL the previous stored value for that key will be set
183+
* here (*prev_val = old_value_ptr). If the key didn't exist, it
184+
* will be set to NULL.
184185
*
185186
* @returns Return codes:
186187
* CDADA_SUCCESS: element is inserted

test/map_test.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,51 @@ int test_u3552_insert_removal_traverse_custom(){
993993
return 0;
994994
}
995995

996+
int test_insert_replace_bug_empty(){
997+
int rv;
998+
uint8_t key;
999+
test_u552_t key2;
1000+
int value, *prev = NULL;
1001+
1002+
//Test insert_replace when key doesn't exist in the map
1003+
map = cdada_map_create(uint8_t);
1004+
TEST_ASSERT(map != NULL);
1005+
1006+
key = 1;
1007+
//Note: prev is deliberately != NULL, as code MUST nullify
1008+
prev = (int*)0x1234;
1009+
rv = cdada_map_insert_replace(map, &key, &value, (void**)&prev);
1010+
TEST_ASSERT(rv == CDADA_SUCCESS);
1011+
TEST_ASSERT(prev == NULL);
1012+
1013+
rv = cdada_map_insert_replace(map, &key, &value, (void**)&prev);
1014+
TEST_ASSERT(rv == CDADA_SUCCESS);
1015+
TEST_ASSERT(prev == &value);
1016+
rv = cdada_map_destroy(map);
1017+
TEST_ASSERT(rv == CDADA_SUCCESS);
1018+
1019+
//Test insert_replace when key doesn't exist in the map
1020+
map = cdada_map_create(test_u552_t);
1021+
TEST_ASSERT(map != NULL);
1022+
1023+
memset(&key2, 0, sizeof(key2));
1024+
key2.mid = 1;
1025+
prev = (int*)0x1234;
1026+
1027+
//if not found
1028+
rv = cdada_map_insert_replace(map, &key2, &value, (void**)&prev);
1029+
TEST_ASSERT(rv == CDADA_SUCCESS);
1030+
TEST_ASSERT(prev == NULL);
1031+
1032+
rv = cdada_map_insert_replace(map, &key2, &value, (void**)&prev);
1033+
TEST_ASSERT(rv == CDADA_SUCCESS);
1034+
TEST_ASSERT(prev == &value);
1035+
rv = cdada_map_destroy(map);
1036+
TEST_ASSERT(rv == CDADA_SUCCESS);
1037+
1038+
return 0;
1039+
}
1040+
9961041
int main(int args, char** argv){
9971042

9981043
int rv;
@@ -1012,6 +1057,8 @@ int main(int args, char** argv){
10121057
rv |= test_u552_insert_removal_traverse_custom();
10131058
rv |= test_u3552_insert_removal_traverse_custom();
10141059

1060+
rv |= test_insert_replace_bug_empty();
1061+
10151062
//Add your test here, and return a code appropriately...
10161063
return rv == 0? EXIT_SUCCESS : EXIT_FAILURE;
10171064
}

0 commit comments

Comments
 (0)