Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Nettle
nettle
Commits
dd279150
Commit
dd279150
authored
Jul 13, 2018
by
Niels Möller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check for allocation overflow in eratosthenes program.
parent
95798b5c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
2 deletions
+13
-2
ChangeLog
ChangeLog
+6
-0
examples/eratosthenes.c
examples/eratosthenes.c
+7
-2
No files found.
ChangeLog
View file @
dd279150
2018-07-13 Niels Möller <nisse@lysator.liu.se>
* examples/eratosthenes.c (vector_alloc): Add assert related to
overflow in the size calculation. Fixes a corner case identified
by static analysis.
2018-07-12 Niels Möller <nisse@lysator.liu.se>
* examples/eratosthenes.c (main): Don't allocate bitmap storage
...
...
examples/eratosthenes.c
View file @
dd279150
...
...
@@ -92,8 +92,13 @@ isqrt(unsigned long n)
static
unsigned
long
*
vector_alloc
(
unsigned
long
size
)
{
unsigned
long
end
=
(
size
+
BITS_PER_LONG
-
1
)
/
BITS_PER_LONG
;
unsigned
long
*
vector
=
malloc
(
end
*
sizeof
(
*
vector
));
unsigned
long
end
;
unsigned
long
*
vector
;
assert
(
size
<=
ULONG_MAX
-
(
BITS_PER_LONG
-
1
));
end
=
(
size
+
BITS_PER_LONG
-
1
)
/
BITS_PER_LONG
;
vector
=
malloc
(
end
*
sizeof
(
*
vector
));
if
(
!
vector
)
{
...
...
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