Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
easy-soc-libs
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
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
HAL
easy-soc-libs
Commits
561cd3b5
Commit
561cd3b5
authored
5 years ago
by
Anjan Chanda
Browse files
Options
Downloads
Patches
Plain Diff
libeasy: check for errors in strtob()
parent
29177663
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!67
Devel
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
libeasy/utils.c
+14
-2
14 additions, 2 deletions
libeasy/utils.c
libeasy/utils.h
+3
-3
3 additions, 3 deletions
libeasy/utils.h
with
17 additions
and
5 deletions
libeasy/utils.c
+
14
−
2
View file @
561cd3b5
...
...
@@ -41,7 +41,19 @@ static int hex2byte(const char *hex)
LIBEASY_API
uint8_t
*
strtob
(
char
*
str
,
int
len
,
uint8_t
*
bytes
)
{
size_t
i
;
size_t
slen
;
int
i
;
if
(
!
str
||
!
bytes
)
return
NULL
;
slen
=
strlen
(
str
);
if
(
!
slen
||
slen
%
2
||
str
[
slen
]
!=
'\0'
)
return
NULL
;
slen
>>=
1
;
if
(
len
>
slen
)
len
=
slen
;
for
(
i
=
0
;
i
<
len
;
i
++
)
{
int
a
;
...
...
@@ -60,7 +72,7 @@ LIBEASY_API char *btostr(uint8_t *bytes, int len, char *str)
{
size_t
i
;
if
(
!
str
)
if
(
!
str
||
!
bytes
)
return
NULL
;
for
(
i
=
0
;
i
<
len
;
i
++
)
...
...
This diff is collapsed.
Click to expand it.
libeasy/utils.h
+
3
−
3
View file @
561cd3b5
...
...
@@ -16,9 +16,9 @@ extern "C" {
* "001122334455" --> {0x00, 0x11, 0x22, 0x33, 0x44, 0x55}
*
* @param[in] str hex string.
* @param[in] len
string
length of
the hex string
.
* @param[in] len length of
output buffer passed to the function
.
* @param[out] bytes output buffer to write the converted hex string.
* @return byte array of the converted hex string.
* @return byte array of the converted hex string
, or %NULL on error
.
*/
extern
uint8_t
*
strtob
(
char
*
str
,
int
len
,
uint8_t
*
bytes
);
...
...
@@ -31,7 +31,7 @@ extern uint8_t *strtob(char *str, int len, uint8_t *bytes);
* @param[in] bytes byte array.
* @param[in] len length of the byte array.
* @param[out] str output buffer to write the hex string.
* @return hex string.
* @return hex string
or %NULL on error
.
*/
extern
char
*
btostr
(
uint8_t
*
bytes
,
int
len
,
char
*
str
);
...
...
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