libqrencode icon indicating copy to clipboard operation
libqrencode copied to clipboard

qrencode produces invalid XPM data.

Open PCDbeeip opened this issue 3 years ago • 2 comments

https://github.com/fukuchi/libqrencode/blob/715e29fd4cd71b6e452ae0f4e36d917b43122ce8/qrenc.c#L727

with margin != 1 XPM data is not valid C code (although correctly processed by most image viewers)

# echo "83c36da7" | qrencode -s1 -m2 -M -t XPM -o QR.xpm
# g++ -c -x c QR.xpm -o QR.o 
QR.xpm:27:1: error: expected identifier or ‘(’ before string constant
   27 | "BBBBBBBBBBBBBBBBBBB"};
      | ^~~~~~~~~~~~~~~~~~~~~

PCDbeeip avatar Feb 14 '22 22:02 PCDbeeip

suggested patch

diff --git a/qrenc.c b/qrenc.c
index c09c4ab..d26b0d2 100644
--- a/qrenc.c
+++ b/qrenc.c
@@ -724,9 +724,11 @@ static int writeXPM(const QRcode *qrcode, const char *outfile)
        }
 
        for (y = 0; y < realmargin; y++) {
-               fprintf(fp, "\"%s\"%s\n", row, y < (size - 1) ? "," : "};");
+               fprintf(fp, "\"%s\",\n", row);
        }
 
+    fputs("};\n", fp);
+
        free(row);
        fclose(fp);

PCDbeeip avatar Feb 15 '22 10:02 PCDbeeip

same as issue #188

PCDbeeip avatar Feb 15 '22 10:02 PCDbeeip