aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cqrlogo.c12
-rw-r--r--lib/libcqrlogo.c16
2 files changed, 14 insertions, 14 deletions
diff --git a/cqrlogo.c b/cqrlogo.c
index 4b87371..bfdd3d2 100644
--- a/cqrlogo.c
+++ b/cqrlogo.c
@@ -13,7 +13,7 @@
/*** main ***/
int main(int argc, char **argv) {
const char * http_referer, * server_name, * query_string, * uri;
- char * uri_server_name, * uri_png, * pattern, * stolen;
+ char * uri_server_name, * pattern, * stolen;
regex_t preg;
regmatch_t pmatch[1];
uint8_t https;
@@ -28,7 +28,6 @@ int main(int argc, char **argv) {
#endif
/* do the variable initialization within the loop! */
uri_server_name = NULL;
- uri_png = NULL;
pattern = NULL;
stolen = NULL;
@@ -98,13 +97,6 @@ int main(int argc, char **argv) {
/* print HTTP header */
printf("Content-Type: image/png\n\n");
- /* cut uri, text in png file may have a max length of 79 chars */
- if (strlen(uri) > 79) {
- uri_png = strdup(uri);
- sprintf(uri_png + 76, "...");
- uri = uri_png;
- }
-
/* generate PNG data */
if ((png = generate_png(bitmap, CQR_COMMENT|CQR_REFERER|CQR_VERSION|CQR_LIBVERSION, uri)) == NULL) {
fprintf(stderr, "Failed to generate PNG.\n");
@@ -119,8 +111,6 @@ int main(int argc, char **argv) {
free(uri_server_name);
if (stolen)
free(stolen);
- if (uri_png)
- free(uri_png);
bitmap_free(bitmap);
if (png->size > 0)
free(png->buffer);
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