Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
953adb16
Commit
953adb16
authored
Jan 31, 2018
by
Thomas Van Lenten
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add casts to removed undefined behaviors around shifts.
Fixes #4246 Fixes #4247
parent
b7185515
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
11 additions
and
11 deletions
+11
-11
GPBCodedInputStream.m
objectivec/GPBCodedInputStream.m
+1
-1
GPBUtilities.m
objectivec/GPBUtilities.m
+2
-2
GPBUtilities_PackagePrivate.h
objectivec/GPBUtilities_PackagePrivate.h
+2
-2
GPBCodedInputStreamTests.m
objectivec/Tests/GPBCodedInputStreamTests.m
+1
-1
GPBCodedOuputStreamTests.m
objectivec/Tests/GPBCodedOuputStreamTests.m
+1
-1
GPBUtilitiesTests.m
objectivec/Tests/GPBUtilitiesTests.m
+4
-4
No files found.
objectivec/GPBCodedInputStream.m
View file @
953adb16
...
...
@@ -110,7 +110,7 @@ static int64_t ReadRawVarint64(GPBCodedInputStreamState *state) {
int64_t
result
=
0
;
while
(
shift
<
64
)
{
int8_t
b
=
ReadRawByte
(
state
);
result
|=
(
int64_t
)(
b
&
0x7F
)
<<
shift
;
result
|=
(
int64_t
)(
(
uint64_t
)(
b
&
0x7F
)
<<
shift
)
;
if
((
b
&
0x80
)
==
0
)
{
return
result
;
}
...
...
objectivec/GPBUtilities.m
View file @
953adb16
...
...
@@ -291,7 +291,7 @@ BOOL GPBGetHasIvar(GPBMessage *self, int32_t idx, uint32_t fieldNumber) {
}
else
{
NSCAssert
(
idx
!=
GPBNoHasBit
,
@"Invalid has bit."
);
uint32_t
byteIndex
=
idx
/
32
;
uint32_t
bitMask
=
(
1
<<
(
idx
%
32
));
uint32_t
bitMask
=
(
1
U
<<
(
idx
%
32
));
BOOL
hasIvar
=
(
self
->
messageStorage_
->
_has_storage_
[
byteIndex
]
&
bitMask
)
?
YES
:
NO
;
return
hasIvar
;
...
...
@@ -315,7 +315,7 @@ void GPBSetHasIvar(GPBMessage *self, int32_t idx, uint32_t fieldNumber,
NSCAssert
(
idx
!=
GPBNoHasBit
,
@"Invalid has bit."
);
uint32_t
*
has_storage
=
self
->
messageStorage_
->
_has_storage_
;
uint32_t
byte
=
idx
/
32
;
uint32_t
bitMask
=
(
1
<<
(
idx
%
32
));
uint32_t
bitMask
=
(
1
U
<<
(
idx
%
32
));
if
(
value
)
{
has_storage
[
byte
]
|=
bitMask
;
}
else
{
...
...
objectivec/GPBUtilities_PackagePrivate.h
View file @
953adb16
...
...
@@ -124,7 +124,7 @@ GPB_INLINE int64_t GPBDecodeZigZag64(uint64_t n) {
// thus always taking 10 bytes on the wire.)
GPB_INLINE
uint32_t
GPBEncodeZigZag32
(
int32_t
n
)
{
// Note: the right-shift must be arithmetic
return
(
uint32_t
)((
n
<<
1
)
^
(
n
>>
31
)
);
return
(
(
uint32_t
)
n
<<
1
)
^
(
uint32_t
)(
n
>>
31
);
}
// Encode a ZigZag-encoded 64-bit value. ZigZag encodes signed integers
...
...
@@ -133,7 +133,7 @@ GPB_INLINE uint32_t GPBEncodeZigZag32(int32_t n) {
// thus always taking 10 bytes on the wire.)
GPB_INLINE
uint64_t
GPBEncodeZigZag64
(
int64_t
n
)
{
// Note: the right-shift must be arithmetic
return
(
uint64_t
)((
n
<<
1
)
^
(
n
>>
63
)
);
return
(
(
uint64_t
)
n
<<
1
)
^
(
uint64_t
)(
n
>>
63
);
}
#pragma clang diagnostic push
...
...
objectivec/Tests/GPBCodedInputStreamTests.m
View file @
953adb16
...
...
@@ -220,7 +220,7 @@
0xa6
,
0x01
)
value
:(
0x1b
<<
0
)
|
(
0x28
<<
7
)
|
(
0x79
<<
14
)
|
(
0x42
<<
21
)
|
(
0x3bLL
<<
28
)
|
(
0x56LL
<<
35
)
|
(
0x00LL
<<
42
)
|
(
0x05LL
<<
49
)
|
(
0x26LL
<<
56
)
|
(
0x01LL
<<
63
)];
(
0x05LL
<<
49
)
|
(
0x26LL
<<
56
)
|
(
0x01
U
LL
<<
63
)];
// Failures
[
self
assertReadVarintFailure
:
bytes
(
0x80
,
0x80
,
0x80
,
0x80
,
0x80
,
0x80
,
0x80
,
...
...
objectivec/Tests/GPBCodedOuputStreamTests.m
View file @
953adb16
...
...
@@ -266,7 +266,7 @@
value
:(
0x1b
<<
0
)
|
(
0x28
<<
7
)
|
(
0x79
<<
14
)
|
(
0x42
<<
21
)
|
(
0x3bLL
<<
28
)
|
(
0x56LL
<<
35
)
|
(
0x00LL
<<
42
)
|
(
0x05LL
<<
49
)
|
(
0x26LL
<<
56
)
|
(
0x01LL
<<
63
)];
(
0x01
U
LL
<<
63
)];
}
-
(
void
)
testWriteLittleEndian
{
...
...
objectivec/Tests/GPBUtilitiesTests.m
View file @
953adb16
...
...
@@ -52,12 +52,12 @@
-
(
void
)
testRightShiftFunctions
{
XCTAssertEqual
((
1UL
<<
31
)
>>
31
,
1UL
);
XCTAssertEqual
((
1
<<
31
)
>>
31
,
-
1
);
XCTAssertEqual
((
int32_t
)(
1U
<<
31
)
>>
31
,
-
1
);
XCTAssertEqual
((
1ULL
<<
63
)
>>
63
,
1ULL
);
XCTAssertEqual
((
1
LL
<<
63
)
>>
63
,
-
1LL
);
XCTAssertEqual
((
int64_t
)(
1U
LL
<<
63
)
>>
63
,
-
1LL
);
XCTAssertEqual
(
GPBLogicalRightShift32
((
1
<<
31
),
31
),
1
);
XCTAssertEqual
(
GPBLogicalRightShift64
((
1LL
<<
63
),
63
),
1LL
);
XCTAssertEqual
(
GPBLogicalRightShift32
((
1
U
<<
31
),
31
),
1
);
XCTAssertEqual
(
GPBLogicalRightShift64
((
1
U
LL
<<
63
),
63
),
1LL
);
}
-
(
void
)
testGPBDecodeTextFormatName
{
...
...
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