Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
relibc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Peter Limkilde Svendsen
relibc
Commits
629c20f0
Commit
629c20f0
authored
7 years ago
by
Alex Lyon
Browse files
Options
Downloads
Patches
Plain Diff
string: ensure resulting string has NUL byte
parent
3e1b945e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/errno/src/lib.rs
+1
-1
1 addition, 1 deletion
src/errno/src/lib.rs
src/string/src/lib.rs
+5
-4
5 additions, 4 deletions
src/string/src/lib.rs
with
6 additions
and
5 deletions
src/errno/src/lib.rs
+
1
−
1
View file @
629c20f0
...
@@ -162,5 +162,5 @@ pub enum Errno {
...
@@ -162,5 +162,5 @@ pub enum Errno {
// Operation would block (may be the same value as [EAGAIN])
// Operation would block (may be the same value as [EAGAIN])
EWOULDBLOCK
,
EWOULDBLOCK
,
// Cross-device link
// Cross-device link
EXDEV
EXDEV
,
}
}
This diff is collapsed.
Click to expand it.
src/string/src/lib.rs
+
5
−
4
View file @
629c20f0
...
@@ -2,9 +2,9 @@
...
@@ -2,9 +2,9 @@
#![no_std]
#![no_std]
extern
crate
errno
;
extern
crate
platform
;
extern
crate
platform
;
extern
crate
stdlib
;
extern
crate
stdlib
;
extern
crate
errno
;
use
platform
::
types
::
*
;
use
platform
::
types
::
*
;
use
errno
::
*
;
use
errno
::
*
;
...
@@ -94,10 +94,10 @@ pub unsafe extern "C" fn strdup(s1: *const c_char) -> *mut c_char {
...
@@ -94,10 +94,10 @@ pub unsafe extern "C" fn strdup(s1: *const c_char) -> *mut c_char {
#[no_mangle]
#[no_mangle]
pub
unsafe
extern
"C"
fn
strndup
(
s1
:
*
const
c_char
,
size
:
usize
)
->
*
mut
c_char
{
pub
unsafe
extern
"C"
fn
strndup
(
s1
:
*
const
c_char
,
size
:
usize
)
->
*
mut
c_char
{
// the "+ 1" is to account for the NUL byte
let
len
=
strnlen
(
s1
,
size
);
let
len
=
strnlen
(
s1
,
size
)
+
1
;
let
buffer
=
stdlib
::
malloc
(
len
)
as
*
mut
c_char
;
// the "+ 1" is to account for the NUL byte
let
buffer
=
stdlib
::
malloc
(
len
+
1
)
as
*
mut
c_char
;
if
buffer
.is_null
()
{
if
buffer
.is_null
()
{
platform
::
errno
=
Errno
::
ENOMEM
as
c_int
;
platform
::
errno
=
Errno
::
ENOMEM
as
c_int
;
}
else
{
}
else
{
...
@@ -105,6 +105,7 @@ pub unsafe extern "C" fn strndup(s1: *const c_char, size: usize) -> *mut c_char
...
@@ -105,6 +105,7 @@ pub unsafe extern "C" fn strndup(s1: *const c_char, size: usize) -> *mut c_char
for
i
in
0
..
len
as
isize
{
for
i
in
0
..
len
as
isize
{
*
buffer
.offset
(
i
)
=
*
s1
.offset
(
i
);
*
buffer
.offset
(
i
)
=
*
s1
.offset
(
i
);
}
}
*
buffer
.offset
(
len
as
isize
)
=
0
;
}
}
buffer
buffer
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment