examples: preventing undef behavior 37/291437/1
authorMira Grudzinska <veleveta@gmail.com>
Mon, 3 Apr 2023 20:45:26 +0000 (22:45 +0200)
committerjykeon <jykeon@samsung.com>
Mon, 17 Apr 2023 03:14:36 +0000 (12:14 +0900)
Calling get() on a unique pointer after
it has been moved is the undefined behavior.

Change-Id: I6878daf840079b59c6584c5741171d1affc71666
Signed-off-by: jykeon <jykeon@samsung.com>
src/examples/ImageScaleDown.cpp
src/examples/ImageScaleUp.cpp

index 81928d0..6ef31c6 100644 (file)
@@ -40,8 +40,9 @@ void tvgDrawCmds(tvg::Canvas* canvas)
         cout << "The PNG file is not loaded correctly. Did you enable PNG Loader?" << endl;
         return;
     }
-    if (canvas->push(move(picture)) == tvg::Result::Success) {
-        pPicture = picture.get();
+    pPicture = picture.get();
+    if (canvas->push(move(picture)) != tvg::Result::Success) {
+        pPicture = nullptr;
     }
 }
 
index f45b96c..45c6d8b 100644 (file)
@@ -40,8 +40,9 @@ void tvgDrawCmds(tvg::Canvas* canvas)
         cout << "The PNG file is not loaded correctly. Did you enable PNG Loader?" << endl;
         return;
     }
-    if (canvas->push(move(picture)) == tvg::Result::Success) {
-        pPicture = picture.get();
+    pPicture = picture.get();
+    if (canvas->push(move(picture)) != tvg::Result::Success) {
+        pPicture = nullptr;
     }
 }