Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: src/common/dwarf/bytereader-inl.h

Issue 1605153004: unittests: fix -Wnarrowing build errors (Closed) Base URL: https://chromium.googlesource.com/breakpad/breakpad.git@master
Patch Set: convert to uint8_t Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2006 Google Inc. All Rights Reserved. 1 // Copyright 2006 Google Inc. All Rights Reserved.
2 // 2 //
3 // Redistribution and use in source and binary forms, with or without 3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are 4 // modification, are permitted provided that the following conditions are
5 // met: 5 // met:
6 // 6 //
7 // * Redistributions of source code must retain the above copyright 7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer. 8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above 9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer 10 // copyright notice, this list of conditions and the following disclaimer
(...skipping 17 matching lines...) Expand all
28 28
29 #ifndef UTIL_DEBUGINFO_BYTEREADER_INL_H__ 29 #ifndef UTIL_DEBUGINFO_BYTEREADER_INL_H__
30 #define UTIL_DEBUGINFO_BYTEREADER_INL_H__ 30 #define UTIL_DEBUGINFO_BYTEREADER_INL_H__
31 31
32 #include "common/dwarf/bytereader.h" 32 #include "common/dwarf/bytereader.h"
33 33
34 #include <assert.h> 34 #include <assert.h>
35 35
36 namespace dwarf2reader { 36 namespace dwarf2reader {
37 37
38 inline uint8 ByteReader::ReadOneByte(const char* buffer) const { 38 inline uint8 ByteReader::ReadOneByte(const uint8_t *buffer) const {
39 return buffer[0]; 39 return buffer[0];
40 } 40 }
41 41
42 inline uint16 ByteReader::ReadTwoBytes(const char* signed_buffer) const { 42 inline uint16 ByteReader::ReadTwoBytes(const uint8_t *buffer) const {
43 const unsigned char *buffer
44 = reinterpret_cast<const unsigned char *>(signed_buffer);
45 const uint16 buffer0 = buffer[0]; 43 const uint16 buffer0 = buffer[0];
46 const uint16 buffer1 = buffer[1]; 44 const uint16 buffer1 = buffer[1];
47 if (endian_ == ENDIANNESS_LITTLE) { 45 if (endian_ == ENDIANNESS_LITTLE) {
48 return buffer0 | buffer1 << 8; 46 return buffer0 | buffer1 << 8;
49 } else { 47 } else {
50 return buffer1 | buffer0 << 8; 48 return buffer1 | buffer0 << 8;
51 } 49 }
52 } 50 }
53 51
54 inline uint64 ByteReader::ReadFourBytes(const char* signed_buffer) const { 52 inline uint64 ByteReader::ReadFourBytes(const uint8_t *buffer) const {
55 const unsigned char *buffer
56 = reinterpret_cast<const unsigned char *>(signed_buffer);
57 const uint32 buffer0 = buffer[0]; 53 const uint32 buffer0 = buffer[0];
58 const uint32 buffer1 = buffer[1]; 54 const uint32 buffer1 = buffer[1];
59 const uint32 buffer2 = buffer[2]; 55 const uint32 buffer2 = buffer[2];
60 const uint32 buffer3 = buffer[3]; 56 const uint32 buffer3 = buffer[3];
61 if (endian_ == ENDIANNESS_LITTLE) { 57 if (endian_ == ENDIANNESS_LITTLE) {
62 return buffer0 | buffer1 << 8 | buffer2 << 16 | buffer3 << 24; 58 return buffer0 | buffer1 << 8 | buffer2 << 16 | buffer3 << 24;
63 } else { 59 } else {
64 return buffer3 | buffer2 << 8 | buffer1 << 16 | buffer0 << 24; 60 return buffer3 | buffer2 << 8 | buffer1 << 16 | buffer0 << 24;
65 } 61 }
66 } 62 }
67 63
68 inline uint64 ByteReader::ReadEightBytes(const char* signed_buffer) const { 64 inline uint64 ByteReader::ReadEightBytes(const uint8_t *buffer) const {
69 const unsigned char *buffer
70 = reinterpret_cast<const unsigned char *>(signed_buffer);
71 const uint64 buffer0 = buffer[0]; 65 const uint64 buffer0 = buffer[0];
72 const uint64 buffer1 = buffer[1]; 66 const uint64 buffer1 = buffer[1];
73 const uint64 buffer2 = buffer[2]; 67 const uint64 buffer2 = buffer[2];
74 const uint64 buffer3 = buffer[3]; 68 const uint64 buffer3 = buffer[3];
75 const uint64 buffer4 = buffer[4]; 69 const uint64 buffer4 = buffer[4];
76 const uint64 buffer5 = buffer[5]; 70 const uint64 buffer5 = buffer[5];
77 const uint64 buffer6 = buffer[6]; 71 const uint64 buffer6 = buffer[6];
78 const uint64 buffer7 = buffer[7]; 72 const uint64 buffer7 = buffer[7];
79 if (endian_ == ENDIANNESS_LITTLE) { 73 if (endian_ == ENDIANNESS_LITTLE) {
80 return buffer0 | buffer1 << 8 | buffer2 << 16 | buffer3 << 24 | 74 return buffer0 | buffer1 << 8 | buffer2 << 16 | buffer3 << 24 |
81 buffer4 << 32 | buffer5 << 40 | buffer6 << 48 | buffer7 << 56; 75 buffer4 << 32 | buffer5 << 40 | buffer6 << 48 | buffer7 << 56;
82 } else { 76 } else {
83 return buffer7 | buffer6 << 8 | buffer5 << 16 | buffer4 << 24 | 77 return buffer7 | buffer6 << 8 | buffer5 << 16 | buffer4 << 24 |
84 buffer3 << 32 | buffer2 << 40 | buffer1 << 48 | buffer0 << 56; 78 buffer3 << 32 | buffer2 << 40 | buffer1 << 48 | buffer0 << 56;
85 } 79 }
86 } 80 }
87 81
88 // Read an unsigned LEB128 number. Each byte contains 7 bits of 82 // Read an unsigned LEB128 number. Each byte contains 7 bits of
89 // information, plus one bit saying whether the number continues or 83 // information, plus one bit saying whether the number continues or
90 // not. 84 // not.
91 85
92 inline uint64 ByteReader::ReadUnsignedLEB128(const char* buffer, 86 inline uint64 ByteReader::ReadUnsignedLEB128(const uint8_t *buffer,
93 size_t* len) const { 87 size_t* len) const {
94 uint64 result = 0; 88 uint64 result = 0;
95 size_t num_read = 0; 89 size_t num_read = 0;
96 unsigned int shift = 0; 90 unsigned int shift = 0;
97 unsigned char byte; 91 uint8_t byte;
98 92
99 do { 93 do {
100 byte = *buffer++; 94 byte = *buffer++;
101 num_read++; 95 num_read++;
102 96
103 result |= (static_cast<uint64>(byte & 0x7f)) << shift; 97 result |= (static_cast<uint64>(byte & 0x7f)) << shift;
104 98
105 shift += 7; 99 shift += 7;
106 100
107 } while (byte & 0x80); 101 } while (byte & 0x80);
108 102
109 *len = num_read; 103 *len = num_read;
110 104
111 return result; 105 return result;
112 } 106 }
113 107
114 // Read a signed LEB128 number. These are like regular LEB128 108 // Read a signed LEB128 number. These are like regular LEB128
115 // numbers, except the last byte may have a sign bit set. 109 // numbers, except the last byte may have a sign bit set.
116 110
117 inline int64 ByteReader::ReadSignedLEB128(const char* buffer, 111 inline int64 ByteReader::ReadSignedLEB128(const uint8_t *buffer,
118 size_t* len) const { 112 size_t* len) const {
119 int64 result = 0; 113 int64 result = 0;
120 unsigned int shift = 0; 114 unsigned int shift = 0;
121 size_t num_read = 0; 115 size_t num_read = 0;
122 unsigned char byte; 116 uint8_t byte;
123 117
124 do { 118 do {
125 byte = *buffer++; 119 byte = *buffer++;
126 num_read++; 120 num_read++;
127 result |= (static_cast<uint64>(byte & 0x7f) << shift); 121 result |= (static_cast<uint64>(byte & 0x7f) << shift);
128 shift += 7; 122 shift += 7;
129 } while (byte & 0x80); 123 } while (byte & 0x80);
130 124
131 if ((shift < 8 * sizeof (result)) && (byte & 0x40)) 125 if ((shift < 8 * sizeof (result)) && (byte & 0x40))
132 result |= -((static_cast<int64>(1)) << shift); 126 result |= -((static_cast<int64>(1)) << shift);
133 *len = num_read; 127 *len = num_read;
134 return result; 128 return result;
135 } 129 }
136 130
137 inline uint64 ByteReader::ReadOffset(const char* buffer) const { 131 inline uint64 ByteReader::ReadOffset(const uint8_t *buffer) const {
138 assert(this->offset_reader_); 132 assert(this->offset_reader_);
139 return (this->*offset_reader_)(buffer); 133 return (this->*offset_reader_)(buffer);
140 } 134 }
141 135
142 inline uint64 ByteReader::ReadAddress(const char* buffer) const { 136 inline uint64 ByteReader::ReadAddress(const uint8_t *buffer) const {
143 assert(this->address_reader_); 137 assert(this->address_reader_);
144 return (this->*address_reader_)(buffer); 138 return (this->*address_reader_)(buffer);
145 } 139 }
146 140
147 inline void ByteReader::SetCFIDataBase(uint64 section_base, 141 inline void ByteReader::SetCFIDataBase(uint64 section_base,
148 const char *buffer_base) { 142 const uint8_t *buffer_base) {
149 section_base_ = section_base; 143 section_base_ = section_base;
150 buffer_base_ = buffer_base; 144 buffer_base_ = buffer_base;
151 have_section_base_ = true; 145 have_section_base_ = true;
152 } 146 }
153 147
154 inline void ByteReader::SetTextBase(uint64 text_base) { 148 inline void ByteReader::SetTextBase(uint64 text_base) {
155 text_base_ = text_base; 149 text_base_ = text_base;
156 have_text_base_ = true; 150 have_text_base_ = true;
157 } 151 }
158 152
159 inline void ByteReader::SetDataBase(uint64 data_base) { 153 inline void ByteReader::SetDataBase(uint64 data_base) {
160 data_base_ = data_base; 154 data_base_ = data_base;
161 have_data_base_ = true; 155 have_data_base_ = true;
162 } 156 }
163 157
164 inline void ByteReader::SetFunctionBase(uint64 function_base) { 158 inline void ByteReader::SetFunctionBase(uint64 function_base) {
165 function_base_ = function_base; 159 function_base_ = function_base;
166 have_function_base_ = true; 160 have_function_base_ = true;
167 } 161 }
168 162
169 inline void ByteReader::ClearFunctionBase() { 163 inline void ByteReader::ClearFunctionBase() {
170 have_function_base_ = false; 164 have_function_base_ = false;
171 } 165 }
172 166
173 } // namespace dwarf2reader 167 } // namespace dwarf2reader
174 168
175 #endif // UTIL_DEBUGINFO_BYTEREADER_INL_H__ 169 #endif // UTIL_DEBUGINFO_BYTEREADER_INL_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698