Fix warning around focus revision handlings
This CL addresses the following warnigns:
- warning C4302:
'reinterpret_cast': truncation from 'LPVOID' to 'int32'
- warning C4311:
'reinterpret_cast': pointer truncation from 'LPVOID' to 'int32'
- warning C4312:
'reinterpret_cast': conversion from 'const int32' to 'void *' of
greater size
This CL also takes care of signed integer overflow, when incrementing
the focus revision, which is one of well-known undefined behaviour in
C++.
Note that in practice we do not depend on the order of the focus
revision in mozc_server. Hence probably this has not been an issue
though unless the overflow results in runtime exceptions.
BUG=#315
TEST=
REF_BUG=26932823
REF_CL=114661183
REF_TIME=2016-02-14T20:31:43-08:00
REF_TIME_RAW=1455510703 -0800
Yohei Yukawa
8 years ago
0 | 0 |
MAJOR=2
|
1 | 1 |
MINOR=17
|
2 | |
BUILD=2487
|
|
2 |
BUILD=2488
|
3 | 3 |
REVISION=102
|
4 | 4 |
# NACL_DICTIONARY_VERSION is the target version of the system dictionary to be
|
5 | 5 |
# downloaded by NaCl Mozc.
|
173 | 173 |
if (g_context_revision_tls_index == kInvalidTlsIndex) {
|
174 | 174 |
return 0;
|
175 | 175 |
}
|
176 | |
const int32 revision =
|
177 | |
reinterpret_cast<int32>(::TlsGetValue(g_context_revision_tls_index));
|
178 | |
return revision;
|
|
176 |
const uintptr_t raw_value = reinterpret_cast<uintptr_t>(
|
|
177 |
::TlsGetValue(g_context_revision_tls_index));
|
|
178 |
return static_cast<int32>(raw_value);
|
179 | 179 |
}
|
180 | 180 |
|
181 | 181 |
void IncrementContextRevision() {
|
182 | 182 |
if (g_context_revision_tls_index == kInvalidTlsIndex) {
|
183 | 183 |
return;
|
184 | 184 |
}
|
185 | |
const int32 next_age = GetContextRevision() + 1;
|
186 | |
TlsSetValue(g_context_revision_tls_index, reinterpret_cast<void *>(next_age));
|
|
185 |
int32 revision = GetContextRevision();
|
|
186 |
if (revision < kint32max) {
|
|
187 |
++revision;
|
|
188 |
} else {
|
|
189 |
revision = 0;
|
|
190 |
}
|
|
191 |
const uintptr_t raw_value = static_cast<uintptr_t>(revision);
|
|
192 |
::TlsSetValue(g_context_revision_tls_index,
|
|
193 |
reinterpret_cast<void *>(raw_value));
|
187 | 194 |
}
|
188 | 195 |
|
189 | 196 |
void FillContext(HIMC himc, mozc::commands::Context *context) {
|
86 | 86 |
}
|
87 | 87 |
|
88 | 88 |
void TipThreadContext::IncrementFocusRevision() {
|
89 | |
++state_->focus_revision;
|
|
89 |
if (state_->focus_revision < kint32max) {
|
|
90 |
state_->focus_revision++;
|
|
91 |
} else {
|
|
92 |
state_->focus_revision = 0;
|
|
93 |
}
|
90 | 94 |
}
|
91 | 95 |
|
92 | 96 |
} // namespace tsf
|