mirror of
https://github.com/chromium/crashpad.git
synced 2024-12-31 01:43:03 +08:00
15103742e0
I opted to leave casts to types that were definitely the same size alone. reinterpret_cast<uintptr_t>(pointer) and reinterpret_cast<intptr_t>(pointer) should always be safe, for example. Casts to other integral types have been replaced with FromPointerCast<>(), which does zero-extension or sign-extension based on the target type. To make it possible to use FromPointerCast<>() with some use sites that were already using checked_cast<>(), FromPointerCast<>() now uses check_cast<>() when converting to a narrower type. Test: crashpad_util_test FromPointerCast*, others Change-Id: I4a71b4aa2d87f545c75524290a702f5f3138d675 Reviewed-on: https://chromium-review.googlesource.com/489701 Reviewed-by: Scott Graham <scottmg@chromium.org>
38 lines
1.2 KiB
C++
38 lines
1.2 KiB
C++
// Copyright 2015 The Crashpad Authors. All rights reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#include "util/win/handle.h"
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "base/numerics/safe_conversions.h"
|
|
#include "util/misc/from_pointer_cast.h"
|
|
|
|
namespace crashpad {
|
|
|
|
// These functions use “int” for the 32-bit integer handle type because
|
|
// sign-extension needs to work correctly. INVALID_HANDLE_VALUE is defined as
|
|
// ((HANDLE)(LONG_PTR)-1), and this needs to round-trip through an integer and
|
|
// back to the same HANDLE value.
|
|
|
|
int HandleToInt(HANDLE handle) {
|
|
return FromPointerCast<int>(handle);
|
|
}
|
|
|
|
HANDLE IntToHandle(int handle_int) {
|
|
return reinterpret_cast<HANDLE>(static_cast<intptr_t>(handle_int));
|
|
}
|
|
|
|
} // namespace crashpad
|