From 3426bed67e74e8aacbff383cc638b371f71ce43f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D1=80=D0=B8=D0=B3=D0=BE=D1=80=D1=8C=D0=B5=D0=B2=20?= =?UTF-8?q?=D0=9A=D0=BE=D1=81=D1=82=D1=8F?= Date: Wed, 1 Feb 2023 10:18:29 +0000 Subject: [PATCH 1/4] changed dict in stamp constructor from reference to shared ptr --- blobstamper/stamp_dict.cpp | 14 +++++++------- blobstamper/stamp_dict.h | 13 ++++++++++--- examples/exampleZZ.cpp | 2 +- t/120-stamp_dict.cpp | 2 +- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/blobstamper/stamp_dict.cpp b/blobstamper/stamp_dict.cpp index fa5a085..c51dbc4 100644 --- a/blobstamper/stamp_dict.cpp +++ b/blobstamper/stamp_dict.cpp @@ -22,19 +22,19 @@ #include "stamp_dict.h" int -StampDict::ChooseStampSize(DictBase & dict) +StampDict::ChooseStampSize(std::shared_ptr dict) { - if (dict.size()<= UCHAR_MAX+1) + if (dict->size()<= UCHAR_MAX+1) { stamp_max_value = UCHAR_MAX; return 1; } - if (dict.size()<= USHRT_MAX+1) + if (dict->size()<= USHRT_MAX+1) { stamp_max_value = USHRT_MAX; return 2; } - if (dict.size()<= UINT_MAX+1) + if (dict->size()<= UINT_MAX+1) { stamp_max_value = UINT_MAX; return 4; @@ -75,7 +75,7 @@ StampDict::ExtractStr(Blob &blob) printf("StampDict::ExtractStr: Something is really wrong\n"); // FIXME better to throw something here :-) exit(1); } - long long actual_index = ((double) index_oracle) / stamp_max_value * dict.size(); - if ( actual_index == dict.size()) actual_index--; /* If we hit the boundary step inside a bit*/ - return dict.get(actual_index); + long long actual_index = ((double) index_oracle) / stamp_max_value * dict->size(); + if ( actual_index == dict->size()) actual_index--; /* If we hit the boundary step inside a bit*/ + return dict->get(actual_index); } diff --git a/blobstamper/stamp_dict.h b/blobstamper/stamp_dict.h index 308050b..f4b80d8 100644 --- a/blobstamper/stamp_dict.h +++ b/blobstamper/stamp_dict.h @@ -25,6 +25,7 @@ #include "stamp.h" #include "stamp_arithm.h" #include "dict.h" +#include class StampDict: public StampBaseStr { @@ -34,16 +35,22 @@ class StampDict: public StampBaseStr StampArithm stamp32; StampArithm stamp64; int stamp_size; - DictBase& dict; + std::shared_ptr dict; unsigned long long stamp_max_value; - int ChooseStampSize(DictBase & dict); + int ChooseStampSize(std::shared_ptr dict); public: - StampDict(DictBase & dict_arg) : dict{dict_arg}, stamp_size{ChooseStampSize(dict_arg)} {}; + StampDict(std::shared_ptr dict_arg) : dict(dict_arg), stamp_size(ChooseStampSize(dict_arg)) {}; std::string ExtractStr(Blob &blob) override; int minSize() override {return stamp_size;} int maxSize() override {return stamp_size;} }; +class StampDictLCAlphaSmall : public StampDict +{ + public: + StampDictLCAlphaSmall (): StampDict(std::make_shared()) {}; +}; + #endif /* STAMP_DICT_H */ diff --git a/examples/exampleZZ.cpp b/examples/exampleZZ.cpp index 382b561..28c8bf2 100644 --- a/examples/exampleZZ.cpp +++ b/examples/exampleZZ.cpp @@ -54,7 +54,7 @@ char data[] = StampArithm stampс; - DictLCAlphaSmall dict; + auto dict = std::make_shared(); StampDict stamp_dict(dict); StampLottery4Recursion stamp_lot({stampс, stamp_dict}); diff --git a/t/120-stamp_dict.cpp b/t/120-stamp_dict.cpp index 5e32040..670b64c 100644 --- a/t/120-stamp_dict.cpp +++ b/t/120-stamp_dict.cpp @@ -48,7 +48,7 @@ main() { TEST_START(4); { /* 1..4 */ - DictTest dict; + auto dict = std::make_shared(); StampDict stamp(dict); Blob blob((char *) sample, 4); std::string s; From ee9d5d385ca311d69f347dbf65af6731aad86db0 Mon Sep 17 00:00:00 2001 From: nataraj-hates-MS-for-stealing-github <48326335+nataraj-hates-MS-for-stealing-github@users.noreply.github.com> Date: Thu, 2 Feb 2023 10:47:25 +0300 Subject: [PATCH 2/4] fix spaces --- blobstamper/stamp_dict.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/blobstamper/stamp_dict.cpp b/blobstamper/stamp_dict.cpp index c51dbc4..fcec9e0 100644 --- a/blobstamper/stamp_dict.cpp +++ b/blobstamper/stamp_dict.cpp @@ -24,17 +24,17 @@ int StampDict::ChooseStampSize(std::shared_ptr dict) { - if (dict->size()<= UCHAR_MAX+1) + if (dict->size() <= UCHAR_MAX+1) { stamp_max_value = UCHAR_MAX; return 1; } - if (dict->size()<= USHRT_MAX+1) + if (dict->size() <= USHRT_MAX+1) { stamp_max_value = USHRT_MAX; return 2; } - if (dict->size()<= UINT_MAX+1) + if (dict->size() <= UINT_MAX+1) { stamp_max_value = UINT_MAX; return 4; From aa6d118239db849c113de67290f292eeea4d8d95 Mon Sep 17 00:00:00 2001 From: nataraj-hates-MS-for-stealing-github <48326335+nataraj-hates-MS-for-stealing-github@users.noreply.github.com> Date: Thu, 2 Feb 2023 10:51:46 +0300 Subject: [PATCH 3/4] Removed StampDictLCAlphaSmall class declaration, as it is not part of shared_ptr issue --- blobstamper/stamp_dict.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/blobstamper/stamp_dict.h b/blobstamper/stamp_dict.h index f4b80d8..52cd870 100644 --- a/blobstamper/stamp_dict.h +++ b/blobstamper/stamp_dict.h @@ -47,10 +47,5 @@ class StampDict: public StampBaseStr int maxSize() override {return stamp_size;} }; -class StampDictLCAlphaSmall : public StampDict -{ - public: - StampDictLCAlphaSmall (): StampDict(std::make_shared()) {}; -}; #endif /* STAMP_DICT_H */ From 38af0bcceba1db30d7bd60f919272a3b57a35934 Mon Sep 17 00:00:00 2001 From: nataraj-hates-MS-for-stealing-github <48326335+nataraj-hates-MS-for-stealing-github@users.noreply.github.com> Date: Thu, 2 Feb 2023 10:52:28 +0300 Subject: [PATCH 4/4] Removed extra new line --- blobstamper/stamp_dict.h | 1 - 1 file changed, 1 deletion(-) diff --git a/blobstamper/stamp_dict.h b/blobstamper/stamp_dict.h index 52cd870..49408db 100644 --- a/blobstamper/stamp_dict.h +++ b/blobstamper/stamp_dict.h @@ -47,5 +47,4 @@ class StampDict: public StampBaseStr int maxSize() override {return stamp_size;} }; - #endif /* STAMP_DICT_H */