diff options
| author | msherbakov <[email protected]> | 2022-02-10 16:49:16 +0300 | 
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:49:16 +0300 | 
| commit | c224a621661ddd69699f9476922eb316607ef57e (patch) | |
| tree | 33f4d878aa0a9faa964005e06bfab0272313aa71 /library/cpp/json | |
| parent | 29d0b2eeae154d04156e0698067c0c21a97ea61d (diff) | |
Restoring authorship annotation for <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/json')
| -rw-r--r-- | library/cpp/json/writer/json.cpp | 2 | ||||
| -rw-r--r-- | library/cpp/json/writer/json_ut.cpp | 80 | 
2 files changed, 41 insertions, 41 deletions
| diff --git a/library/cpp/json/writer/json.cpp b/library/cpp/json/writer/json.cpp index 02370c2d79e..fcc2980f9be 100644 --- a/library/cpp/json/writer/json.cpp +++ b/library/cpp/json/writer/json.cpp @@ -221,7 +221,7 @@ namespace NJsonWriter {      TValueContext TBuf::WriteBool(bool b) {          constexpr TStringBuf trueVal = "true";          constexpr TStringBuf falseVal = "false"; -        UnsafeWriteValue(b ? trueVal : falseVal); +        UnsafeWriteValue(b ? trueVal : falseVal);           return TValueContext(*this);      } diff --git a/library/cpp/json/writer/json_ut.cpp b/library/cpp/json/writer/json_ut.cpp index 9980555683f..d5ee4ff1c34 100644 --- a/library/cpp/json/writer/json_ut.cpp +++ b/library/cpp/json/writer/json_ut.cpp @@ -1,5 +1,5 @@  #include <library/cpp/testing/unittest/registar.h> -#include <util/system/sanitizers.h> +#include <util/system/sanitizers.h>   #include "json.h"  #include <library/cpp/json/json_value.h> @@ -265,43 +265,43 @@ Y_UNIT_TEST_SUITE(JsonWriter) {              UNIT_ASSERT_STRINGS_EQUAL(buf.Str(), R"({"\u003C\u003E&":"Ololo","<>&":"Ololo2"})");          }      } - -    Y_UNIT_TEST(WriteUninitializedBoolDoesntCrashProgram) { -        // makes sense only in release build w/ address sanitizer -        // -        // passing uninitialized boolean into WriteBool can make cleverly optimized code which is emitted by compiler crash program -        // https://stackoverflow.com/questions/54120862/does-the-c-standard-allow-for-an-uninitialized-bool-to-crash-a-program - -        // looks like compiler can detect UB at compile time in simple cases, but not in this one -        class  TSensorConf { -        public: -            class TAggrRuleItem { -            public: -                TVector<TString> Cond; -                TVector<TString> Target; -            }; - -            TString ToString() const { -                NJson::TJsonValue jsonValue; -                NJsonWriter::TBuf jsonOutput; -                jsonOutput.BeginObject() -                    .WriteKey("rawDataMemOnly").WriteBool(RawDataMemOnly) -                    .WriteKey("aggrRules").BeginList(); - -                jsonOutput.EndList() -                    .EndObject(); - -                return jsonOutput.Str(); -            } - -            TVector<TAggrRuleItem> AggrRules; -            bool RawDataMemOnly; -        }; - -        TSensorConf s; -        NSan::Unpoison(&s.RawDataMemOnly, sizeof(s.RawDataMemOnly)); -        auto p = s.ToString(); -        // doesn't really matter -        UNIT_ASSERT(!p.empty()); -    } +  +    Y_UNIT_TEST(WriteUninitializedBoolDoesntCrashProgram) {  +        // makes sense only in release build w/ address sanitizer  +        //  +        // passing uninitialized boolean into WriteBool can make cleverly optimized code which is emitted by compiler crash program  +        // https://stackoverflow.com/questions/54120862/does-the-c-standard-allow-for-an-uninitialized-bool-to-crash-a-program  +  +        // looks like compiler can detect UB at compile time in simple cases, but not in this one  +        class  TSensorConf {  +        public:  +            class TAggrRuleItem {  +            public:  +                TVector<TString> Cond;  +                TVector<TString> Target;  +            };  +  +            TString ToString() const {  +                NJson::TJsonValue jsonValue;  +                NJsonWriter::TBuf jsonOutput;  +                jsonOutput.BeginObject()  +                    .WriteKey("rawDataMemOnly").WriteBool(RawDataMemOnly)  +                    .WriteKey("aggrRules").BeginList();  +  +                jsonOutput.EndList()  +                    .EndObject();  +  +                return jsonOutput.Str();  +            }  +  +            TVector<TAggrRuleItem> AggrRules;  +            bool RawDataMemOnly;  +        };  +  +        TSensorConf s;  +        NSan::Unpoison(&s.RawDataMemOnly, sizeof(s.RawDataMemOnly));  +        auto p = s.ToString();  +        // doesn't really matter  +        UNIT_ASSERT(!p.empty());  +    }   } | 
