• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SAFE_ACCESS_H_
6 #define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SAFE_ACCESS_H_
7 
8 #include <type_traits>
9 
10 #define SAFE_ACCESS(pointer, member, default_value)                      \
11   ([=]() {                                                               \
12     if (offsetof(std::remove_pointer<decltype(pointer)>::type, member) + \
13             sizeof(pointer->member) <=                                   \
14         pointer->struct_size) {                                          \
15       return pointer->member;                                            \
16     }                                                                    \
17     return static_cast<decltype(pointer->member)>((default_value));      \
18   })()
19 
20 #endif  // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SAFE_ACCESS_H_
21