diff --git a/crypto/test/file_test.cc b/crypto/test/file_test.cc index 963429da5..47a6f4c8b 100644 --- a/crypto/test/file_test.cc +++ b/crypto/test/file_test.cc @@ -205,11 +205,10 @@ FileTest::ReadResult FileTest::ReadNext() { // Duplicate keys are rewritten to have “/2”, “/3”, … suffixes. std::string mapped_key = key; - for (unsigned i = 2; attributes_.count(mapped_key) != 0; i++) { - char suffix[32]; - snprintf(suffix, sizeof(suffix), "/%u", i); - suffix[sizeof(suffix)-1] = 0; - mapped_key = key + suffix; + // If absent, the value will be zero-initialized. + const size_t num_occurrences = ++attribute_count_[key]; + if (num_occurrences > 1) { + mapped_key += "/" + std::to_string(num_occurrences); } unused_attributes_.insert(mapped_key); @@ -317,6 +316,7 @@ void FileTest::ClearTest() { start_line_ = 0; type_.clear(); parameter_.clear(); + attribute_count_.clear(); attributes_.clear(); unused_attributes_.clear(); unused_instructions_.clear(); diff --git a/crypto/test/file_test.h b/crypto/test/file_test.h index 87f306f9b..150200387 100644 --- a/crypto/test/file_test.h +++ b/crypto/test/file_test.h @@ -221,6 +221,9 @@ class FileTest { std::string type_; // parameter_ is the value of the first attribute. std::string parameter_; + // attribute_count_ maps unsuffixed attribute names to the number of times + // they have occurred so far. + std::map attribute_count_; // attributes_ contains all attributes in the test, including the first. std::map attributes_; // instructions_ contains all instructions in scope for the test.