Skip to content

Template function is_empty() is possibly incorrect #10

@pstavirs

Description

@pstavirs

is_empty() is defined assuming a struct with std::string(s) will be all zero - which may not be true. I fixed it using template specializations. Also included in PR #9.

diff --git a/main.cpp b/main.cpp
index b1f5146..4362782 100644
--- a/main.cpp
+++ b/main.cpp
@@ -175,6 +175,21 @@ bool is_empty(T data) {
   return (*mm == 0) && memcmp(mm, mm + 1, sizeof(T) - 1) == 0;
 }

+template <>
+bool is_empty(license_file data) {
+  return data.enc.empty();
+}
+
+template <>
+bool is_empty(license data) {
+  return data.id.empty();
+}
+
+template <>
+bool is_empty(machine data) {
+  return data.id.empty();
+}
+

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions