From 92ed37268072ab053b06d8e2f8b2e7320a495c57 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Sat, 30 May 2020 19:56:26 +0200 Subject: [PATCH] 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 Change-Id: I978ff3d377b3652c7f1c5fac4f429ade0398d5f7 Reviewed-on: https://review.haiku-os.org/c/haiku/+/2852 Reviewed-by: waddlesplash --- .../import_export/flat_icon/FlatIconExporter.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 a0eb7b8c24..1115a6229f 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 @@ status_t 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 @@ write_path_with_commands(LittleEndianBuffer& buffer, VectorPath* path, 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 @@ FlatIconExporter::_WritePaths(LittleEndianBuffer& buffer, PathContainer* paths) 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 @@ _WritePathSourceShape(LittleEndianBuffer& buffer, Shape* shape, 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 @@ _WritePathSourceShape(LittleEndianBuffer& buffer, Shape* shape, return false; } + if (shape->CountTransformers() > 255) + return B_RESULT_NOT_REPRESENTABLE; uint8 transformerCount = min_c(255, shape->CountTransformers()); // shape flags @@ -572,6 +582,8 @@ FlatIconExporter::_WriteShapes(LittleEndianBuffer& buffer, 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;