summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1209858)
raw | patch | inline | side by side (parent: 1209858)
author | Thomas Guyot-Sionnest <dermoth@aei.ca> | |
Wed, 31 Mar 2010 06:45:45 +0000 (02:45 -0400) | ||
committer | Thomas Guyot-Sionnest <dermoth@aei.ca> | |
Wed, 31 Mar 2010 23:55:47 +0000 (19:55 -0400) |
Rework last patch, copying the converted portion of the string rather
than re-converting it. This is safer for backwards-compatibility as the
value is never modified.
than re-converting it. This is safer for backwards-compatibility as the
value is never modified.
plugins/check_snmp.c | patch | blob | history |
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index ce3919d1af4f3592f08b3fa229cffe1102ce4bc5..fdb5819e05d443e5a71accbe5625e843b63b5989 100644 (file)
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
int
main (int argc, char **argv)
{
- int i;
+ int i, len;
int iresult = STATE_UNKNOWN;
int result = STATE_UNKNOWN;
int return_code = 0;
int external_error = 0;
- double perftmp;
char **command_line = NULL;
char *cl_hidden_auth = NULL;
char *oidname = NULL;
if (nunits > (size_t)0 && (size_t)i < nunits && unitv[i] != NULL)
asprintf (&outbuff, "%s %s", outbuff, unitv[i]);
- /* Try a two-way conversion of show and add perfdata only if we get
- * something back at the end */
+ /* Write perfdata with whatever can be parsed by strtod, if possible */
ptr = NULL;
- perftmp = strtod(show, &ptr);
- if (ptr != show) {
- ptr = NULL;
- asprintf(&ptr, "%0.9g", perftmp);
+ strtod(show, &ptr);
+ if (ptr > show) {
strncat(perfstr, oidname, sizeof(perfstr)-strlen(perfstr)-1);
strncat(perfstr, "=", sizeof(perfstr)-strlen(perfstr)-1);
- strncat(perfstr, ptr, sizeof(perfstr)-strlen(perfstr)-1);
- free(ptr);
+ len = sizeof(perfstr)-strlen(perfstr)-1;
+ strncat(perfstr, show, len>ptr-show ? ptr-show : len);
if (type)
strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1);