summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/utils/html.c39
1 files changed, 26 insertions, 13 deletions
diff --git a/src/utils/html.c b/src/utils/html.c
index 4fd71ea..b8abbac 100644
--- a/src/utils/html.c
+++ b/src/utils/html.c
@@ -761,11 +761,15 @@ mq_html_input_select(const gchar *name, const gchar *label,
g_assert(selected && selected[0]); /* Would cause buffer overflow */
/* Calculate length. */
- len = strlen("<label for=\"");
- len += strlen(name);
- len += strlen("\">\n<span>");
- len += strlen(label);
- len += strlen(":</span>\n<select name=\"");
+ len = 0;
+ if (label && label[0]) {
+ len += strlen("<label for=\"");
+ len += strlen(name);
+ len += strlen("\">\n<span>");
+ len += strlen(label);
+ len += strlen(":</span>\n");
+ }
+ len += strlen("<select name=\"");
len += strlen(name);
len += strlen("\" id=\"");
len += strlen(name);
@@ -782,16 +786,22 @@ mq_html_input_select(const gchar *name, const gchar *label,
}
va_end(ap);
len += strlen(" selected=\"selected\"");
- len += strlen("</select>\n</label>\n");
+ len += strlen("</select>\n");
+ if (label && label[0]) {
+ len += strlen("</label>\n");
+ }
++len; /* NUL byte */
/* Build string. */
- select = g_new(gchar, len);
- ptr = g_stpcpy(select, "<label for=\"");
- ptr = g_stpcpy(ptr, name);
- ptr = g_stpcpy(ptr, "\">\n<span>");
- ptr = g_stpcpy(ptr, label);
- ptr = g_stpcpy(ptr, ":</span>\n<select name=\"");
+ ptr = select = g_new(gchar, len);
+ if (label && label[0]) {
+ ptr = g_stpcpy(ptr, "<label for=\"");
+ ptr = g_stpcpy(ptr, name);
+ ptr = g_stpcpy(ptr, "\">\n<span>");
+ ptr = g_stpcpy(ptr, label);
+ ptr = g_stpcpy(ptr, ":</span>\n");
+ }
+ ptr = g_stpcpy(ptr, "<select name=\"");
ptr = g_stpcpy(ptr, name);
ptr = g_stpcpy(ptr, "\" id=\"");
ptr = g_stpcpy(ptr, name);
@@ -816,7 +826,10 @@ mq_html_input_select(const gchar *name, const gchar *label,
ptr = g_stpcpy(ptr, "</option>\n");
}
va_end(ap);
- ptr = g_stpcpy(ptr, "</select>\n</label>\n"); /* g_stpcpy() adds NUL */
+ ptr = g_stpcpy(ptr, "</select>\n");
+ if (label && label[0]) {
+ ptr = g_stpcpy(ptr, "</label>\n"); /* g_stpcpy() adds NUL */
+ }
return select;
}