diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-10-14 21:45:24 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-10-14 21:45:24 -0700 |
commit | 49ed062cb1fd364d6c794db4092920d54d516abc (patch) | |
tree | de43ffdddb3ff51299ffd11cbd4d1dbdfa328d8e | |
parent | 480fd9958abbd9b3b8443190ece755504cacdf9c (diff) | |
download | mu-49ed062cb1fd364d6c794db4092920d54d516abc.tar.gz |
7033
Thanks Max Bernstein for pointing out this bug: https://git.sr.ht/~akkartik/mu-x86_64/commit/9e2ef1c90d
-rw-r--r-- | 001help.cc | 6 | ||||
-rw-r--r-- | 002test.cc | 14 |
2 files changed, 18 insertions, 2 deletions
diff --git a/001help.cc b/001help.cc index 5fd13a7b..87466acd 100644 --- a/001help.cc +++ b/001help.cc @@ -95,8 +95,10 @@ void init_help() { } :(code) -bool is_equal(char* s, const char* lit) { - return strncmp(s, lit, strlen(lit)) == 0; +bool is_equal(const char* s, const char* lit) { + size_t len = strlen(lit); + if (strlen(s) != len) return false; + return strncmp(s, lit, len) == 0; } bool starts_with(const string& s, const string& pat) { diff --git a/002test.cc b/002test.cc index 4122a46e..7865c3b5 100644 --- a/002test.cc +++ b/002test.cc @@ -105,5 +105,19 @@ for (size_t i=0; i < sizeof(Tests)/sizeof(Tests[0]); ++i) { } } +//: A pending test that also serves to put our test harness through its paces. + +:(code) +void test_is_equal() { + CHECK(is_equal("", "")); + CHECK(!is_equal("", "foo")); + CHECK(!is_equal("foo", "")); + CHECK(!is_equal("f", "bar")); + CHECK(!is_equal("bar", "f")); + CHECK(!is_equal("bar", "ba")); + CHECK(!is_equal("ba", "bar")); + CHECK(is_equal("bar", "bar")); +} + :(before "End Includes") #include <stdlib.h> |