Fix bundle_decode_raw() implementaion 20/244220/1
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 16 Sep 2020 05:54:47 +0000 (14:54 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 16 Sep 2020 05:54:47 +0000 (14:54 +0900)
Change-Id: Id27bff120336ab6b24cbd564060f529eef85baad
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/bundle-internal.cc
src/bundle-internal.h
src/stub.cc

index 2298412..55c2181 100644 (file)
@@ -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);
 }
index 73f55d0..136458a 100644 (file)
@@ -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();
 
index 7bf991a..0c22e5e 100644 (file)
@@ -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<bundle_raw*>(r);
+    b = new Bundle(static_cast<unsigned char*>(raw), data_size, false);
+  } catch (Exception& e) {
+    set_last_result(e.GetErrorCode());
     return nullptr;
-
-  auto* h = reinterpret_cast<Bundle*>(b);
-  auto* raw = const_cast<bundle_raw*>(r);
-  int ret = h->DecodeRaw(static_cast<unsigned char*>(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<bundle*>(b);
 }
 
 extern "C" EXPORT_API int bundle_get_type(bundle* b, const char* key) {