From 01d54380acba0ef907d8a265f7e0155d4c59bbee Mon Sep 17 00:00:00 2001 From: Rahul Sheth Date: Fri, 10 Jul 2020 14:27:37 -0400 Subject: [PATCH 1/2] Use std::string instead of const char* for GetKey function --- tiny_gltf.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index b2c76b9..d6b82a9 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -3000,7 +3000,9 @@ json_const_iterator ObjectEnd(const json &o) { #endif } -const char *GetKey(json_const_iterator &it) { +// Making this a const char* results in a pointer to a temporary when +// TINYGLTF_USE_RAPIDJSON is off. +std::string GetKey(json_const_iterator &it) { #ifdef TINYGLTF_USE_RAPIDJSON return it->name.GetString(); #else From 96a8b2c69b04a49dc70920d02dcc48e7135be44d Mon Sep 17 00:00:00 2001 From: Rahul Sheth Date: Fri, 10 Jul 2020 14:27:46 -0400 Subject: [PATCH 2/2] Run clang-format --- tiny_gltf.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index d6b82a9..de80a1f 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -1253,7 +1253,8 @@ struct FsCallbacks { bool FileExists(const std::string &abs_filename, void *); /// -/// Expand file path(e.g. `~` to home directory on posix, `%APPDATA%` to `C:\Users\tinygltf\AppData`) +/// Expand file path(e.g. `~` to home directory on posix, `%APPDATA%` to +/// `C:\Users\tinygltf\AppData`) /// /// @param[in] filepath File path string. Assume UTF-8 /// @param[in] userdata User data. Set to `nullptr` if you don't need it. @@ -2495,7 +2496,7 @@ static inline std::wstring UTF8ToWchar(const std::string &str) { static inline std::string WcharToUTF8(const std::wstring &wstr) { int str_size = WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.size(), - nullptr, 0, NULL, NULL); + nullptr, 0, NULL, NULL); std::string str(str_size, 0); WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.size(), &str[0], (int)str.size(), NULL, NULL); @@ -2638,7 +2639,8 @@ bool ReadWholeFile(std::vector *out, std::string *err, __gnu_cxx::stdio_filebuf wfile_buf(file_descriptor, std::ios_base::in); std::istream f(&wfile_buf); #elif defined(_MSC_VER) || defined(_LIBCPP_VERSION) - // For libcxx, assume _LIBCPP_HAS_OPEN_WITH_WCHAR is defined to accept `wchar_t *` + // For libcxx, assume _LIBCPP_HAS_OPEN_WITH_WCHAR is defined to accept + // `wchar_t *` std::ifstream f(UTF8ToWchar(filepath).c_str(), std::ifstream::binary); #else // Unknown compiler/runtime @@ -7345,8 +7347,9 @@ static void SerializeGltfModel(Model *model, json &o) { // Also add "KHR_lights_punctual" to `extensionsUsed` { - auto has_khr_lights_punctual = std::find_if( - extensionsUsed.begin(), extensionsUsed.end(), [](const std::string &s) { + auto has_khr_lights_punctual = + std::find_if(extensionsUsed.begin(), extensionsUsed.end(), + [](const std::string &s) { return (s.compare("KHR_lights_punctual") == 0); });