]> sourceware.org Git - libabigail.git/commitdiff
Fix --type-id-style hash for empty internal names.
authorGiuliano Procida <gprocida@google.com>
Mon, 6 Jul 2020 09:21:33 +0000 (10:21 +0100)
committerDodji Seketeli <dodji@redhat.com>
Mon, 27 Jul 2020 09:23:26 +0000 (11:23 +0200)
libabigail's intern_string class treats the empty string specially. It
is not safe to call the raw method without checking for a empty
pointer. It is safe to convert to std::string.

This commit changes the XML writer to convert interned strings to
std::strings before computing their hashes.

* src/abg-writer.cc (write_context::get_id_for_type): When
hashing internal type names, convert to std::string rather
than using the raw method directly as this will avoid a null
pointer dereference in the case of an empty string; tabify
code indentation.

Signed-off-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
src/abg-writer.cc

index 77d91e8c8c64b33b491931fb3d69f460fb7c49ad..7833e6c09f9f1b17960bb4e78fbda6167d84b41e 100644 (file)
@@ -450,20 +450,20 @@ public:
     switch (m_type_id_style)
       {
       case SEQUENCE_TYPE_ID_STYLE:
-        {
-          interned_string id = get_id_manager().get_id_with_prefix("type-id-");
-          return m_type_id_map[c] = id;
-        }
+       {
+         interned_string id = get_id_manager().get_id_with_prefix("type-id-");
+         return m_type_id_map[c] = id;
+       }
       case HASH_TYPE_ID_STYLE:
-        {
-          interned_string pretty = c->get_cached_pretty_representation(true);
-          size_t hash = hashing::fnv_hash(*pretty.raw());
-          while (!m_used_type_id_hashes.insert(hash).second)
-            ++hash;
-          std::ostringstream os;
-          os << std::hex << std::setfill('0') << std::setw(8) << hash;
-          return m_type_id_map[c] = c->get_environment()->intern(os.str());
-        }
+       {
+         interned_string pretty = c->get_cached_pretty_representation(true);
+         size_t hash = hashing::fnv_hash(pretty);
+         while (!m_used_type_id_hashes.insert(hash).second)
+           ++hash;
+         std::ostringstream os;
+         os << std::hex << std::setfill('0') << std::setw(8) << hash;
+         return m_type_id_map[c] = c->get_environment()->intern(os.str());
+       }
       }
     ABG_ASSERT_NOT_REACHED;
     return interned_string();
This page took 0.035566 seconds and 5 git commands to generate.