[haiku-commits] Change in haiku[master]: Icon-O-Matic: check number of items when exporting

  • From: Gerrit <review@xxxxxxxxxxxxxxxxxxx>
  • To: waddlesplash <waddlesplash@xxxxxxxxx>, haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 30 May 2020 18:02:07 +0000

From Adrien Destugues <pulkomandy@xxxxxxxxx>:

Adrien Destugues has uploaded this change for review. ( 
https://review.haiku-os.org/c/haiku/+/2852 ;)


Change subject: Icon-O-Matic: check number of items when exporting
......................................................................

Icon-O-Matic: check number of items when exporting

Silently saving only part of the data is not nice and confusing.

The error message just says "Out of range" now however, which is not
really great either. We could improve the error reporting, and, as
mentionned in the ticket, also warn in the UI when the limit is reached
(a marker near the shape/path/fill lists maybe?) so the user knows they
need to simplify their picture.

Part of #13978
---
M src/apps/icon-o-matic/import_export/flat_icon/FlatIconExporter.cpp
1 file changed, 12 insertions(+), 0 deletions(-)



  git pull ssh://git.haiku-os.org:22/haiku refs/changes/52/2852/1

diff --git a/src/apps/icon-o-matic/import_export/flat_icon/FlatIconExporter.cpp 
b/src/apps/icon-o-matic/import_export/flat_icon/FlatIconExporter.cpp
index a0eb7b8..1115a62 100644
--- a/src/apps/icon-o-matic/import_export/flat_icon/FlatIconExporter.cpp
+++ b/src/apps/icon-o-matic/import_export/flat_icon/FlatIconExporter.cpp
@@ -212,6 +212,8 @@
 FlatIconExporter::_WriteStyles(LittleEndianBuffer& buffer,
                                                           StyleContainer* 
styles)
 {
+       if (styles->CountStyles() > 255)
+               return B_RESULT_NOT_REPRESENTABLE;
        uint8 styleCount = min_c(255, styles->CountStyles());
        if (!buffer.Write(styleCount))
                return B_NO_MEMORY;
@@ -369,6 +371,8 @@
 status_t
 FlatIconExporter::_WritePaths(LittleEndianBuffer& buffer, PathContainer* paths)
 {
+       if (paths->CountPaths() > 255)
+               return B_RESULT_NOT_REPRESENTABLE;
        uint8 pathCount = min_c(255, paths->CountPaths());
        if (!buffer.Write(pathCount))
                return B_NO_MEMORY;
@@ -379,6 +383,8 @@
                if (path->IsClosed())
                        pathFlags |= PATH_FLAG_CLOSED;

+               if (path->CountPoints() > 255)
+                       return B_RESULT_NOT_REPRESENTABLE;
                uint8 pointCount = min_c(255, path->CountPoints());

                // see if writing segments with commands is more efficient
@@ -490,6 +496,8 @@
        if (styleIndex < 0 || styleIndex > 255)
                return false;

+       if (shape->Paths()->CountPaths() > 255)
+               return B_RESULT_NOT_REPRESENTABLE;
        uint8 pathCount = min_c(255, shape->Paths()->CountPaths());

        // write shape type and style index
@@ -509,6 +517,8 @@
                        return false;
        }

+       if (shape->CountTransformers() > 255)
+               return B_RESULT_NOT_REPRESENTABLE;
        uint8 transformerCount = min_c(255, shape->CountTransformers());

        // shape flags
@@ -572,6 +582,8 @@
                                                           PathContainer* paths,
                                                           ShapeContainer* 
shapes)
 {
+       if (shapes->CountShapes() > 255)
+               return B_RESULT_NOT_REPRESENTABLE;
        uint8 shapeCount = min_c(255, shapes->CountShapes());
        if (!buffer.Write(shapeCount))
                return B_NO_MEMORY;

--
To view, visit https://review.haiku-os.org/c/haiku/+/2852
To unsubscribe, or for help writing mail filters, visit 
https://review.haiku-os.org/settings

Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: I978ff3d377b3652c7f1c5fac4f429ade0398d5f7
Gerrit-Change-Number: 2852
Gerrit-PatchSet: 1
Gerrit-Owner: Adrien Destugues <pulkomandy@xxxxxxxxx>
Gerrit-MessageType: newchange

Other related posts:

  • » [haiku-commits] Change in haiku[master]: Icon-O-Matic: check number of items when exporting - Gerrit