From 94405f6b6011aaee0c5258425092720b46a79308 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 25 Feb 2014 13:19:14 +0100 Subject: make the lib handle max png comment size --- lib/libcqrlogo.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3-70-g09d2