summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2014-02-25 13:19:14 +0100
committerGravatar Christian Hesse <mail@eworm.de>2014-02-25 13:19:14 +0100
commit94405f6b6011aaee0c5258425092720b46a79308 (patch)
treebc212a7790889c3e2b9cc5abe1d0ad88ecba44ea /lib
parent87ffef6e32856495b8175553dcfbeb288c30e56a (diff)
downloadcqrlogo-94405f6b6011aaee0c5258425092720b46a79308.tar.gz
cqrlogo-94405f6b6011aaee0c5258425092720b46a79308.tar.zst
make the lib handle max png comment size
Diffstat (limited to 'lib')
-rw-r--r--lib/libcqrlogo.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/libcqrlogo.c b/lib/libcqrlogo.c
index aca5cb5..cfe864c 100644
--- a/lib/libcqrlogo.c
+++ b/lib/libcqrlogo.c
@@ -73,13 +73,20 @@ struct png_t * generate_png (struct bitmap_t *bitmap, const uint8_t meta, const
#if defined PNG_TEXT_SUPPORTED
unsigned int textcount = 0;
png_text *pngtext = NULL;
- char *libsstr = NULL, *qrver;
+ char *curi = NULL, *libsstr = NULL, *qrver;
if (meta & CQR_COMMENT)
pngtext = add_png_text(pngtext, &textcount, "comment", "QR-Code created by cqrlogo - https://github.com/eworm-de/cqrlogo");
- if (meta & CQR_REFERER)
- pngtext = add_png_text(pngtext, &textcount, "referer", (char *)uri);
+ if (meta & CQR_REFERER) {
+ curi = strdup(uri);
+
+ /* text in png file may have a max length of 79 chars */
+ if (strlen(curi) > 79)
+ sprintf(curi + 76, "...");
+
+ pngtext = add_png_text(pngtext, &textcount, "referer", curi);
+ }
if (meta & CQR_VERSION)
pngtext = add_png_text(pngtext, &textcount, "version", VERSIONSTR);
@@ -95,6 +102,9 @@ struct png_t * generate_png (struct bitmap_t *bitmap, const uint8_t meta, const
png_set_text(png_ptr, info_ptr, pngtext, textcount);
png_free (png_ptr, pngtext);
+
+ if (curi)
+ free(curi);
if (libsstr)
free(libsstr);
#endif