Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
asn1c
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
asn1c
Commits
f5927117
Commit
f5927117
authored
Sep 03, 2012
by
Lev Walkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove volatile qualifier from OID code
parent
e09f9f1b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
34 deletions
+76
-34
skeletons/OBJECT_IDENTIFIER.c
skeletons/OBJECT_IDENTIFIER.c
+59
-29
skeletons/tests/check-OIDs.c
skeletons/tests/check-OIDs.c
+17
-5
No files found.
skeletons/OBJECT_IDENTIFIER.c
View file @
f5927117
...
...
@@ -3,6 +3,7 @@
* Redistribution and modifications are permitted subject to BSD license.
*/
#include <asn_internal.h>
#include <INTEGER.h>
#include <OBJECT_IDENTIFIER.h>
#include <OCTET_STRING.h>
#include <limits.h>
/* for CHAR_BIT */
...
...
@@ -649,12 +650,13 @@ OBJECT_IDENTIFIER_parse_arcs(const char *oid_text, ssize_t oid_txt_length,
long
*
arcs
,
unsigned
int
arcs_slots
,
const
char
**
opt_oid_text_end
)
{
unsigned
int
arcs_count
=
0
;
const
char
*
oid_end
;
long
value
=
0
;
const
char
*
value_start
;
enum
{
ST_SKIPSPACE
,
ST_LEADSPACE
,
ST_TAILSPACE
,
ST_WAITDIGITS
,
/* Next character is expected to be a digit */
ST_DIGITS
}
state
=
ST_
SKIP
SPACE
;
ST_DIGITS
/* INVARIANT: value_start != 0 in this state */
}
state
=
ST_
LEAD
SPACE
;
if
(
!
oid_text
||
oid_txt_length
<
-
1
||
(
arcs_slots
&&
!
arcs
))
{
if
(
opt_oid_text_end
)
*
opt_oid_text_end
=
oid_text
;
...
...
@@ -665,42 +667,70 @@ OBJECT_IDENTIFIER_parse_arcs(const char *oid_text, ssize_t oid_txt_length,
if
(
oid_txt_length
==
-
1
)
oid_txt_length
=
strlen
(
oid_text
);
#define _OID_CAPTURE_ARC(value_start, oid_text) do { \
long value; \
switch(asn_strtol(value_start, oid_text, &value)) { \
case ASN_STRTOL_OK: \
if(arcs_count < arcs_slots) \
arcs[arcs_count] = value; \
arcs_count++; \
break; \
case ASN_STRTOL_ERROR_RANGE: \
if(opt_oid_text_end) \
*opt_oid_text_end = oid_text; \
errno = ERANGE; \
return -1; \
case ASN_STRTOL_ERROR_INVAL: \
if(opt_oid_text_end) \
*opt_oid_text_end = oid_text; \
errno = EINVAL; \
return -1; \
} \
} while(0)
for
(
oid_end
=
oid_text
+
oid_txt_length
;
oid_text
<
oid_end
;
oid_text
++
)
{
switch
(
*
oid_text
)
{
case
0x09
:
case
0x0a
:
case
0x0d
:
case
0x20
:
/* whitespace */
if
(
state
==
ST_SKIPSPACE
)
{
switch
(
state
)
{
case
ST_LEADSPACE
:
case
ST_TAILSPACE
:
continue
;
}
else
{
break
;
/* Finish */
case
ST_DIGITS
:
_OID_CAPTURE_ARC
(
value_start
,
oid_text
);
state
=
ST_TAILSPACE
;
continue
;
case
ST_WAITDIGITS
:
break
;
}
case
0x2e
:
/* '.' */
if
(
state
!=
ST_DIGITS
||
(
oid_text
+
1
)
==
oid_end
)
{
switch
(
state
)
{
case
ST_LEADSPACE
:
case
ST_WAITDIGITS
:
break
;
case
ST_TAILSPACE
:
state
=
ST_WAITDIGITS
;
break
;
case
ST_DIGITS
:
_OID_CAPTURE_ARC
(
value_start
,
oid_text
);
state
=
ST_WAITDIGITS
;
continue
;
}
if
(
arcs_count
<
arcs_slots
)
arcs
[
arcs_count
]
=
value
;
arcs_count
++
;
state
=
ST_WAITDIGITS
;
continue
;
break
;
case
0x30
:
case
0x31
:
case
0x32
:
case
0x33
:
case
0x34
:
case
0x35
:
case
0x36
:
case
0x37
:
case
0x38
:
case
0x39
:
if
(
state
!=
ST_DIGITS
)
{
switch
(
state
)
{
case
ST_TAILSPACE
:
state
=
ST_WAITDIGITS
;
break
;
case
ST_LEADSPACE
:
case
ST_WAITDIGITS
:
state
=
ST_DIGITS
;
value
=
0
;
}
if
(
1
)
{
long
volatile
new_value
=
value
*
10
;
/* GCC 4.x is being too smart without volatile */
if
(
new_value
/
10
!=
value
||
(
value
=
new_value
+
(
*
oid_text
-
0x30
))
<
0
)
{
/* Overflow */
state
=
ST_WAITDIGITS
;
break
;
}
value_start
=
oid_text
;
continue
;
case
ST_DIGITS
:
continue
;
}
break
;
default:
/* Unexpected symbols */
state
=
ST_WAITDIGITS
;
...
...
@@ -714,14 +744,14 @@ OBJECT_IDENTIFIER_parse_arcs(const char *oid_text, ssize_t oid_txt_length,
/* Finalize last arc */
switch
(
state
)
{
case
ST_LEADSPACE
:
case
ST_WAITDIGITS
:
errno
=
EINVAL
;
return
-
1
;
case
ST_DIGITS
:
if
(
arcs_count
<
arcs_slots
)
arcs
[
arcs_count
]
=
value
;
arcs_count
++
;
_OID_CAPTURE_ARC
(
value_start
,
oid_text
);
/* Fall through */
case
ST_TAILSPACE
:
default:
return
arcs_count
;
}
...
...
skeletons/tests/check-OIDs.c
View file @
f5927117
...
...
@@ -249,8 +249,10 @@ static void check_xer(int expect_arcs, char *xer) {
&
asn_DEF_RELATIVE_OID
,
(
void
**
)
stp
,
"t"
,
xer
,
strlen
(
xer
));
if
(
expect_arcs
==
-
1
)
{
if
(
rc
.
code
!=
RC_OK
)
if
(
rc
.
code
!=
RC_OK
)
{
printf
(
"-1
\n
"
);
return
;
}
}
assert
(
rc
.
code
==
RC_OK
);
...
...
@@ -381,17 +383,27 @@ main() {
CHECK_REGEN_OID
(
19
);
CHECK_REGEN_OID
(
20
);
check_parse
(
""
,
0
);
check_parse
(
" "
,
0
);
check_parse
(
" "
,
0
);
check_parse
(
""
,
-
1
);
check_parse
(
" "
,
-
1
);
check_parse
(
" "
,
-
1
);
check_parse
(
"."
,
-
1
);
check_parse
(
" ."
,
-
1
);
check_parse
(
".1"
,
-
1
);
check_parse
(
"1."
,
-
1
);
check_parse
(
"1. "
,
-
1
);
check_parse
(
".1. "
,
-
1
);
check_parse
(
" .1. "
,
-
1
);
check_parse
(
" 1"
,
1
);
check_parse
(
" 1.2"
,
2
);
check_parse
(
" 1."
,
-
1
);
check_parse
(
" 1. "
,
-
1
);
check_parse
(
"1. "
,
-
1
);
check_parse
(
"1.2"
,
2
);
check_parse
(
"1.2 "
,
2
);
check_parse
(
"1.2 "
,
2
);
check_parse
(
" 1.2 "
,
2
);
check_parse
(
"1. 2"
,
-
1
);
check_parse
(
"1 .2"
,
-
1
);
check_parse
(
"10.30.234.234"
,
4
);
check_parse
(
"10.30.234.234 "
,
4
);
check_parse
(
"10.30.234. 234 "
,
-
1
);
...
...
@@ -414,7 +426,7 @@ main() {
check_parse
(
"1.900a0000000.3"
,
-
1
);
check_parse
(
"1.900a.3"
,
-
1
);
check_xer
(
0
,
"<t></t>"
);
check_xer
(
-
1
,
"<t></t>"
);
check_xer
(
2
,
"<t>1.2</t>"
);
check_xer
(
3
,
"<t>1.2.3</t>"
);
check_xer
(
3
,
"<t> 1.2.3 </t>"
);
...
...
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