Skip to content

Commit 42d26a3

Browse files
updates to fix build errors, found an off by 1 error that would never actually arrise, UB, but, fixed anyways in the heap code
1 parent 9bb1229 commit 42d26a3

3 files changed

Lines changed: 33 additions & 20 deletions

File tree

‎git-dep/shm‎

Submodule shm updated 1 file

‎modules/heapalloc/src/_512bits.cpp‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -157,34 +157,34 @@ alloc::_512bits::set_bit( std::uint16_t x, _512bits *f )
157157
}
158158
else if( x < 128 )
159159
{
160-
f->_064_127 |= (1ULL << x);
160+
f->_064_127 |= (1ULL << ( x - 64 ));
161161

162162
}
163163
else if( x < 192 )
164164
{
165-
f->_128_191 |= (1ULL << x);
165+
f->_128_191 |= (1ULL << ( x - 128 ));
166166
}
167167
else if( x < 256 )
168168
{
169-
f->_192_255 |= (1ULL << x);
169+
f->_192_255 |= (1ULL << ( x - 192 ));
170170
}
171171
else if( x < 320 )
172172
{
173-
f->_256_319 |= (1ULL << x);
173+
f->_256_319 |= (1ULL << ( x - 256 ));
174174
}
175175
else if( x < 384 )
176176
{
177-
f->_320_383 |= (1ULL << x);
177+
f->_320_383 |= (1ULL << ( x - 320 ));
178178

179179
}
180180
else if( x < 448 )
181181
{
182-
f->_384_447 |= (1ULL << x);
182+
f->_384_447 |= (1ULL << ( x - 384 ));
183183

184184
}
185185
else if( x < 512 )
186186
{
187-
f->_448_511 |= (1ULL << x);
187+
f->_448_511 |= (1ULL << ( x - 448 ));
188188
}
189189
return;
190190
}
@@ -198,32 +198,32 @@ alloc::_512bits::unset_bit( std::uint16_t x, _512bits *f )
198198
}
199199
else if( x < 128 )
200200
{
201-
f->_064_127 &= ~(1ULL << x);
201+
f->_064_127 &= ~(1ULL << ( x - 64 ));
202202

203203
}
204204
else if( x < 192 )
205205
{
206-
f->_128_191 &= ~(1ULL << x);
206+
f->_128_191 &= ~(1ULL << ( x - 128 ));
207207
}
208208
else if( x < 256 )
209209
{
210-
f->_192_255 &= ~(1ULL << x);
210+
f->_192_255 &= ~(1ULL << ( x - 192 ));
211211
}
212212
else if( x < 320 )
213213
{
214-
f->_256_319 &= ~(1ULL << x);
214+
f->_256_319 &= ~(1ULL << ( x - 256 ));
215215
}
216216
else if( x < 384 )
217217
{
218-
f->_320_383 &= ~(1ULL << x);
218+
f->_320_383 &= ~(1ULL << ( x - 320 ));
219219
}
220220
else if( x < 448 )
221221
{
222-
f->_384_447 &= ~(1ULL << x);
222+
f->_384_447 &= ~(1ULL << ( x - 384 ));
223223
}
224224
else if( x < 512 )
225225
{
226-
f->_448_511 &= ~(1ULL << x);
226+
f->_448_511 &= ~(1ULL << ( x - 448 ));
227227
}
228228
return;
229229
}

‎testsuite/calculateOffset.cpp‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,26 @@ int main()
1111
{
1212

1313

14-
char *base = (char*)malloc( (1 << ipc::buffer_size_pow_two ) );
15-
14+
char *base = nullptr;
15+
base = reinterpret_cast<char*>( std::malloc( (1 << ipc::buffer_size_pow_two ) ) );
16+
if( base == nullptr )
17+
{
18+
std::cerr << "malloc failed\n";
19+
return( EXIT_FAILURE );
20+
}
1621

22+
#if defined(__GNUC__) || defined(__clang__)
23+
#pragma GCC diagnostic push
24+
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
25+
#endif
1726
const auto offset1 = ipc::buffer::calculate_buffer_offset( base, (void*)(base));
18-
const auto offset3 = ipc::buffer::calculate_buffer_offset( base, (void*)(base-1));
27+
const auto offset3 = ipc::buffer::calculate_buffer_offset( base, (void*)(base - 1));
1928
const auto offset5 = ipc::buffer::calculate_buffer_offset( base, (void*)(0));
20-
const auto offset6 = ipc::buffer::calculate_buffer_offset( base, (void*)(base + ( 1<<ipc::buffer_size_pow_two )+1 ) );
29+
const auto offset6 = ipc::buffer::calculate_buffer_offset( base,
30+
(void*)(base + ( 1<<ipc::buffer_size_pow_two )+1 ) );
31+
#if defined(__GNUC__) || defined(__clang__)
32+
#pragma GCC diagnostic pop
33+
#endif
2134

2235

2336
/** Offsets should be zero */
@@ -48,6 +61,6 @@ int main()
4861
return( EXIT_FAILURE );
4962
}
5063

51-
free( base );
64+
std::free( base );
5265
return( EXIT_SUCCESS );
5366
}

0 commit comments

Comments
 (0)