From 01c6a443586f81d07f0b05bd09b11a5406d28b81 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Tue, 5 Oct 2021 19:25:09 +0000 Subject: [PATCH] dawn_node: Fixes for GPU.cpp Check the result of std::getenv() before constructing a std::string. std::string cannot be constructed with nullptr. Fix ambiguous overload resolution of std::tolower(), by wrapping it in a lambda that explicitly takes a 'char' argument. Bug: dawn:1123 Change-Id: I8a44524a6c0e71f7d2a49a5a9f730115c32df577 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/65960 Reviewed-by: Antonio Maiorano Commit-Queue: Ben Clayton --- src/dawn_node/binding/GPU.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/dawn_node/binding/GPU.cpp b/src/dawn_node/binding/GPU.cpp index c4ba2a328b..cf22465ec3 100644 --- a/src/dawn_node/binding/GPU.cpp +++ b/src/dawn_node/binding/GPU.cpp @@ -31,7 +31,10 @@ namespace { } return ""; #else - return std::getenv(varName); + if (auto* val = std::getenv(varName)) { + return val; + } + return ""; #endif } } // namespace @@ -81,7 +84,8 @@ namespace wgpu { namespace binding { // Check for override from env var std::string envVar = getEnvVar("DAWNNODE_BACKEND"); - std::transform(envVar.begin(), envVar.end(), envVar.begin(), std::tolower); + std::transform(envVar.begin(), envVar.end(), envVar.begin(), + [](char c) { return std::tolower(c); }); if (envVar == "null") { targetBackendType = wgpu::BackendType::Null; } else if (envVar == "webgpu") {