Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
9f43b2f8
Commit
9f43b2f8
authored
Sep 26, 2010
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
alloc: fix case where poolsize is not a power of 2.
parent
82569e8c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
1 deletion
+28
-1
ccan/alloc/alloc.c
ccan/alloc/alloc.c
+2
-1
ccan/alloc/test/run-corrupt.c
ccan/alloc/test/run-corrupt.c
+26
-0
No files found.
ccan/alloc/alloc.c
View file @
9f43b2f8
...
...
@@ -133,7 +133,7 @@ static unsigned int size_to_bucket(unsigned long size)
static
unsigned
int
small_page_bits
(
unsigned
long
poolsize
)
{
return
fls
(
poolsize
/
MAX_SMALL_PAGES
/
2
);
return
fls
(
poolsize
/
MAX_SMALL_PAGES
-
1
);
}
static
struct
page_header
*
from_pgnum
(
struct
header
*
head
,
...
...
@@ -404,6 +404,7 @@ void alloc_init(void *pool, unsigned long poolsize)
/* Add the rest of the pages as large pages. */
i
=
SMALL_PAGES_PER_LARGE_PAGE
;
while
((
i
<<
sp_bits
)
+
(
1
<<
lp_bits
)
<=
poolsize
)
{
assert
(
i
<
MAX_SMALL_PAGES
);
ph
=
from_pgnum
(
head
,
i
,
sp_bits
);
ph
->
elements_used
=
0
;
add_large_page_to_freelist
(
head
,
ph
,
sp_bits
);
...
...
ccan/alloc/test/run-corrupt.c
0 → 100644
View file @
9f43b2f8
/* Example allocation which caused corruption. */
#include <ccan/alloc/alloc.c>
#include <ccan/alloc/bitops.c>
#include <ccan/alloc/tiny.c>
#include <ccan/tap/tap.h>
#include <stdlib.h>
int
main
(
int
argc
,
char
*
argv
[])
{
void
*
mem
;
plan_tests
(
7
);
mem
=
malloc
(
1179648
);
alloc_init
(
mem
,
1179648
);
ok1
(
alloc_check
(
mem
,
1179648
));
ok1
(
alloc_get
(
mem
,
1179648
,
48
,
16
));
ok1
(
alloc_check
(
mem
,
1179648
));
ok1
(
alloc_get
(
mem
,
1179648
,
53
,
16
));
ok1
(
alloc_check
(
mem
,
1179648
));
ok1
(
alloc_get
(
mem
,
1179648
,
53
,
16
));
ok1
(
alloc_check
(
mem
,
1179648
));
free
(
mem
);
return
exit_status
();
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment