Skip to content

Commit 13206b8

Browse files
committed
* introduced MULLE_BUFFER_IS_SPRINTF_INFLEXIBLE for that sprintf use special case, to quiet a wrong assert
1 parent a6e4b68 commit 13206b8

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
cmake_minimum_required( VERSION 3.14)
1+
cmake_minimum_required( VERSION 3.13...99.99)
22

3-
project( mulle-buffer VERSION 5.0.0 LANGUAGES C)
3+
project( mulle-buffer VERSION 5.0.1 LANGUAGES C)
44

55

66
### mulle-sde environment

RELEASENOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### 5.0.1
2+
3+
* introduced `MULLE_BUFFER_IS_SPRINTF_INFLEXIBLE` for that sprintf use special case, to quiet a wrong assert
4+
15
# 5.0.0
26

37

src/mulle--buffer.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ void
5959
//
6060
// this is for mulle_sprintf, where we have API that gets storage, where
6161
// we don't know the size. We can't have buffer->_sentinel wrapping
62-
// around though for our tests
62+
// around though for our tests. Of course the crazy sentinel value,
63+
// can't protect us from overwrites (but thats sprintf)
6364
//
6465
if( length == INT_MAX)
6566
{
@@ -68,9 +69,11 @@ void
6869
length >>= 1;
6970
buffer->_sentinel = &buffer->_storage[ length];
7071
}
72+
buffer->_type = MULLE_BUFFER_IS_SPRINTF_INFLEXIBLE;
7173
}
72-
buffer->_size = length;
73-
buffer->_type = MULLE_BUFFER_IS_INFLEXIBLE;
74+
else
75+
buffer->_type = MULLE_BUFFER_IS_INFLEXIBLE;
76+
buffer->_size = length;
7477

7578
assert( buffer->_sentinel >= buffer->_storage);
7679
}

src/mulle--buffer.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ struct mulle_allocator;
4545

4646
enum
4747
{
48-
MULLE_BUFFER_IS_FLEXIBLE = 0,
49-
MULLE_BUFFER_IS_INFLEXIBLE = 1,
50-
MULLE_BUFFER_IS_FLUSHABLE = 2
48+
MULLE_BUFFER_IS_FLEXIBLE = 0,
49+
MULLE_BUFFER_IS_INFLEXIBLE = 1,
50+
MULLE_BUFFER_IS_FLUSHABLE = 2,
51+
MULLE_BUFFER_IS_SPRINTF_INFLEXIBLE = 3 // sentinel is not trustworthy
5152
};
5253

5354

@@ -554,7 +555,11 @@ static inline int _mulle__buffer_intersects_bytes( struct mulle__buffer *buffe
554555
unsigned char *start;
555556
unsigned char *end;
556557

557-
if( ! length)
558+
// so if the buffer is MULLE_BUFFER_IS_SPRINTF_INFLEXIBLE (which it NEVER
559+
// should be except when we are doing actually a sprintf implementation)
560+
// the concept of intersection becomes meaningless, as the sentinel is
561+
// way off
562+
if( ! length || (buffer->_type & MULLE_BUFFER_IS_SPRINTF_INFLEXIBLE) == MULLE_BUFFER_IS_SPRINTF_INFLEXIBLE)
558563
return( 0);
559564

560565
start = bytes;

src/mulle-buffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#ifndef mulle_buffer_h__
4040
#define mulle_buffer_h__
4141

42-
#define MULLE__BUFFER_VERSION ((5UL << 20) | (0 << 8) | 0)
42+
#define MULLE__BUFFER_VERSION ((5UL << 20) | (0 << 8) | 1)
4343

4444
#include "include.h"
4545
#include "mulle--buffer.h"

0 commit comments

Comments
 (0)