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
redox-os
relibc
Commits
33d7c5a5
Commit
33d7c5a5
authored
7 months ago
by
Peter Limkilde Svendsen
Browse files
Options
Downloads
Patches
Plain Diff
Fix wcpncpy test
parent
31d43c95
No related branches found
No related tags found
1 merge request
!487
Refactor mktime, timegm and fix wcpncpy test
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/wchar/wcpncpy.c
+25
-6
25 additions, 6 deletions
tests/wchar/wcpncpy.c
with
25 additions
and
6 deletions
tests/wchar/wcpncpy.c
+
25
−
6
View file @
33d7c5a5
...
...
@@ -4,15 +4,34 @@
int
main
()
{
wchar_t
src
[]
=
L"Привет мир"
;
wchar_t
dest
[
10
];
wchar_t
*
result
=
wcpncpy
(
dest
,
src
,
5
);
assert
(
wcsncmp
(
dest
,
src
,
5
)
==
0
);
size_t
n_input
=
10
;
size_t
n_short
=
6
;
size_t
n_long
=
15
;
// FIXME: seems to read from uninitialized memory?
// assert(*result == L'\0');
// Initialize with sentinel values to detect exactly how much is overwritten
wchar_t
dest_short
[]
=
L"
\x12\x34\x56\x78\x90\x12\x34\x56\x78\x90\x12\x34\x56\x78
"
;
wchar_t
dest_long
[]
=
L"
\x12\x34\x56\x78\x90\x12\x34\x56\x78\x90\x12\x34\x56\x78
"
;
assert
(
result
==
dest
+
5
);
wchar_t
expected_short
[]
=
L"Привет
\x34\x56\x78\x90\x12\x34\x56\x78
"
;
// The "short" test should copy exactly n_short characters without terminating null
wchar_t
*
result_short
=
wcpncpy
(
dest_short
,
src
,
n_short
);
assert
(
wcsncmp
(
dest_short
,
src
,
n_short
)
==
0
);
assert
(
result_short
==
dest_short
+
n_short
);
for
(
size_t
i
=
n_short
;
i
<
n_long
;
i
++
)
{
// Check that the sentinel characters have not been overwritten
assert
(
dest_short
[
i
]
==
expected_short
[
i
]);
}
// The "long" test should write the input string, with nulls appended up to n_long
wchar_t
*
result_long
=
wcpncpy
(
dest_long
,
src
,
n_long
);
assert
(
wcsncmp
(
dest_long
,
src
,
n_long
)
==
0
);
assert
(
result_long
==
dest_long
+
n_input
);
for
(
size_t
i
=
n_input
;
i
<
n_long
;
i
++
)
{
// Check that nulls are written up to n_long
assert
(
dest_long
[
i
]
==
L'\0'
);
}
return
0
;
}
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