From: Hwankyu Jhun Date: Wed, 16 Sep 2020 05:54:47 +0000 (+0900) Subject: Fix bundle_decode_raw() implementaion X-Git-Tag: submit/tizen/20200916.062312~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b14812d536b28b75a25bc86dd8df7e95c58980df;p=platform%2Fcore%2Fbase%2Fbundle.git Fix bundle_decode_raw() implementaion Change-Id: Id27bff120336ab6b24cbd564060f529eef85baad Signed-off-by: Hwankyu Jhun --- diff --git a/src/bundle-internal.cc b/src/bundle-internal.cc index 2298412..55c2181 100644 --- a/src/bundle-internal.cc +++ b/src/bundle-internal.cc @@ -31,8 +31,12 @@ static const int CHECKSUM_LENGTH = 32; Bundle::Bundle() = default; -Bundle::Bundle(unsigned char* raw, int size) { - int ret = Decode(raw, size); +Bundle::Bundle(unsigned char* raw, int size, bool base64) { + int ret; + if (base64) + ret = Decode(raw, size); + else + ret = DecodeRaw(raw, size); if (ret != BUNDLE_ERROR_NONE) THROW(ret); } diff --git a/src/bundle-internal.h b/src/bundle-internal.h index 73f55d0..136458a 100644 --- a/src/bundle-internal.h +++ b/src/bundle-internal.h @@ -50,7 +50,7 @@ class Bundle { }; Bundle(); - Bundle(unsigned char* raw, int size); + Bundle(unsigned char* raw, int size, bool base64 = true); Bundle(int argc, char** argv); virtual ~Bundle(); diff --git a/src/stub.cc b/src/stub.cc index 7bf991a..0c22e5e 100644 --- a/src/stub.cc +++ b/src/stub.cc @@ -369,21 +369,20 @@ extern "C" EXPORT_API bundle* bundle_decode_raw(const bundle_raw* r, return nullptr; } - bundle* b = bundle_create(); - if (b == nullptr) + Bundle* b = nullptr; + try { + auto* raw = const_cast(r); + b = new Bundle(static_cast(raw), data_size, false); + } catch (Exception& e) { + set_last_result(e.GetErrorCode()); return nullptr; - - auto* h = reinterpret_cast(b); - auto* raw = const_cast(r); - int ret = h->DecodeRaw(static_cast(raw), data_size); - if (ret != BUNDLE_ERROR_NONE) { - bundle_free(b); - set_last_result(ret); + } catch (const std::bad_alloc& ba) { + set_last_result(BUNDLE_ERROR_OUT_OF_MEMORY); return nullptr; } set_last_result(BUNDLE_ERROR_NONE); - return b; + return reinterpret_cast(b); } extern "C" EXPORT_API int bundle_get_type(bundle* b, const char* key) {