Thanks Max Bernstein for pointing out this bug:
  https://git.sr.ht/~akkartik/mu-x86_64/commit/9e2ef1c90d
This commit is contained in:
Kartik Agaram 2020-10-14 21:45:24 -07:00
parent 480fd9958a
commit 49ed062cb1
2 changed files with 18 additions and 2 deletions

View File

@ -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) {

View File

@ -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>