Icon-O-Matic bugs when exporting to png set

If I have an icon and I want to export it to a png set, two issues are occuring:

  1. If I want to save the png exports to the same directory, I’m asked if I want to overwrite the original, but the export files are supposed to have different filenames (MyIcon becomes MyIcon_{64|16|32}.png). Confirming this will not overwrite the original file at all.

  2. If the filename is too long, it will be truncated without appending the proper extension, resulting in the exported filenames all being the same. So Instead of LONGNAME being saved to TRUNCATED_{64|16|32}.png there is only 1 file with a truncated name. The issue is in the file src/apps/icon-o-matic/document/savers/BitmapSetSaver.cpp, with a potential fix like this:

--- a/src/apps/icon-o-matic/document/savers/BitmapSetSaver.cpp
+++ b/src/apps/icon-o-matic/document/savers/BitmapSetSaver.cpp
@@ -28,24 +28,28 @@
 BitmapSetSaver::Save(Document* document)
 {
     entry_ref actualRef(fRef);
-    char name[B_OS_NAME_LENGTH];
+    size_t size = B_OS_NAME_LENGTH;
+    char name[size];
 
     // 64x64
-    snprintf(name, sizeof(name), "%s_64.png", fRef.name);
+    snprintf(name, size-7, "%s", fRef.name);
+    snprintf(name, size, "%s_64.png", name);
     actualRef.set_name(name);
     Exporter* exporter = new BitmapExporter(64);
     exporter->SetSelfDestroy(true);
     exporter->Export(document, actualRef);
 
     // 16x16
-    snprintf(name, sizeof(name), "%s_16.png", fRef.name);
+    snprintf(name, size-7, "%s", fRef.name);
+    snprintf(name, size, "%s_16.png", name);
     actualRef.set_name(name);
     exporter = new BitmapExporter(16);
     exporter->SetSelfDestroy(true);
     exporter->Export(document, actualRef);
 
     // 32x32
-    snprintf(name, sizeof(name), "%s_32.png", fRef.name);
+    snprintf(name, size-7, "%s", fRef.name);
+    snprintf(name, size, "%s_32.png", name);
     actualRef.set_name(name);
     exporter = new BitmapExporter(32);
     exporter->SetSelfDestroy(true);

By the way B_OS_NAME_LENGTH is defined as 32 which is not very long in opinion.

B_FILE_NAME_LENGTH is 256, B_OS_NAME_LENGTH is for named kernel objects, like semaphores, threads, memory areas, etc.

So it should be declared char name[B_FILE_NAME_LENGTH] in BitmapSetSaver.cpp?

Yes, or use that “size” intermediate variable (with a const for safety and compiler optimization of allocating the array[size]) set to:
const size_t size = B_FILE_NAME_LENGTH;

And don’t do the double snprintf using the “name” array as both input and output, could malfunction in some cases. Better to use one snprintf like:
snprintf(name, size, “%s_64.png”, fRef.name);

The double snprintf was only a suggestion to make sure there’s enough space to append the _64.png to avoid the issue #2 mentioned in my first post (if it was me I’d just use std::string). I wanted to register to the bug tracker and file a bug report there but the bug tracker thought I was a spammer and didn’t allow me to.

By the way adding a few command line options to Icon-O-Matic so someone could export from or to HVIF or Icon-O-Matic documents could be useful too.

You could use BString::SetToFormat instead of C APIs.
Don’t forget to submit your patch to the bug tracker at dev.haiku-os.org.

I can’t register at the bug tracker, sorry.

https://dev.haiku-os.org/ticket/14930