You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@htrace.apache.org by cm...@apache.org on 2015/08/18 00:18:28 UTC
incubator-htrace git commit: HTRACE-224. htrace C client:
htrace_conf_get_u64,
htrace_conf_get_double can't handle spaces at the end of strings (cmccabe)
Repository: incubator-htrace
Updated Branches:
refs/heads/master a06159b27 -> afa0b71a4
HTRACE-224. htrace C client: htrace_conf_get_u64, htrace_conf_get_double can't handle spaces at the end of strings (cmccabe)
Project: http://git-wip-us.apache.org/repos/asf/incubator-htrace/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-htrace/commit/afa0b71a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-htrace/tree/afa0b71a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-htrace/diff/afa0b71a
Branch: refs/heads/master
Commit: afa0b71a4ff46378158f149b6b719aa3c8e1006f
Parents: a06159b
Author: Colin P. Mccabe <cm...@apache.org>
Authored: Thu Jul 30 16:52:15 2015 -0700
Committer: Colin P. Mccabe <cm...@apache.org>
Committed: Mon Aug 17 15:17:58 2015 -0700
----------------------------------------------------------------------
htrace-c/src/core/conf.c | 6 ++++--
htrace-c/src/test/conf-unit.c | 22 ++++++++++++++++++++--
2 files changed, 24 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/afa0b71a/htrace-c/src/core/conf.c
----------------------------------------------------------------------
diff --git a/htrace-c/src/core/conf.c b/htrace-c/src/core/conf.c
index 08fbb8c..c004fad 100644
--- a/htrace-c/src/core/conf.c
+++ b/htrace-c/src/core/conf.c
@@ -178,11 +178,12 @@ static int convert_double(struct htrace_log *log, const char *key,
if (c == '\0') {
break;
}
- if ((c != ' ') || (c != '\t')) {
+ if (!((c == ' ') || (c == '\t'))) {
htrace_log(log, "error parsing %s for %s: garbage at end "
"of string.\n", in, key);
return 0;
}
+ endptr++;
}
*out = ret;
return 1;
@@ -229,11 +230,12 @@ static int convert_u64(struct htrace_log *log, const char *key,
if (c == '\0') {
break;
}
- if ((c != ' ') || (c != '\t')) {
+ if (!((c == ' ') || (c == '\t'))) {
htrace_log(log, "error parsing %s for %s: garbage at end "
"of string.\n", in, key);
return 0;
}
+ endptr++;
}
*out = ret;
return 1;
http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/afa0b71a/htrace-c/src/test/conf-unit.c
----------------------------------------------------------------------
diff --git a/htrace-c/src/test/conf-unit.c b/htrace-c/src/test/conf-unit.c
index debc866..715141f 100644
--- a/htrace-c/src/test/conf-unit.c
+++ b/htrace-c/src/test/conf-unit.c
@@ -29,7 +29,9 @@ static int test_simple_conf(void)
{
struct htrace_conf *conf;
struct htrace_log *lg;
- conf = htrace_conf_from_strs("foo=bar;foo2=baz;foo3=quux;foo5=123",
+ conf = htrace_conf_from_strs("foo=bar;foo2=baz;foo3=quux;foo5=123;"
+ "garbage.at.end=1234garbage;"
+ "whitespace.at.end=123\t \t",
"foo3=default3;foo4=default4");
lg = htrace_log_alloc(conf);
EXPECT_NONNULL(conf);
@@ -39,6 +41,8 @@ static int test_simple_conf(void)
EXPECT_UINT64_EQ((uint64_t)123, htrace_conf_get_u64(lg, conf, "foo5"));
EXPECT_UINT64_EQ((uint64_t)123, htrace_conf_get_u64(lg, conf, "foo5"));
EXPECT_NULL(htrace_conf_get(conf, "unknown"));
+ EXPECT_UINT64_EQ((uint64_t)0, htrace_conf_get_u64(lg, conf, "garbage.at.end"));
+ EXPECT_UINT64_EQ((uint64_t)123, htrace_conf_get_u64(lg, conf, "whitespace.at.end"));
htrace_log_free(lg);
htrace_conf_free(conf);
@@ -51,7 +55,9 @@ static int test_double_conf(void)
struct htrace_log *lg;
double d;
- conf = htrace_conf_from_strs("my.double=5.4;bozo=wakkawakkaa",
+ conf = htrace_conf_from_strs("my.double=5.4;bozo=wakkawakkaa;"
+ "garbage.at.end=1.0garbage;"
+ "tabs.at.end=5.0\t\t",
"my.double=1.1;bozo=2.0");
EXPECT_NONNULL(conf);
lg = htrace_log_alloc(conf);
@@ -78,6 +84,18 @@ static int test_double_conf(void)
"got %g\n", d);
return EXIT_FAILURE;
}
+ d = htrace_conf_get_double(lg, conf, "garbage.at.end");
+ if ((d > 0.001) || (d < -0.001)) {
+ htrace_log(lg, "failed to parse garbage.at.end... expected 0.0, "
+ "got %g\n", d);
+ return EXIT_FAILURE;
+ }
+ d = htrace_conf_get_double(lg, conf, "tabs.at.end");
+ if ((d > 5.001) || (d < 4.990)) {
+ htrace_log(lg, "failed to parse tabs.at.end... expected 5.0, "
+ "got %g\n", d);
+ return EXIT_FAILURE;
+ }
htrace_log_free(lg);
htrace_conf_free(conf);