diff options
author | swarmer <swarmer@yandex-team.com> | 2025-03-15 02:13:05 +0300 |
---|---|---|
committer | swarmer <swarmer@yandex-team.com> | 2025-03-15 02:27:03 +0300 |
commit | 2ff6c17bf66cd3580cf4f4746870518f071864d6 (patch) | |
tree | 52c07b345a576c0f29c1f8df66fa413ac5a04c9e /library/cpp | |
parent | b3a7e645ed5b602b647e2ba73b4a01c20912f9bf (diff) | |
download | ydb-2ff6c17bf66cd3580cf4f4746870518f071864d6.tar.gz |
annotate TJsonValue's methods with a lifetime bound attribute
Check that the strings and dictionaries owned by TJsonValue are not accessed after the destruction of the TJsonValue instance itself.
commit_hash:0ed6d84f28681d3f9d8c0fe7080bd7a5dd183919
Diffstat (limited to 'library/cpp')
-rw-r--r-- | library/cpp/json/writer/json_value.h | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/library/cpp/json/writer/json_value.h b/library/cpp/json/writer/json_value.h index 80aa59b985c..4a57c536826 100644 --- a/library/cpp/json/writer/json_value.h +++ b/library/cpp/json/writer/json_value.h @@ -8,6 +8,7 @@ #include <util/generic/deque.h> #include <util/generic/utility.h> #include <util/generic/yexception.h> +#include <util/system/compiler.h> namespace NJson { enum EJsonValueType { @@ -62,67 +63,67 @@ namespace NJson { TJsonValue(const TJsonValue& vval); TJsonValue(TJsonValue&& vval) noexcept; - TJsonValue& operator=(const TJsonValue& val); - TJsonValue& operator=(TJsonValue&& val) noexcept; + TJsonValue& operator=(const TJsonValue& val) Y_LIFETIME_BOUND; + TJsonValue& operator=(TJsonValue&& val) noexcept Y_LIFETIME_BOUND; ~TJsonValue() { Clear(); } EJsonValueType GetType() const noexcept; - TJsonValue& SetType(EJsonValueType type); + TJsonValue& SetType(EJsonValueType type) Y_LIFETIME_BOUND; - TJsonValue& SetValue(const TJsonValue& value); - TJsonValue& SetValue(TJsonValue&& value); + TJsonValue& SetValue(const TJsonValue& value) Y_LIFETIME_BOUND; + TJsonValue& SetValue(TJsonValue&& value) Y_LIFETIME_BOUND; // for Map - TJsonValue& InsertValue(const TString& key, const TJsonValue& value); - TJsonValue& InsertValue(TStringBuf key, const TJsonValue& value); - TJsonValue& InsertValue(const char* key, const TJsonValue& value); - TJsonValue& InsertValue(const TString& key, TJsonValue&& value); - TJsonValue& InsertValue(TStringBuf key, TJsonValue&& value); - TJsonValue& InsertValue(const char* key, TJsonValue&& value); + TJsonValue& InsertValue(const TString& key, const TJsonValue& value) Y_LIFETIME_BOUND; + TJsonValue& InsertValue(TStringBuf key, const TJsonValue& value) Y_LIFETIME_BOUND; + TJsonValue& InsertValue(const char* key, const TJsonValue& value) Y_LIFETIME_BOUND; + TJsonValue& InsertValue(const TString& key, TJsonValue&& value) Y_LIFETIME_BOUND; + TJsonValue& InsertValue(TStringBuf key, TJsonValue&& value) Y_LIFETIME_BOUND; + TJsonValue& InsertValue(const char* key, TJsonValue&& value) Y_LIFETIME_BOUND; // for Array - TJsonValue& AppendValue(const TJsonValue& value); - TJsonValue& AppendValue(TJsonValue&& value); - TJsonValue& Back(); - const TJsonValue& Back() const; + TJsonValue& AppendValue(const TJsonValue& value) Y_LIFETIME_BOUND; + TJsonValue& AppendValue(TJsonValue&& value) Y_LIFETIME_BOUND; + TJsonValue& Back() Y_LIFETIME_BOUND; + const TJsonValue& Back() const Y_LIFETIME_BOUND; bool GetValueByPath(TStringBuf path, TJsonValue& result, char delimiter = '.') const; bool SetValueByPath(TStringBuf path, const TJsonValue& value, char delimiter = '.'); bool SetValueByPath(TStringBuf path, TJsonValue&& value, char delimiter = '.'); // returns NULL on failure - const TJsonValue* GetValueByPath(TStringBuf path, char delimiter = '.') const noexcept; - TJsonValue* GetValueByPath(TStringBuf path, char delimiter = '.') noexcept; + const TJsonValue* GetValueByPath(TStringBuf path, char delimiter = '.') const noexcept Y_LIFETIME_BOUND; + TJsonValue* GetValueByPath(TStringBuf path, char delimiter = '.') noexcept Y_LIFETIME_BOUND; void EraseValue(TStringBuf key); void EraseValue(size_t index); - TJsonValue& operator[](size_t idx); - TJsonValue& operator[](const TStringBuf& key); - const TJsonValue& operator[](size_t idx) const noexcept; - const TJsonValue& operator[](const TStringBuf& key) const noexcept; + TJsonValue& operator[](size_t idx) Y_LIFETIME_BOUND; + TJsonValue& operator[](const TStringBuf& key) Y_LIFETIME_BOUND; + const TJsonValue& operator[](size_t idx) const noexcept Y_LIFETIME_BOUND; + const TJsonValue& operator[](const TStringBuf& key) const noexcept Y_LIFETIME_BOUND; bool GetBoolean() const; long long GetInteger() const; unsigned long long GetUInteger() const; double GetDouble() const; - const TString& GetString() const; - const TMapType& GetMap() const; - const TArray& GetArray() const; + const TString& GetString() const Y_LIFETIME_BOUND; + const TMapType& GetMap() const Y_LIFETIME_BOUND; + const TArray& GetArray() const Y_LIFETIME_BOUND; //throwing TJsonException possible bool GetBooleanSafe() const; long long GetIntegerSafe() const; unsigned long long GetUIntegerSafe() const; double GetDoubleSafe() const; - const TString& GetStringSafe() const; - const TMapType& GetMapSafe() const; - TMapType& GetMapSafe(); - const TArray& GetArraySafe() const; - TArray& GetArraySafe(); + const TString& GetStringSafe() const Y_LIFETIME_BOUND; + const TMapType& GetMapSafe() const Y_LIFETIME_BOUND; + TMapType& GetMapSafe() Y_LIFETIME_BOUND; + const TArray& GetArraySafe() const Y_LIFETIME_BOUND; + TArray& GetArraySafe() Y_LIFETIME_BOUND; bool GetBooleanSafe(bool defaultValue) const; long long GetIntegerSafe(long long defaultValue) const; |