Repository: microsoft/terminal
File: src/inc/til/env.h (C/C++)

Code before:
                    std::wstring valueName;
                    std::basic_string<BYTE> valueData;
                    valueName.resize(maxValueNameSize);
                    valueData.resize(maxValueDataSize);

                    for (DWORD pass = 0; pass < 2; ++pass)
                    {
                        DWORD valueNameSize = maxValueNameSize;
                        DWORD valueDataSize = maxValueDataSize;

                        DWORD index = 0;
                        DWORD type = 0;

                        while (true)
                        {
                            const DWORD result = RegEnumValueW(key.get(), index, valueName.data(), &valueNameSize, nullptr, &type, valueData.data(), &valueDataSize);
                            if (result != ERROR_SUCCESS)
                            {
                                break;
                            }
                            valueName.resize(valueNameSize);
                            valueData.resize(valueDataSize);

                            if (valueNameSize)
                            {
                                bool isPathVar = is_path_var(valueName);

                                // On some systems we've seen path variables that are REG_SZ instead
                                // of REG_EXPAND_SZ. We should always treat them as REG_EXPAND_SZ.
                                if (isPathVar && type == REG_SZ)
                                {
                                    type = REG_EXPAND_SZ;
                                }

                                std::wstring data;
                                if (pass == 0 && (type == REG_SZ) && valueDataSize >= sizeof(wchar_t))
                                {
                                    data = {
                                        reinterpret_cast<wchar_t*>(valueData.data()), valueData.size() / sizeof(wchar_t)
                                    };
                                }
                                else if (pass == 1 && (type == REG_EXPAND_SZ) && valueDataSize >= sizeof(wchar_t))
                                {
                                    data = {
                                        reinterpret_cast<wchar_t*>(valueData.data()), valueData.size() / sizeof(wchar_t)
                                    };
                                    data = expand_environment_strings(data.data());
                                }

                                // Because Registry data may or may not be null terminated... check if we've managed
                                // to store an extra null in the wstring by telling it to create itself from pointer and size.

Review comment (suggestion):
```suggestion
                                const bool isPathVar = is_path_var(valueName);
```

apparently static analysis got mad at this one

Code after:
                    std::wstring valueName;
                    std::basic_string<BYTE> valueData;
                    valueName.resize(maxValueNameSize);
                    valueData.resize(maxValueDataSize);

                    for (DWORD pass = 0; pass < 2; ++pass)
                    {
                        DWORD valueNameSize = maxValueNameSize;
                        DWORD valueDataSize = maxValueDataSize;

                        DWORD index = 0;
                        DWORD type = 0;

                        while (true)
                        {
                            const DWORD result = RegEnumValueW(key.get(), index, valueName.data(), &valueNameSize, nullptr, &type, valueData.data(), &valueDataSize);
                            if (result != ERROR_SUCCESS)
                            {
                                break;
                            }
                            valueName.resize(valueNameSize);
                            valueData.resize(valueDataSize);

                            if (valueNameSize)
                            {
                                const bool isPathVar = is_path_var(valueName);

                                // On some systems we've seen path variables that are REG_SZ instead
                                // of REG_EXPAND_SZ. We should always treat them as REG_EXPAND_SZ.
                                if (isPathVar && type == REG_SZ)
                                {
                                    type = REG_EXPAND_SZ;
                                }

                                std::wstring data;
                                if (pass == 0 && (type == REG_SZ) && valueDataSize >= sizeof(wchar_t))
                                {
                                    data = {
                                        reinterpret_cast<wchar_t*>(valueData.data()), valueData.size() / sizeof(wchar_t)
                                    };
                                }
                                else if (pass == 1 && (type == REG_EXPAND_SZ) && valueDataSize >= sizeof(wchar_t))
                                {
                                    data = {
                                        reinterpret_cast<wchar_t*>(valueData.data()), valueData.size() / sizeof(wchar_t)
                                    };
                                    data = expand_environment_strings(data.data());
                                }

                                // Because Registry data may or may not be null terminated... check if we've managed
                                // to store an extra null in the wstring by telling it to create itself from pointer and size.