Codebase list mozc / 204cfd9
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
3 changed file(s) with 18 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
00 MAJOR=2
11 MINOR=17
2 BUILD=2487
2 BUILD=2488
33 REVISION=102
44 # NACL_DICTIONARY_VERSION is the target version of the system dictionary to be
55 # downloaded by NaCl Mozc.
173173 if (g_context_revision_tls_index == kInvalidTlsIndex) {
174174 return 0;
175175 }
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);
179179 }
180180
181181 void IncrementContextRevision() {
182182 if (g_context_revision_tls_index == kInvalidTlsIndex) {
183183 return;
184184 }
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));
187194 }
188195
189196 void FillContext(HIMC himc, mozc::commands::Context *context) {
8686 }
8787
8888 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 }
9094 }
9195
9296 } // namespace tsf