summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2018-10-27 18:34:41 +0200
committerErich Eckner <git@eckner.net>2018-10-27 18:34:41 +0200
commitf960a6d5c824c795195f82483b53dd2fda6a968a (patch)
treebe461378598da5562571f92fac2eea8542579dcb
parent5da124c9de6a81461af381ca16b83ffb3e3adec6 (diff)
downloadanzeige-f960a6d5c824c795195f82483b53dd2fda6a968a.tar.xz
check for max_len<0
-rw-r--r--input_gadgets.c62
1 files changed, 39 insertions, 23 deletions
diff --git a/input_gadgets.c b/input_gadgets.c
index 46661cb..fe754da 100644
--- a/input_gadgets.c
+++ b/input_gadgets.c
@@ -86,20 +86,25 @@ char *gadgets_retrieve_current_temperature(char *output, int max_len)
return NULL;
}
regfree(&re);
- int i = snprintf(output, max_len, "%.*s (%.*s %.*s-%.*s-%.*s)",
- (int)(rm[6].rm_eo - rm[6].rm_so), (char*)(chunk.memory + rm[6].rm_so),
- (int)(rm[4].rm_eo - rm[4].rm_so), (char*)(chunk.memory + rm[4].rm_so),
- (int)(rm[3].rm_eo - rm[3].rm_so), (char*)(chunk.memory + rm[3].rm_so),
- (int)(rm[2].rm_eo - rm[2].rm_so), (char*)(chunk.memory + rm[2].rm_so),
- (int)(rm[1].rm_eo - rm[1].rm_so), (char*)(chunk.memory + rm[1].rm_so)
- );
- char* ende = output + i;
- for (; i>=0; i--)
- if (output[i] == '(')
- break;
- for (; i>=0; i--)
- if (output[i] == '.')
- output[i] = ',';
+ char* ende;
+ if (max_len > 0) {
+ int i = snprintf(output, max_len, "%.*s (%.*s %.*s-%.*s-%.*s)",
+ (int)(rm[6].rm_eo - rm[6].rm_so), (char*)(chunk.memory + rm[6].rm_so),
+ (int)(rm[4].rm_eo - rm[4].rm_so), (char*)(chunk.memory + rm[4].rm_so),
+ (int)(rm[3].rm_eo - rm[3].rm_so), (char*)(chunk.memory + rm[3].rm_so),
+ (int)(rm[2].rm_eo - rm[2].rm_so), (char*)(chunk.memory + rm[2].rm_so),
+ (int)(rm[1].rm_eo - rm[1].rm_so), (char*)(chunk.memory + rm[1].rm_so)
+ );
+ ende = output + i;
+ for (; i>=0; i--)
+ if (output[i] == '(')
+ break;
+ for (; i>=0; i--)
+ if (output[i] == '.')
+ output[i] = ',';
+ }
+ else
+ ende = output;
free(chunk.memory);
return ende;
}
@@ -224,15 +229,19 @@ char *gadgets_retrieve_weather_forecast(char *output, int max_len)
xmlFreeDoc(doc);
xmlCleanupParser();
- int i = snprintf(output, max_len, "%0.1f ,, %0.1f °C; %0.1f mm; %0.1f m/s", temp_min, temp_max, rain_total, wind_max);
- char *ende = output + i;
- for (; i>=0; i--)
- if (output[i] == '.')
- output[i] = ',';
- else if (output[i] == ',')
- output[i] = '.';
+ if (max_len > 0) {
+ int i = snprintf(output, max_len, "%0.1f ,, %0.1f °C; %0.1f mm; %0.1f m/s", temp_min, temp_max, rain_total, wind_max);
+ char *ende = output + i;
+ for (; i>=0; i--)
+ if (output[i] == '.')
+ output[i] = ',';
+ else if (output[i] == ',')
+ output[i] = '.';
- return ende;
+ return ende;
+ }
+ else
+ return output;
}
char *gadgets_retrieve_weather_warnings(char *output, int max_len)
@@ -731,12 +740,19 @@ char *gadgets_retrieve_weather_warnings(char *output, int max_len)
free(chunk.memory);
char *ende = output;
+ if ((!warnings_len) && (max_len > 0))
+ ende += snprintf(ende, max_len, "%s", "keine Warnungen");
for (int i=0; i<warnings_len; i++) {
- ende += snprintf(ende, output + max_len - ende, "%s: %s ", warnings[i].headline, warnings[i].event);
+ if (output + max_len - ende > 0) {
+ ende += snprintf(ende, output + max_len - ende, "%s", warnings[i].event);
+ if ((i+1<warnings_len) && (output + max_len - ende > 0))
+ ende += snprintf(ende, output + max_len - ende, ", ", warnings[i].event);
+ }
free(warnings[i].headline);
free(warnings[i].event);
}
+ free(warnings);
return ende;
}